ardatan / ardatan/graphql-tools
Federation @join__field requires parameter handling improvement
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 830
- Avg merge
- 10h 59m
- Merged PRs (30d)
- 45
Description
### Issue workflow progress
_Progress of the issue based on the
[Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-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.
```graphql
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](https://github.com/ardatan/graphql-tools/blob/4b56b04d69b02919f6c5fa4f97d33da63f36e8c8/packages/federation/src/utils.ts#L12C17-L12C38). 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.
Contributor guide
Research direction
Read packages/federation/src/utils.ts, especially getKeyFnForFederation, and reproduce the two requires selection sets from the issue. Determine how nested fields with different whitespace are handled; done means external2 receives the nested environment id as external1 does, with coverage for the reported difference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100