Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors are sometimes omitted when bubbling nulls up to nullable types #321

Open
dnerdy opened this issue Jan 21, 2022 · 0 comments
Open
Labels
internally-reviewed Internally reviewed

Comments

@dnerdy
Copy link
Contributor

dnerdy commented Jan 21, 2022

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.)

@StarpTech StarpTech added the internally-reviewed Internally reviewed label Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internally-reviewed Internally reviewed
Projects
None yet
Development

No branches or pull requests

2 participants