Created
September 21, 2015 21:46
-
-
Save arunoda/f91b9a9defb902ed1e8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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