Skip to content

Graphql : Cannot return null for non-nullable field #902

@sushicodeur

Description

@sushicodeur

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 ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions