Cannot return null for non-nullable field User.id


#1

Query

query {
  user {
    id
  }
}

Query.js file

async function user(parent, args, context) {


  const user = await context.prisma.users({
    where: {
      id_contains: args.id
    },
    first: args.first,
    orderBy: args.orderBy,
  });

  return {
    user,
  }

}


module.exports = {
  user,
}

ERROR:

{
  "data": null,
  "errors": [
    {
      "message": "Cannot return null for non-nullable field User.id.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "user",
        "id"
      ]
    }
  ]
}

what am I doing wrong??


#2

Hi @RecoX,

From the query that you are making I assume you are willing to query the details of a single user. You need to use the user method provided by prisma not the users one. I have made a PR in your . repository fixing you issue.

You are now able to query the user by it’s ID like so:

Let me know if you have any further questions.


#3

Hey @pantharshit00 could you explain why do we have to do it this way??


#5