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

Support case where nullable entity can not be resolved #2589

Open
jhanggi opened this issue May 19, 2023 · 0 comments
Open

Support case where nullable entity can not be resolved #2589

jhanggi opened this issue May 19, 2023 · 0 comments
Labels
P3 An issue that should be addressed when able.

Comments

@jhanggi
Copy link

jhanggi commented May 19, 2023

Issue Description

We have a case where we have one subgraph that might have references to entities that don't exist or no longer exist. We're ok with this ending up null in the response and our schema represents that. The data is coming back in the form with want (with appropriate nulls), but there are errors that we don't care about.

In our reproduction, we're fine if the product comes back null.

type Review {
  id: String!
  content: String
  product: Product # nullable
}

This seems like #2374, but the errors I'm seeing are on the base errors and not extensions. Additionally, I don't understand how that author is successfully returning null from the __resolveReference.

Link to Reproduction

https://codesandbox.io/p/sandbox/empty-dawn-1qwky5?file=%2Fsrc%2Freviews.ts%3A9%2C32

Reproduction Steps

Run this query on port 4000 (the supergraph):

query ExampleQuery {
  reviews {
    id
      product {
        id
        name
        __typename
        ... on Book {
          author
        }
        ... on Movie {
          director
        }
      }
  
  }
}

There are two scenarios in the reviewData array and it probably makes sense to flip between them by commenting one of them out at a time.

The first case is where there is a productId that doesn't exist over in the product subgraph (id: 3). I've tried various ways of handling this, though ideally I would just return null from the __resolveReference and call it a day. But that raises an error Abstract type \"Product\" __resolveReference method must resolve to an Object type at runtime. I'm not sure how to handle this one. One thing I tried is a generic UnsupportedProduct, and that mostly worked, but honestly I'd rather have a null.

The second case is when the review does not have a productId. In this case, it never even tries to call the product __resolveReference. It returns the null in the data as desired, but there's an error Cannot return null for non-nullable field Product.id.. This seems like #2374, but it's on response.errors not extensions.

Thanks for the help!

@korinne korinne added the P3 An issue that should be addressed when able. label May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 An issue that should be addressed when able.
Projects
None yet
Development

No branches or pull requests

2 participants