Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphQL "Cannot return null for non-nullable" [duplicate]

Trying to make my first graphQL server, here's what I have written so far.

https://gist.github.com/tharakabimal/7f2947e805e69f67af2b633268db0406

Following error pops up on GraphQL when I try to filter the users by username.

Error on GraphQL

The error occurs in the users field in UserQueriesQL.js.

Is there anything wrong the way I pass arguments on the resolve functions?

user: {
type: UserType,
args: { 
  username: {
    name: 'username',
    type: new GraphQLNonNull(GraphQLString)
  }
},
resolve: function(parentValue, args) {
  return User.find( args ).exec();
}
like image 667
King Julian Avatar asked Feb 23 '17 06:02

King Julian


1 Answers

As I am beginner into GraphQL, even I ran into this issue. After going through each file individually I found that I forgot to import into my resolvers

import User from './User';
**import Post from './Post';**

const resolvers = [User, **Posts**];

Maybe this will help!

like image 157
Neville Dabreo Avatar answered Sep 19 '22 08:09

Neville Dabreo