enisdenjo / graphql-composite

Spec agnostic GraphQL composite schema planner, executor and explainer.
MIT License
7 stars 0 forks source link

Remove non-resolvable fragments from the query #37

Closed kamilkisiela closed 5 months ago

kamilkisiela commented 5 months ago

Given these subgraphs:

A

type Query {
  nodes: [Node]
}

interface Node {
  id: ID!
}

type Oven @key(fields: "id") {
  id: ID!
}

type Toaster implements Node @key(fields: "id") {
  id: ID!
  warranty: Int
}

B

interface Node {
  id: ID!
}

type Oven implements Node @key(fields: "id") {
  id: ID!
  warranty: Int
}

And the following query:

query {
  nodes {
    ... on Oven { id }
    ... on Toaster { id }
  }
}

The Oven and Toaster object types both implement the Node interface in the public API schema. It looks like Oven could be queries through Query.nodes, but in reality, it's not true. The Oven is never resolved by Query.nodes as Oven object type is not implementing Node interface in the subgraph that defines Query.nodes (A).

The gateway should remove ... on Oven fragment from the query and pass the following query to the subgraph A:

query {
  nodes {
    ... on Toaster { id }
  }
}