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

gatsby-source-graphql@2.1.33 giving a "context is not defined" error #21170

Closed
stevebreault opened this issue Feb 3, 2020 · 8 comments
Closed
Assignees
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@stevebreault
Copy link

Description

After having upgraded to version 2.1.33 of gatsby-source-graphql I'm getting an error when trying to query. Error does not occur in versions of the plugin using graphql-tools rather than graphql-tools-fork (ex.: previous version used was 2.1.15). The graphql source in this case is an AWS AppSync endpoint. A test call to the endpoint with the parameters set in the gatsby-config.js file returns a successful response.

Steps to reproduce

gatsby-config.js

{
  resolve: `gatsby-source-graphql`,
    options: {
      typeName: 'Book',
      fieldName: 'catalogue',
      url: 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
      headers: {
        'x-api-key': 'xxxxxx'
      }
   }
}

Upon navigating to the graphql console at http://localhost:8000/___graphql and trying to run a query against the fieldName, the following error result occurs:

{
  "errors": [
    {
      "message": "context is not defined",
      "locations": [
        {
          "line": 7,
          "column": 5
        }
      ],
      "path": [
        "catalogue",
        "listBooks"
      ],
      "stack": [
        "ReferenceError: context is not defined",
        "    at buildDelegationTransforms (/Users/steve/Source/catalogue/node_modules/graphql-tools-fork/dist/stitching/delegateToSchema.js:48:98)",
        "    at delegateRequest (/Users/steve/Source/catalogue/node_modules/graphql-tools-fork/dist/stitching/delegateToSchema.js:75:32)",
        "    at Object.delegateToSchema [as default] (/Users/steve/Source/catalogue/node_modules/graphql-tools-fork/dist/stitching/delegateToSchema.js:40:12)",
        "    at /Users/steve/Source/catalogue/node_modules/graphql-tools-fork/dist/stitching/resolvers.js:57:86",
        "    at resolveFieldValueOrError (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:467:18)",
        "    at resolveField (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:434:16)",
        "    at executeFields (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:275:18)",
        "    at collectAndExecuteSubfields (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:713:10)",
        "    at completeObjectValue (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:703:10)",
        "    at completeValue (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:591:12)",
        "    at completeValue (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:557:21)",
        "    at completeValueCatchingError (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:495:19)",
        "    at resolveField (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:435:10)",
        "    at executeFields (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:275:18)",
        "    at executeOperation (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:219:122)",
        "    at executeImpl (/Users/steve/Source/catalogue/node_modules/graphql/execution/execute.js:104:14)"
      ]
    }
  ],
  "data": {
    "graphQlSource": {
      "fieldName": "catalogue",
      "typeName": "Book"
    },
    "catalogue": {
      "listBooks": null
    }
  }
}

Expected result

The query should return data from the graphql source, which it does when an older version of the package is used.

Actual result

"context is not defined" error is returned

Environment

  System:
    OS: macOS 10.15.2
    CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
    Shell: 5.7.1 - /usr/local/bin/zsh
  Binaries:
    Node: 10.18.1 - /usr/local/opt/node@10/bin/node
    npm: 6.13.4 - /usr/local/opt/node@10/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 79.0.3945.130
    Safari: 13.0.4
  npmPackages:
    gatsby: ^2.19.12 => 2.19.12 
    gatsby-image: ^2.2.40 => 2.2.40 
    gatsby-plugin-manifest: ^2.2.41 => 2.2.41 
    gatsby-plugin-offline: ^3.0.34 => 3.0.34 
    gatsby-plugin-react-helmet: ^3.1.22 => 3.1.22 
    gatsby-plugin-sharp: ^2.4.5 => 2.4.5 
    gatsby-source-filesystem: ^2.1.48 => 2.1.48 
    gatsby-source-graphql: ^2.1.33 => 2.1.33 
    gatsby-transformer-sharp: ^2.3.14 => 2.3.14 
  npmGlobalPackages:
    gatsby-cli: 2.8.28
@ricokahler
Copy link
Contributor

ricokahler commented Feb 3, 2020

I also am experiencing this issue. I went on a downgrading spree and version 2.1.29 was the version that fixed it for me.

Edit: it seems like the package-lock tells a bit of the story.

image

Version 2.1.30 was the version where graphql-tools-fork went from 7 to 8

@stevebreault
Copy link
Author

I can confirm that the downgrade to 2.1.29 fixed the issue. Maybe @yaacovCR has an idea of what's happening here?

@sidharthachatterjee sidharthachatterjee added the type: bug An issue or pull request relating to a bug in Gatsby label Feb 3, 2020
@yaacovCR
Copy link
Contributor

yaacovCR commented Feb 3, 2020

@yaacovCR
Copy link
Contributor

yaacovCR commented Feb 3, 2020

Poor linting. Should be able to fix overnight (US Eastern). Anybody who can give me some guidance on the underlying lint failure, would be much appreciated.

@yaacovCR
Copy link
Contributor

yaacovCR commented Feb 4, 2020

Should be fixed by v8.5.1.

@vladar
Copy link
Contributor

vladar commented Feb 5, 2020

@stevebreault Can you confirm that upstream fixes in graphql-tools-fork fixed it for you? If it is the case then we can close this.

@stevebreault
Copy link
Author

stevebreault commented Feb 5, 2020

@vladar I added graphql-tools-fork@8.5.1 as a dependency after re-upgrading to gatsby-source-graphql@2.1.33 and can confirm that the fixes there resolve the issue.

Here's my output of npm list that confirms the package versions used:

▶ npm list --depth=0
gatsby-starter-default@0.1.0 /Users/steve/Source/catalogue
├── gatsby@2.19.12
├── gatsby-image@2.2.40
├── gatsby-plugin-manifest@2.2.41
├── gatsby-plugin-offline@3.0.34
├── gatsby-plugin-react-helmet@3.1.22
├── gatsby-plugin-sharp@2.4.5
├── gatsby-source-filesystem@2.1.48
├── gatsby-source-graphql@2.1.33
├── gatsby-transformer-sharp@2.3.14
├── graphql-tools-fork@8.5.1
├── prettier@1.19.1
├── prop-types@15.7.2
├── react@16.12.0
├── react-dom@16.12.0
└── react-helmet@5.2.1

@yaacovCR
Copy link
Contributor

Feel free to reopen if you hit this again, closing for now, latest versions of graphql-tools-fork use eslint rules which only enable mocha environment in test files so that this can be avoided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

5 participants