lazy-gql

1.0.17 • Public • Published

Very lazy gql builder for your app

Npm package for fast app prototyping

Motivation

For fast prototyping next.js app with Hasura as backend Library is abstruction layer ower Hasura query api

How to use

  1. Create dataSchema file, minimal example
export default {
  user: {
    id: { },
    name: { },
    email: { },
  },
}
  1. Fill internal library store with setDataSchema
import { setDataSchema } from 'lazy-gql'
import dataSchema from 'dataSchema'

setDataSchema(dataSchema)

  1. Call one of build methods

Examples

lazy-gql-request for backend use example(with next.js api routes)

import { request } from 'lazy-gql-request'
import { buildInsert, setDataSchema } from 'lazy-gql'
import dataSchema from 'dataSchema'

setDataSchema(dataSchema)

const handler = async (req) => {
  return await request(process.env.URL, { headers: { } })(buildInsert('users'), [{
    name: 'random name',
    email: 'random@email',
  }])
}

export default handler

Set data schema you could on app instance initialization

import { setDataSchema } from 'lazy-gql'
import dataSchema from 'dataSchema'

setDataSchema(dataSchema)

For react application use hooks from lazy-gql-hooks

Also available support for react for builder lazy-gql-form

See examples at each package separately

Complex example with relations

export default {
  user: {
    id: { },
    name: { },
    email: { },
  },
  projects: {
    name: {  },
    description: {  }
  },
  flows: {
    name: {  },
  }
}

return await request(process.env.URL)(buildQuery({
  users: [{
    projects: ['flows']
  }]
}))

this renders gql query

query QueryUsers {
  users {
    id
    name
    email
    projects {
      name
      description
      flows {
        name
      }
    }
  }
}

API

all api methods have similar argument types - first is struct, second, variables more special info about each Hasura api methods

Package Sidebar

Install

npm i lazy-gql

Weekly Downloads

1

Version

1.0.17

License

MIT

Unpacked Size

33.2 kB

Total Files

16

Last publish

Collaborators

  • kirillsuhodolov