2.x - Aliases do not work with default resolvers in merged schemas
See original GitHub issueI opened an issue on graphql-js: https://github.com/graphql/graphql-js/issues/1530#event-1862105684
Comment by Dan https://github.com/apollographql/apollo-server/issues/1724#issuecomment-425596109
This issues doesn’t seem to be related to fragments. Aliases do not appear to be working with default resolvers in merged schemas:
OP:
Basically, when using fragments in a hierarchy like the below query, aliases don’t work and can return non-nullable
errors or they simply just cause the objects to be null
.
It appears that my issue may not be related to the parser itself. This is a bug that was introduced when I upgraded to Apollo Server 2.x. I even rolled back every package except apollo-server
to what I had before and the issue persists.
Playground: https://pinto-hip.glitch.me
Issue the query:
{
books {
name
categoryHierarchy {
...category
categories {
...category
}
}
}
}
fragment category on Category {
abc: name
}
Error:
{
"data": {
"books": [
{
"name": "Harry Potter and the Chamber of Secrets",
"categoryHierarchy": [
null
]
},
{
"name": "Jurassic Park",
"categoryHierarchy": [
null
]
}
]
},
"errors": [
{
"message": "Expected Iterable, but did not find one for field Category.categories.",
"locations": [
{
"line": 6,
"column": 7
}
],
"path": [
"books",
0,
"categoryHierarchy",
0,
"categories"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: Expected Iterable, but did not find one for field Category.categories.",
" at invariant (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/jsutils/invariant.js:19:11)",
" at completeListValue (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:673:65)",
" at completeValue (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:643:12)",
" at completeValue (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:629:21)",
" at completeValueWithLocatedError (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:580:21)",
" at completeValueCatchingError (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:550:12)",
" at resolveField (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:497:10)",
" at /rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:364:18",
" at Array.reduce (<anonymous>)",
" at executeFields (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:361:42)"
]
}
}
},
{
"message": "Expected Iterable, but did not find one for field Category.categories.",
"locations": [
{
"line": 6,
"column": 7
}
],
"path": [
"books",
1,
"categoryHierarchy",
0,
"categories"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: Expected Iterable, but did not find one for field Category.categories.",
" at invariant (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/jsutils/invariant.js:19:11)",
" at completeListValue (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:673:65)",
" at completeValue (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:643:12)",
" at completeValue (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:629:21)",
" at completeValueWithLocatedError (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:580:21)",
" at completeValueCatchingError (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:550:12)",
" at resolveField (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:497:10)",
" at /rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:364:18",
" at Array.reduce (<anonymous>)",
" at executeFields (/rbd/pnpm-volume/0897a123-e913-41b8-a689-0921f96aa33a/node_modules/.registry.npmjs.org/graphql/0.13.2/node_modules/graphql/execution/execute.js:361:42)"
]
}
}
}
]
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:12
Top GitHub Comments
This issues doesn’t seem to be related to fragments. Aliases do not appear to be working with default resolvers in merged schemas:
This doesn’t work:
This does:
The error message is correct Your bug is here:
You aren’t returning an Iterable (array) for the first level of
categories
. Should be: