0
votes

I'm training ReactJS with ApolloServer for my personal project. i created a Type User with yours queries and mutations.

type User {
id: ID!      
name: String
password: String!
email: String!  
}

type Query {
  users: [User!]!
  user(id: ID!): User
}

input UserInput{
name: String
password: String!
email: String! 
}

type Mutation {
  createUser(data: UserInput): User!
  updateUser(id: ID!, data: UserInput!): User!
  deleteUser(id: ID!): Boolean
}

My Mutation:

createUser: async (_, { data }, { pubsub }) => {
      console.log(data)
      const { password, ...rest } = data
      const hashPassword = await bcrypt.hashSync(password, 10)
      const user = await prisma.user.create({
        data: {
          password: hashPassword,
          ...rest
        }
      })
      /* pubsub.publish(USER_ADDED, {
        userAdded: user
      }) */
      return user
    },

Command I used to perform the mutation:

mutation {
  createUser(
    data:{
      name: "Renato",
      password: "12345",
      email: "[email protected]"
    }
  ){
    id
  }
}

But when i execute a mutation createUser with this command, return this:

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field Mutation.createUser.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "createUser"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Cannot return null for non-nullable field Mutation.createUser.",
            "    at completeValue (/home/renato/Documents/workspace/rntjr/react-graphql-authentication-example/server/node_modules/graphql/execution/execute.js:560:13)",
            "    at completeValueCatchingError (/home/renato/Documents/workspace/rntjr/react-graphql-authentication-example/server/node_modules/graphql/execution/execute.js:495:19)",
            "    at resolveField (/home/renato/Documents/workspace/rntjr/react-graphql-authentication-example/server/node_modules/graphql/execution/execute.js:435:10)",
            "    at /home/renato/Documents/workspace/rntjr/react-graphql-authentication-example/server/node_modules/graphql/execution/execute.js:244:18",
            "    at /home/renato/Documents/workspace/rntjr/react-graphql-authentication-example/server/node_modules/graphql/jsutils/promiseReduce.js:23:10",
            "    at Array.reduce (<anonymous>)",
            "    at promiseReduce (/home/renato/Documents/workspace/rntjr/react-graphql-authentication-example/server/node_modules/graphql/jsutils/promiseReduce.js:20:17)",
            "    at executeFieldsSerially (/home/renato/Documents/workspace/rntjr/react-graphql-authentication-example/server/node_modules/graphql/execution/execute.js:241:37)",
            "    at executeOperation (/home/renato/Documents/workspace/rntjr/react-graphql-authentication-example/server/node_modules/graphql/execution/execute.js:219:55)",
            "    at executeImpl (/home/renato/Documents/workspace/rntjr/react-graphql-authentication-example/server/node_modules/graphql/execution/execute.js:104:14)"
          ]
        }
      }
    }
  ],
  "data": null
}

My github project for analysis: https://github.com/rntjr/react-graphql-authentication-example/tree/develop/server

1
Please check the user or its fields to see if they exist - slideshowp2
Are all registered - Im not a dev

1 Answers

0
votes

I had this same message popping up in my terminal when I was testing a mutation. In the project I was working in I had the resolver in a different file from the command to perform the mutation (In your case, something like the third image) After +30 minutes searching for the error I realized that my resolver was not being exported correctly. I had module.export = { resolverName } instead of module.exports = { resolverName } and thus my mutation command couldn't communicate with my resolver.