graphql-go-tools icon indicating copy to clipboard operation
graphql-go-tools copied to clipboard

Errors are sometimes omitted when bubbling nulls up to nullable types

Open dnerdy opened this issue 3 years ago • 0 comments

When null is returned for a non-nullable field, graphql-go-tools usually bubbles the null to the nearest nullable parent and adds an error indicating that the original field with the null value couldn't be resolved. This doesn't always happen, though.

Here are some examples that can be run in the examples/federation playground:

query($skip:Boolean!){
  me {
    reviews {
      author {
        username
      }
      body @skip(if:$skip)
      product {
        name 
      }
    }
  }
}

Returns:

{
  "data": {
    "me": {
      "reviews": [
        null,
        null
      ]
    }
  }
}

In this case "body" is non-nullable, so the null due to the @skip (which itself is a bug reported in #320) bubbles up to the nearest nullable type, which is Review (hence the list of nulls).

Note the lack of an error.

Here's another example:

query($skip:Boolean!){
  me {
    username @skip(if:$skip)
  }
}

Returns:

{
  "data": {
    "me": null
  }
}

Here are an example that works as expected:

query($skip:Boolean!){
  me {
    reviews {
      author {
        username
      }
      body
      product {
        name @skip(if:$skip)
      }
    }
  }
}

Returns:

{
  "errors": [
    {
      "message": "unable to resolve",
      "locations": [
        {
          "line": 9,
          "column": 9
        }
      ],
      "path": [
        "me",
        "reviews",
        "0",
        "product"
      ]
    },
    {
      "message": "unable to resolve",
      "locations": [
        {
          "line": 9,
          "column": 9
        }
      ],
      "path": [
        "me",
        "reviews",
        "1",
        "product"
      ]
    }
  ],
  "data": {
    "me": {
      "reviews": [
        null,
        null
      ]
    }
  }
}

(Though I believe in this case the path should be [..., "product", "name"] instead of ending at just "product" according to the section of the GraphQL spec on this matter.)

dnerdy avatar Jan 21 '22 13:01 dnerdy