graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Federation @join__field requires parameter handling improvement

Open aarne opened this issue 1 year ago • 0 comments
trafficstars

Issue workflow progress

Progress of the issue based on the Contributor Workflow

  • [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox

    Make sure to fork this template and run yarn generate in the terminal.

    Please make sure the GraphQL Tools package versions under package.json matches yours.

  • [ ] 2. A failing test has been provided
  • [ ] 3. A local solution has been provided
  • [ ] 4. A pull request is pending review

Describe the bug

Given this snipped from a working supergraph schema.

type Environment {
  id: ID!
}

type Whatever {
  id: ID!
  environment: Environment! @join__field(graph: ACCOUNTS)  @join__field(graph: LOCAL, external: true) 
  external1: String @join__field(graph: LOCAL, requires: "id environment {id}") 
  external2: String @join__field(graph: LOCAL, requires: "id environment{id}") 
}

The resolver for external1 will receive the required fields correctly. But external2 will get only the id field correctly filled. The difference is only the space.

Not sure what is the best way to fix this, but i assume this is driven from utils/getKeyFnForFederation. The function considers the first level keys (split by space) only.

I think we have 2 options:

  • keep current simple logic and split the key until first { - will still give you the whole subtree (might be more data than needed)
  • we could parse the whole selectionSet and recursively filter the root value.

aarne avatar Feb 17 '24 10:02 aarne