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

Enable @requires on root Query types or error on using on root query types #2937

Open
lleadbet opened this issue Feb 15, 2024 · 0 comments
Open

Comments

@lleadbet
Copy link
Contributor

Issue Description

Utilizing @requires on root query fields results in a broken query plan that does not return the required fields.

Link to Reproduction

Code sandbox appears broken?

Reproduction Steps

The code sandbox appears to be broken, so unable to share a working example at the moment.

As a minimum reproducible example, given subgraphs:

1:

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

type Query @key(fields: "__typename") {
  b: B!
}

type B {
  id: ID!
}

and subgraph 2:

extend schema
  @link(
    url: "https://specs.apollo.dev/federation/v2.5"
    import: ["@key", "@inaccessible", "@requires", "@external"]
  )

type Query @key(fields: "__typename") {
  a: A! @requires(fields: "b {id}")
  b: B! @external
}

type A @key(fields: "id") {
  id: ID!
  a: String
}

type B @external {
  id: ID!
}

It will successfully compose. However running the following operation:

query {
  a {
    a
  }
}

Which should in theory require:

b {id}, but does not; the query plan for this results in:

QueryPlan {
  Sequence {
    Fetch(service: "2") {
      {
        a {
          a
        }
      }
    },
    Flatten(path: "") {
      Fetch(service: "1") {
        {
          ... on Query {
            b {
              id
            }
          }
        }
      },
    },
  },
}

Which basically does the inverse of what is required.

This ideally should either be A) allowed and properly handled or B) fail composition as the behavior is not supported/is broken.

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