Skip to content

KirillSuhodolov/lazy-gql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: { },
  },
}

2 Fill internal library store with setDataSchema

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

setDataSchema(dataSchema)

3 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

About

Very lazy gql builder for your app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published