Skip to content

ahincalan/gql-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();

About

Graphql Query Builder

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published