New to GraphQL, I'm having problems sending a query through GraphiQL.
This is my schema.js
const graphql = require('graphql');
const _ = require('lodash');
const{
GraphQLObjectType,
GraphQLInt,
GraphQLString,
GraphQLSchema
} = graphql;
const users = [
{id:'23', firstName:'Bill', age:20},
{id:'47', firstName:'Samantha', age:21}
];
const UserType = new GraphQLObjectType({
name: 'User',
fields:{
id: {type: GraphQLString},
firstName: {type: GraphQLString},
age:{type: GraphQLInt}
}
});
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields:{
user: {
type: UserType,
args:{
id: {type: GraphQLString}
},
resolve(parentValue, args){ // move the resolve function to here
return _.find(users, {id: args.id});
}
},
}
});
module.exports = new GraphQLSchema({
query: RootQuery
});
And when I run the following query on graphiql:
query {
user {
id: "23"
}
}
I got "Syntax Error GraphQL request (3:9) Expected Name, found String", but I would expect to get the user with id "23".
What am I missing?