Skip to content

Instantly share code, notes, and snippets.

@arunoda
Created September 21, 2015 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arunoda/f91b9a9defb902ed1e8f to your computer and use it in GitHub Desktop.
Save arunoda/f91b9a9defb902ed1e8f to your computer and use it in GitHub Desktop.
var graphql = require('graphql');
var userType = new graphql.GraphQLObjectType({
name: 'User',
fields: () => ({
id: {type: graphql.GraphQLString},
name: {type: graphql.GraphQLString},
friends: {
type: new graphql.GraphQLList(userType),
args: {
close: {type: graphql.GraphQLBoolean}
},
resolve: function(_, args) {
if(args.close) {
return [{id: "close", name: "close friend"}]
} else {
return [{id: "not-close", name: "not close friend"}];
}
}
}
})
});
var schema = new graphql.GraphQLSchema({
query: new graphql.GraphQLObjectType({
name: 'Query',
fields: {
user: {
type: userType,
args: {
id: {type: graphql.GraphQLString, required: true}
},
resolve: function(_, args) {
console.log('Args:', args);
return {id: 'one', name: "Arunoda", friends: [100, 200, 300]};
}
}
}
})
});
var query = `
{
user {
name,
friends(close: true) {
name,
friends(close: true) {
name
}
}
}
}
`;
graphql.graphql(schema, query).then(result => {
console.log(JSON.stringify(result, null, 2));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment