user: {
type: UserType,
args: {
username: { type: new GraphQLNonNull(GraphQLString) }
},
resolve: function(parentValue, args) {
return User.find( args ).exec(); // User.find({username: 'some name'}).exec();
// will work as matches your mongoose schema
}
Previously, in the args
you are providing an an object
with nested object username
so,
args: { // this won't match your mongoose schema field as it's nested object
username: {
name: 'username',
type: new GraphQLNonNull(GraphQLString)
}
}
so when the user queries and provides args then
your args would be { username: { name: 'abcd' } }
// args = {username: {name: 'abcd'}}
and resolve()
is executing User.find({username: {name: 'abcd'}}).exec();
/* searching for username{} object, but
your mongoose schema is username: String */
which doesn't match your database fields, which will always return an empty array []
,also which will not match your GraphQL field type, as it is GraphQLNonNull
after viewing the gist
the problem is with rootquery
the problem is with rootquery
let RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: () => ({
users: { type:UserQueries.users, resolve: UserQueries.users }
user: { type: UserQueries.user, resolve: UserQueries.user }
})
});