apollographql / federation

🌐  Build and scale a single data graph across multiple services with Apollo's federation gateway.
https://apollographql.com/docs/federation/
Other
669 stars 254 forks source link

INTERFACE_OBJECT_USAGE_ERROR when using @interfaceObject and contributing fields to an implementing type #3185

Open oskargotte opened 1 week ago

oskargotte commented 1 week ago

Issue Description

I'm trying to compose a supergraph where one of the subgraph is referencing an interface from the other subgraph with the @interfaceObject directive. It is not adding any fields, it just needs to define the type to be able to use it in queries. However, the subgraph also extends one of the implementing types with a field and hence I get the INTERFACE_OBJECT_USAGE_ERROR with the error message Interface type "Media" is defined as an @interfaceObject in subgraph "b" so that subgraph should not define any of the implementation types of "Media", but it defines type "Movie"

The documentation says that "If a subgraph contributes entity fields via @interfaceObject, it "gives up" the ability to contribute fields to any individual entity that implements that interface."

But in this case I'm not contributing any fields to the interface via @interfaceObject so I would argue that the compose validation is a bit too restrictive in this case.

The following schemas can be used for reproduction

Subgraph A Subgraph B
```graphql interface Media @key(fields: "id") { id: ID! title: String! } type Book implements Media @key(fields: "id") { id: ID! title: String! } type Movie implements Media @key(fields: "id") { id: ID! title: String! } ``` ```graphql type Media @key(fields: "id", resolvable: false) @interfaceObject { id: ID! } type Movie @key(fields: "id") { id: ID! imdbScore: Int! } type Query { numberOneMedia: Media! } ```

Link to Reproduction

https://codesandbox.io/p/devbox/amazing-dirac-mrm9sj

Reproduction Steps

Go to the sandbox and check the terminal output or try to compose the schemas above into a supergraph with rover.