Programmatically Graphql Query Builder Component
npm install gql-builder
- Simple usage
- Query support
- Mutation support
- Nested fields support
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();
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();
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();
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();
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();