ardatan / ardatan/graphql-tools

Stitched schema does return "null" for aliased fields in union types

Open
#4,394 11 comments 0 reactions 0 assignees View on GitHub
stage/1-reproduction
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 [here](https://github.com/xddq/stitch-alias-null)
- [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review

---

**Describe the bug**

- Aliased attributes in union types resolve to null instead of their correct value when using schema stitching to combine two remote schemas.
- The same query returns the correct result on the "non-stitched" schema when issued to the non-stitched schema at localhost:/4001/graphql

**To Reproduce**
Steps to reproduce the behavior:
- checkout the [github repo](https://github.com/xddq/stitch-alias-null)
- follow the README.md steps:
- `npm i && npm run start`
- gateway on localhost:4444/graphql
- remote-1 on localhost:4001/graphql
- remote-2 on localhost:4002/graphql
- go to localhost:4444/graphql (the stitched schema) and query
-
```
query {articles {title {
... on TitleOne {text}
... on TitleTwo {renamedText: text}
}}}
```

**Expected behavior**
- result should contain correct values. E.g.
```
{
"data": {
"articles": [
{
"title": {
"text": "hello world"
}
},
{
"title": {
"renamedText": 1
}
},
{
"title": {
"renamedText": 2
}
},
{
"title": {
"text": "bye"
}
}
]
}
}

```

** Actual Behaviour **
- result contains "null" for aliased fields

```
{
"data": {
"articles": [
{
"title": {
"text": "hello world"
}
},
{
"title": {
"renamedText": null
}
},
{
"title": {
"renamedText": null
}
},
{
"title": {
"text": "bye"
}
}
]
}
}

```

**Environment:**

- OS: ubuntu 18.04
- "@graphql-tools/load": "^7.5.8",
- "@graphql-tools/schema": "^8.3.8",
- "@graphql-tools/stitch": "^8.6.6",
- "@graphql-tools/url-loader": "^7.9.11",
- "@graphql-tools/wrap": "^8.4.13",
- NodeJS: v14.19.1

Contributor guide

Open the contributing guide

Research direction

Start with the linked xddq/stitch-alias-null reproduction and follow its README steps to run the gateway and remote schemas. Run the aliased union-type query against localhost:4444/graphql and compare it with localhost:4001/graphql; done means the stitched gateway returns the expected non-null aliased values.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.