When I upgrade graphql-tools to ^3.0.0 (or when I use { makeExecutableSchema, mergeSchemas } from apollo-server-express ^2.0.0), I get the following error when I run one of my resolvers:
authenticatedSchemaServer: response: { data: { allClients: null },
errors:
[ { GraphQLError: Cannot read property 'map' of null
message: 'Cannot read property \'map\' of null',
locations: [Array],
path: [Array],
extensions: [Object] } ],
extensions: { cacheControl: { version: 1, hints: [Array] } } }
[2018-07-20T19:44:07.063Z] ERROR: nexus/22950 on DESKTOP-DOVO15N: Cannot read property 'map' of null
err: {
"message": "Cannot read property 'map' of null",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"allClients"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"TypeError: Cannot read property 'map' of null",
" at /mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/src/transforms/AddArgumentsAsVariables.ts:67:59",
" at Array.map (<anonymous>)",
" at addVariablesToRootField (/mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/src/transforms/AddArgumentsAsVariables.ts:66:36)",
" at AddArgumentsAsVariablesTransform.transformRequest (/mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/src/transforms/AddArguments
AsVariables.ts:31:11)",
" at /mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/src/transforms/transforms.ts:24:21",
" at Array.reduce (<anonymous>)",
" at Object.applyRequestTransforms (/mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/src/transforms/transforms.ts:21:21)",
" at /mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/src/stitching/delegateToSchema.ts:76:28",
" at step (/mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)",
" at Object.next (/mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)",
" at /mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:7:71",
" at new Promise (<anonymous>)",
" at __awaiter (/mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:3:12)",
" at delegateToSchemaImplementation (/mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:57:12)",
" at Object.delegateToSchema [as default] (/mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/src/stitching/delegateToSchema.ts:44:10)
",
" at Object.delegateToSchema (/mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/src/stitching/mergeSchemas.ts:354:30)"
]
}
}
}
The resolver works fine when I downgrade to graphql-tools ^2.24.0:
[2018-07-20T20:24:42.700Z] DEBUG: nexus/23805 on DESKTOP-DOVO15N: authenticatedSchemaServer: Query nesting depth: { '': 1 }
[2018-07-20T20:24:42.702Z] DEBUG: nexus/23805 on DESKTOP-DOVO15N: Client.getClientsBaseInfo:
{ method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [],
__knexQueryUid: '8ef5057d-616d-4c24-a14d-d977e1253d5c',
sql: 'select * from "anewgo"."clients" order by "alt_name" asc' }
authenticatedSchemaServer: response: { data:
{ allClients:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ] },
extensions: { cacheControl: { version: 1, hints: [Array] } } }
I have the same issue, in my case, it triggers when I query with a Query Definition without a name
{ User { name } }, if i name it query userName { User { name } } it does not throws.
@edgarjrg : awesome, that was very helpful, thanks.
I confirmed that is the case.
In the GraphQL Playground, if I try running the query
{
allClients {
id
}
}
or
query {
allClients {
id
}
}
, it fails with the 'Cannot read property \'map\' of null' error.
However, if I try running this named query
query queryWithAName {
allClients{
id
}
}
, then it works.
Any workaround found for this issue?
@edgarjrg The work around I used was to give my queries names. Another workaround I used earlier was to downgrade graphql-tools to 2.x; can you clarify what kind of workaround you are looking for?
@edelreal I regex the query in a middleware to see if it has a name and if not append one, but then ran into: https://github.com/apollographql/graphql-tools/issues/743. I tried to downgrade to 2.x but was using the transforms of 3.x heavily, and it did not work well using the 2 lib versions (the transforms did not return the expected values.)
This stale issue appears to be fixed. Please reopen if necessary.
Most helpful comment
I have the same issue, in my case, it triggers when I query with a Query Definition without a name
{ User { name } }, if i name itquery userName { User { name } }it does not throws.