gql-builder
TypeScript icon, indicating that this package has built-in type declarations

0.0.16 • Public • Published

NPM Version Build Status Coverage Status

GQL Builder

Programmatically Graphql Query Builder Component

Install Package
npm install gql-builder
Features
  • Simple usage
  • Query support
  • Mutation support
  • Nested fields support
Usage Examples

Query Example 1

String Usage

'query {
    user {
        id
        name
    }
}'

GqlBuilder Usage

const qb =  new GqlBuilder();
qb.addSibling('user',['id', 'name']);
qb.toQueryString();

GqlBuilder Alternative Usage

const qb =  new GqlBuilder();
qb.addSibling({ name:'user', fields:['id', 'name']});
qb.toQueryString();

Query Example 2

String Usage

'query {
    user {
        id
        name
        country {
            code
            name            
        }
    }
}'

GqlBuilder Usage

const qb =  new GqlBuilder();
qb.addSibling('user',['id','name',
  {name:'country', fields:['code', 'name']}]);
qb.toQueryString();

GqlBuilder Alternative Usage

const qb =  new GqlBuilder();
qb.addChild('user', ['id', 'name']).
    addChild('country', ['code', 'name']);
qb.toQueryString();

Query Example 3

String Usage

'query ($id: 'Int') {
    user (id: $id) {
        id
        name
        country {
            code
            name            
        }
    }
}'

GqlBuilder Usage

const qb =  new GqlBuilder();
qb.addSibling('user',['id','name',
  {name:'country', fields:['code', 'name']}],
  {id:'Int'});
qb.toQueryString();

GqlBuilder Alternative Usage

const qb =  new GqlBuilder();
qb.addChild('user', ['id', 'name'], {id: 'Int'}).
    addChild('country', ['code', 'name']);
qb.toQueryString();

Mutation Example 1

String Usage

'mutation ($user: User_Input) {
    createUser (user: $user) {
        id
        name
    }
}'

GqlBuilder Usage

const qb =  new GqlBuilder();
qb.addSibling('createUser', ['id','name'], {user:'User_Input'});
qb.toMutationString();

GqlBuilder Alternative Usage

const qb =  new GqlBuilder();
qb.addSibling({name:'createUser', fields:['id','name'], filters:{user:'User_Input'}});
qb.toMutationString();

Mutation Example 2

String Usage

'mutation ($id: Int, $name: String, $gender: String) {
    updateUser (id: $id, user: {
        name: $name
        gender: $gender
    }) {
        id
        name
        gender
    }
}'

GqlBuilder Usage

const qb =  new GqlBuilder();
qb.addSibling('updateUser', ['id','name','gender'], 
  {
    id: 'Int', 
    user: {name:'String', gender:'String'}
  });
qb.toMutationString();

GqlBuilder Alternative Usage

const qb =  new GqlBuilder();
qb.addSibling({
  name:'createUser', 
  fields:['id','name'], 
  filters: {
             id: 'Int', 
             user: {name:'String', gender:'String'}
           }
});
qb.toMutationString();

Readme

Keywords

Package Sidebar

Install

npm i gql-builder

Weekly Downloads

1

Version

0.0.16

License

MIT

Unpacked Size

18.2 kB

Total Files

8

Last publish

Collaborators

  • ahincalan