graphql-query-builder
a simple but powerful graphQL query builder
info:
tests:
quality:
★ it on github
If this was helpful,Demo / Sandbox 👍
Install
npm install graphql-query-builder
Api
const Query = ;
constructor
query/mutator you wish to use, and an alias or filter arguments.
Argument (one to two) | Description |
---|---|
String | the name of the query function |
* String / Object | (optional) This can be an alias or filter values |
let profilePicture = "profilePicture"size : 50;
setAlias
set an alias for this result.
Argument | Description |
---|---|
String | The alias for this result |
profilePicture;
filter
the parameters to run the query against.
Argument | Description |
---|---|
Object | An object mapping attribute to values |
profilePicture;
find
outlines the properties you wish to be returned from the query.
Argument (one to many) | Description |
---|---|
String or Object | representing each attribute you want Returned |
... | same as above |
profilePicture;
toString
return to the formatted query string
// A (ES6)``;// BprofilePicture+'';// CprofilePicture;
run samples
node example/simple.js
Example
var Query = ;// example of nesting Queryslet profilePicture = "profilePicture"size : 50;profilePicture;let user = "user"id : 123;userconsole/*user( id:123 ) {id,nickname : name,isViewerFriend,image : profilePicture( size:50 ) {uri,width,height}}*/// And another examplelet MessageRequest = type:"chat" message:"yoyo"user:name:"bob"screen:height:1080width:1920friends:id:1name:"ann"id:2name:"tom";let MessageQuery = "Message""myPost";MessageQuery;MessageQuery;console;/*myPost:Message( type:"chat",message:"yoyo",user:{name:"bob",screen:{height:1080,width:1920}},friends:[{id:1,name:"ann"},{id:2,name:"tom"}]){messageId : id,postedTime : createTime}*/// Simple nestinglet user = "user";user/*user {profilePicture {uri,width,height}}*/// Simple nesting with renamelet user = "user";user/*user {image : profilePicture {uri,width,height}}*/