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

Issues when using @interfaceObject in combination with fragments #3184

Open
oskargotte opened this issue Nov 12, 2024 · 1 comment
Open

Issues when using @interfaceObject in combination with fragments #3184

oskargotte opened this issue Nov 12, 2024 · 1 comment

Comments

@oskargotte
Copy link

oskargotte commented Nov 12, 2024

Issue Description

Consider these simplified schemas from the interface extension example where Subgraph B extends the Media interface and hence the implementing Book type from Subgraph A with an extra review field.

Subgraph A Subgraph B
interface Media @key(fields: "id") {
  id: ID!
  title: String!
}

type Book implements Media @key(fields: "id"){
  id: ID!
  title: String!
}
type Media @key(fields: "id") @interfaceObject {
  id: ID!
  review: Int!
}

type Query {
  topRatedMedia: [Media!]!
}

One can query for Media with title from Subgraph A and review from Subgraph B like this

topRatedMedia {
  title
  review
}

One can use a fragment to get the review field only for Book types in case there are more implementations of the Media interface

topRatedMedia {
  title
  ... on Book {
    review
  }
}

However, if __typename fields are added to the previous query (which is what the Apollo Client would do)

topRatedMedia {
  __typename
  title
  ... on Book {
    __typename
    review
  }
}

the query fails silently with the data being null, no error in the response and no error in the router logs but an extension in the response

{"data":null,"extensions":{"valueCompletion":[{"message":"Cannot return null for non-nullable array element of type Media at index 0","path":["topRatedMedia",0]},{"message":"Cannot return null for non-nullable field [Media!]!.topRatedMedia","path":["topRatedMedia"]}]}}

Link to Reproduction

https://codesandbox.io/p/devbox/nervous-silence-5rpvys

Steps to reproduce

Open the sandbox link above and try the different queries

@oskargotte
Copy link
Author

Closely related to #2743 which is solved for the queries mentioned in the issue but would still fail on e.g.

  searchProducts {
    id
    ... on Book {
      __typename
      reviews
    }  
  }

Seems like an issue with the query plan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant