question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Graphql : Cannot return null for non-nullable field

See original GitHub issue

Hello,

I’ve got a very strange problem using graphql.

When I list some Contacts (note: this is the entity used by doctrine_user_provider to check login) :

{
  contacts(first: 30, after: "MjAw") {
    edges {
      node {
        _id
        salesforceId
        email
        role
        passwordSent
        firstName
        lastName
        phone
        mobilePhone
        function {
          id
          label
        }
        contactOwner {
          id
          salesforceId
        }
        account {
          salesforceId
        }
        contactTitle {
          salesforceId
        }
        department {
          salesforceId
        }
        lastUpstreamSync
      }
    }
  }
}

I’ve got for one contact (id 219) this error :

{
  "errors": [
    {
      "debugMessage": "Cannot return null for non-nullable field Contact.role.",
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 8,
          "column": 9
        }
      ],
      "path": [
        "contacts",
        "edges",
        16,
        "node",
        "role"
      ]
    }
  ],
  "data": {
    "contacts": {
      "edges": [
        // some contacts...
        {
          "node": null
        },
        // some contacts...
      ]
    }
  }
}

All other Contacts are returning fine, just this one (and only this one) fails to return properly. I’ve double checked what value in db could lead to such a problem, the record seems fine, no strange data, some expected null fields, no null in not null fields…

If I query this item with the same fields, it’s all ok:

{
  contact(id: "/v2/contacts/219") {
      _id
      salesforceId
      email
      role
      passwordSent
      firstName
      lastName
      phone
      mobilePhone
      function {
        id
        label
      }
      contactOwner {
        id
        salesforceId
      }
      account {
        salesforceId
      }
      contactTitle {
        salesforceId
      }
      department {
        salesforceId
      }
      lastUpstreamSync
    }
}

returns:

{
  "data": {
    "contact": {
      "_id": 219,
      "salesforceId": "obfurscated",
      "email": "obfurscated@obfurscated.fr",
      "role": "ROLE_ADMINISTRATOR",
      "passwordSent": false,
      "firstName": "obfurscated",
      "lastName": "obfurscated",
      "phone": "",
      "mobilePhone": "obfurscated",
      "function": {
        "id": "\/v2\/contact_functions\/18",
        "label": "Direction"
      },
      "contactOwner": null,
      "account": null,
      "contactTitle": {
        "salesforceId": "obfurscated"
      },
      "department": {
        "salesforceId": "obfurscated"
      },
      "lastUpstreamSync": null
    }
  }
}

If i change the field role to accept nullable :

    /**
     * @var string role
     *
     * @ORM\Column(type="string", length=60, unique=false, nullable=true)
     */
    private $role = "NO_ACCESS";

Then the list query raises no error but returns this :

{
  "data": {
    "contacts": {
      "edges": [
        // some contacts...
        {
          "node": {
            "_id": 219,
            "salesforceId": "obfurscated",
            "email": null,
            "role": null,
            "passwordSent": null,
            "firstName": null,
            "lastName": null,
            "phone": null,
            "mobilePhone": null,
            "function": null,
            "contactOwner": null,
            "account": null,
            "contactTitle": null,
            "department": null,
            "lastUpstreamSync": null
          }
        },
        // some contacts...
      ]
    }
  }
}

What could lead to such a behavior, where should I look ?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tmsnvdcommented, Jan 6, 2020

As I understand, the essence of graphql is to get data from backend without changing it, in this case, I must change backend entities in order to get additional data in front. Makes no sense.

1reaction
BernardAcommented, Dec 20, 2019

I found what my issue was. I have a normalizer that adds a group “get-owner” to context and my properties were missing that group. So, it is a good idea to check your normalization groups.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why am I getting a "Cannot return null for non-nullable field ...
The biggest problem with your resolver is that in any number of scenarios, instead of returning a User object, you return a string....
Read more >
`Cannot return null for non-nullable field` when throwing error
When querying me without ctx.user set, it returns 2 errors instead of 1. Errors: Error: MISSING_AUTHENTICATION Cannot return null for non- ...
Read more >
Cannot return null for non-nullable type graphql - Fauna Forums
I get the following error when i query allTodos index through graphql "errors": [ { "message": "Cannot return null for non-nullable type ...
Read more >
GraphQL Nullability - Episode #42
The GraphQL type system has built-in support for null, and non-null fields. GraphQL is null by default. Consider the following schema:
Read more >
Issue in "Exploring our first query" - Help - Apollo GraphQL
While trying to run the first tracksForHome query, I get the below error: { "errors": [ { "message": "Cannot return null for non-nullable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found