Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running a query that has no name fails in addVariablesToRootField() with: Cannot read property 'map' of null at /mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/src/transforms/AddArgumentsAsVariables.ts:67:59 #900

Closed
1 of 5 tasks
edelreal opened this issue Jul 20, 2018 · 6 comments
Labels
has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository

Comments

@edelreal
Copy link

edelreal commented Jul 20, 2018

  • has-reproduction
  • feature
  • docs
  • blocking
  • good first issue

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] } } }
@ghost ghost added the has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository label Jul 20, 2018
@codingedgar
Copy link

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.

@edelreal
Copy link
Author

edelreal commented Jul 24, 2018

@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.

@edelreal edelreal changed the title Stiched schema fails in addVariablesToRootField(): Cannot read property 'map' of null at /mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/src/transforms/AddArgumentsAsVariables.ts:67:59 Running a query that has no name fails in addVariablesToRootField() with: Cannot read property 'map' of null at /mnt/c/Users/pixel/git/nexus/node_modules/graphql-tools/src/transforms/AddArgumentsAsVariables.ts:67:59 Jul 24, 2018
@ghost ghost added the has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository label Jul 24, 2018
@codingedgar
Copy link

Any workaround found for this issue?

@edelreal
Copy link
Author

edelreal commented Aug 6, 2018

@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?

@codingedgar
Copy link

@edelreal I regex the query in a middleware to see if it has a name and if not append one, but then ran into: #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.)

@yaacovCR
Copy link
Collaborator

yaacovCR commented Apr 1, 2020

This stale issue appears to be fixed. Please reopen if necessary.

@yaacovCR yaacovCR closed this as completed Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository
Projects
None yet
Development

No branches or pull requests

3 participants