ardatan / ardatan/graphql-tools
Aliasing not working if multiple stiched layers are used
- 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)_
- [x] 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**
We are experiencing an aliasing issue in a multilayer stitching setting. The issue is that once an alias is used within the query the aliasing is lost somewhere within the stiching process. I am fairly new to GraphQL and GraphQL Tools and could not narrow it down further. The reproduction is a the bare minimum required to trigger the issue.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to https://codesandbox.io/s/5nfdct?file=/index.js
2. Issue the following Query:
```
{
film(id: "ZmlsbXM6MQ==") {
id
x: title
planetConnection{
planets {
name
}
baz: newProp {
id
title
}
}
}
}
```
The query is only partially successful with the following output:
```
{
"errors": [
{
"message": "Cannot return null for non-nullable field FilmPlanetsConnection.newProp.",
"locations": [
{
"line": 9,
"column": 7
}
],
"path": [
"film",
"planetConnection",
"baz"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: Cannot return null for non-nullable field FilmPlanetsConnection.newProp.",
" at completeValue (/Users/mairt/Downloads/apollo-tools-bug-repro-forked/node_modules/graphql/execution/execute.js:594:13)",
" at executeField (/Users/mairt/Downloads/apollo-tools-bug-repro-forked/node_modules/graphql/execution/execute.js:489:19)",
" at executeFields (/Users/mairt/Downloads/apollo-tools-bug-repro-forked/node_modules/graphql/execution/execute.js:413:20)",
" at completeObjectValue (/Users/mairt/Downloads/apollo-tools-bug-repro-forked/node_modules/graphql/execution/execute.js:914:10)",
" at completeValue (/Users/mairt/Downloads/apollo-tools-bug-repro-forked/node_modules/graphql/execution/execute.js:635:12)",
" at /Users/mairt/Downloads/apollo-tools-bug-repro-forked/node_modules/graphql/execution/execute.js:486:9",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at async Promise.all (index 2)"
]
}
}
}
],
"data": {
"film": {
"id": "ZmlsbXM6MQ== id",
"x": "ZmlsbXM6MQ== film title",
"planetConnection": null
}
}
}
```
**Expected behavior**
The query should have the following output:
```
{
"data": {
"film": {
"id": "ZmlsbXM6MQ== id",
"x": "ZmlsbXM6MQ== film title",
"planetConnection": {
"planets": [
{
"name": "0.41128816183728456 name"
}
],
"baz": {
"id": "ZmlsbXM6Mw== id",
"title": "ZmlsbXM6Mw== film title"
}
}
}
}
}
```
**Additional context**
The issue does not manifest itself if in the last layer the `defaultMergedResolver` is used (see comment in repro).
The issue is also no present when the alias on the `newProp` field is removed.
```
{
film(id: "ZmlsbXM6MQ==") {
id
x: title
planetConnection{
planets {
name
}
newProp {
id
title
}
}
}
}
```
Contributor guide
Research direction
Start with the linked CodeSandbox at index.js and run the provided reproduction query after running yarn generate. Compare the multilayer stitching behavior with and without defaultMergedResolver, and with the newProp alias removed. Done means the aliased query preserves baz and returns the expected nested data without an error.
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