Skip to content

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

@oskargotte

Description

@oskargotte

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
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!
}
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions