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

Unable to add an interface extending an entity interface without breaking dependent subgraphs #2936

Open
bluepichu opened this issue Feb 14, 2024 · 0 comments

Comments

@bluepichu
Copy link

bluepichu commented Feb 14, 2024

Issue Description

Consider these subgraphs:

ProductsReviews
extend schema @link(
  url: "https://specs.apollo.dev/federation/v2.3"
  import: ["@key", "@interfaceObject"]
)

type Query {
  products: [Product]
}

interface Product @key(fields: "id") {
  id: String!
  name: String
}

interface PhysicalProduct implements Product @key(fields: "id") {
  id: String!
  name: String
  weight: Int
}

type Book implements PhysicalProduct & Product @key(fields: "id") {
  id: String!
  name: String
  weight: Int
}

type Pen implements PhysicalProduct & Product @key(fields: "id") {
  id: String!
  name: String
  weight: Int
}

type Movie implements Product @key(fields: "id") {
  id: String!
  name: String
}
extend schema @link(
  url: "https://specs.apollo.dev/federation/v2.3"
  import: ["@key", "@interfaceObject"]
)

type Query {
  reviews: [Review]
}

type Review {
  id: String!
  content: String
}

type Product @key(fields: "id") @interfaceObject {
  id: String!
  reviews: [Review]
}

I would expect this to compose ok, because the gateway should understand that all PhysicalProduct objects are also Product objects, so resolving reviews on them should be possible via the reviews subgraph. However, attempting to compose the above results in an error:

Interface field "Product.reviews" is declared in  but type "PhysicalProduct", which implements "Product" only in subgraph "products" does not have field "reviews".

This can be worked around by instead declaring the following in the reviews subgraph:

type Product @key(fields: "id") @interfaceObject {
  id: String!
  reviews: [Review] @shareable
}

type PhysicalProduct @key(fields: "id") @interfaceObject {
  id: String!
  reviews: [Review] @shareable
}

But this solution is pretty undesirable, since it means that we can't actually separate concerns between the two subgraphs (as the reviews subgraph needs to be aware of all interfaces extending Product in the products subgraph instead of just the Product interface).

Link to Reproduction

https://codesandbox.io/p/devbox/stoic-jennings-dmtcpt?workspaceId=f349a0f5-d280-4992-b1d5-8f95a3bc8dda

@bluepichu bluepichu changed the title Unable to add an interface extending an entity interface Unable to add an interface extending an entity interface without breaking dependent subgraphs Feb 14, 2024
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