Cannot return null for non-nullable field 🔌 API

GraphQL: Cannot return null for non-nullable field Query.user

A resolver returned null (or threw) for a field the schema marks as non-null (!), so GraphQL nulls out the parent and reports this error.

Seen on: REST API

Meaning

The real cause is usually in the resolver: not found records, an exception, a missing return, or a field name mismatch between the resolver result and the schema.

Common causes

  • Resolver returns null/undefined (record not found, missing return)
  • Resolver threw an error
  • Returned object uses different property names
  • Schema says non-null where null is legitimately possible

⚡ Quick fix

  1. Check server logs for the resolver error
  2. Return a value or make the field nullable
  3. Map database fields to schema names

Detailed fix by platform

JavaScript

  1. javascript
    const resolvers = { Query: { user: async (_, { id }, { db }) => {
      const u = await db.user.findUnique({ where: { id } });
      if (!u) throw new GraphQLError("User not found", { extensions: { code: "NOT_FOUND" } });
      return u;
    } } };

How to diagnose

  1. Path — errors[].path
  2. Logs — Resolver exceptions
  3. Schema — Non-null correct?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.