gatsby: gatsby-source-graphql > 2.1.29: schema.getDirectives is not a function

Description

Encountered schema.getDirectives is not a function using gatsby-source-graphql@2.1.33.

The issue seems to be with dependency graphql-tool-fork@8.

Using gatsby-source-graphql@2.1.29 which depends on graphql-tool-fork@7 is how I worked around this issue.

Steps to reproduce

# clone repo
git clone https://github.com/lablancas/gatsby-reproduce-bug.git
cd gatsby-reproduce-bug

# edit .env.development to connect to your GraphQL server

# install dependencies and start gatsby
yarn
gatsby develop

Expected result

Gatsby development server starts without error and lineups node has been successfully created

Open http://localhost:8000/___graphql and run

query {
  lineups {
    __typename
  }
}

Response should be

{
  "data": {
    "lineups": {
      "__typename": "Lineups"
    }
  }
}

Actual result

Gatsby server log has an error TypeError: schema.getDirectives is not a function and lineups node was not created

GraphQL response from the query above is

{
  "errors": [
    {
      "message": "Cannot query field \"lineups\" on type \"Query\".",
      "locations": [
        {
          "line": 3,
          "column": 3
        }
      ],
      "stack": [
        "GraphQLError: Cannot query field \"lineups\" on type \"Query\".",
        "    at Object.Field (/Users/lucas/Development/lineups/gatsby-reproduce-bug/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:53:31)",
        "    at Object.enter (/Users/lucas/Development/lineups/gatsby-reproduce-bug/node_modules/graphql/language/visitor.js:324:29)",
        "    at Object.enter (/Users/lucas/Development/lineups/gatsby-reproduce-bug/node_modules/graphql/language/visitor.js:375:25)",
        "    at visit (/Users/lucas/Development/lineups/gatsby-reproduce-bug/node_modules/graphql/language/visitor.js:242:26)",
        "    at validate (/Users/lucas/Development/lineups/gatsby-reproduce-bug/node_modules/graphql/validation/validate.js:73:24)",
        "    at getGraphQLParams.then.then.optionsData (/Users/lucas/Development/lineups/gatsby-reproduce-bug/node_modules/express-graphql/index.js:121:32)",
        "    at process._tickCallback (internal/process/next_tick.js:68:7)"
      ]
    }
  ]
}

Environment

System: OS: macOS 10.15.3 CPU: x64 Intel® Core™ i5-7360U CPU @ 2.30GHz Shell: 5.7.1 - /bin/zsh Binaries: Node: 10.17.0 - ~/.nvm/versions/node/v10.17.0/bin/node Yarn: 1.22.0 - ~/.yvm/shim/yarn npm: 6.11.3 - ~/.nvm/versions/node/v10.17.0/bin/npm Browsers: Chrome: 79.0.3945.130 Safari: 13.0.5 npmPackages: gatsby: ^2.19.7 => 2.19.7 gatsby-image: ^2.2.39 => 2.2.39 gatsby-plugin-manifest: ^2.2.39 => 2.2.39 gatsby-plugin-offline: ^3.0.32 => 3.0.32 gatsby-plugin-react-helmet: ^3.1.21 => 3.1.21 gatsby-plugin-sharp: ^2.4.3 => 2.4.3 gatsby-source-filesystem: ^2.1.46 => 2.1.46 gatsby-source-graphql: ^2.1.33 => 2.1.33 gatsby-transformer-sharp: ^2.3.13 => 2.3.13

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 7
  • Comments: 31 (9 by maintainers)

Commits related to this issue

Most upvoted comments

hey everybody, I keep getting the error

Screen Shot 2020-04-10 at 1 45 50 AM

despite trying versions: “gatsby-source-graphql”: “2.1.28” “gatsby-source-graphql”: “2.1.29” “gatsby-source-graphql”: “2.1.32”

Please let me know if you need further context. thanks!

Should be fixed by graphql-tools-fork v8.5.5.

Apologies for regression. If you can verify this has been fixed with v8.5.5 after unpinning v8.5.4, should be able to close.

Running gatsby-source-graphql back to 2.1.29 recovers operation.

Thanks so much @narration-sd you just saved me hours of debugging.

package-lock.json

"gatsby-source-graphql": {
  "version": "2.3.2",
  "resolved": "https://registry.npmjs.org/gatsby-source-graphql/-/gatsby-source-graphql-2.3.2.tgz",
  "integrity": "sha512-RonjzodAAdMwh/idCokA6IqeH4eQGQPQD2vO9CDx3ocMiyvKRM5f7x617R1jxZM6lATjn1ndySmDvLvRqJz/Ig==",
  "requires": {
    "@babel/runtime": "^7.8.7",
    "apollo-link": "1.2.13",
    "apollo-link-http": "^1.5.16",
    "dataloader": "^2.0.0",
    "graphql": "^14.6.0",
    "graphql-tools-fork": "^8.9.6",
    "invariant": "^2.2.4",
    "node-fetch": "^1.7.3",
    "uuid": "^3.4.0"
  },
  "dependencies": {
    "node-fetch": {
      "version": "1.7.3",
      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
      "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
      "requires": {
        "encoding": "^0.1.11",
        "is-stream": "^1.0.1"
      }
    }
  }
},

Running ‘gatsby build’ with the above settings gives the same error as the image. If you run gatsby build after restoring to the following settings, no error will occur. What is the problem?

backup package-lock.json

"gatsby-source-graphql": {
  "version": "2.2.0",
  "resolved": "https://registry.npmjs.org/gatsby-source-graphql/-/gatsby-source-graphql-2.2.0.tgz",
  "integrity": "sha512-2Wk05rkOPUK4URVm3g0O8bcXKvRHAC0bNa3j7bguxv0DSa936Qr16kAm94t18EAe9TWDHH7x8Q4R1QJ2VDTEqQ==",
  "requires": {
    "@babel/runtime": "^7.8.7",
    "apollo-link": "1.2.13",
    "apollo-link-http": "^1.5.16",
    "graphql-tools-fork": "^8.9.6",
    "invariant": "^2.2.4",
    "node-fetch": "^1.7.3",
    "uuid": "^3.4.0"
  },
  "dependencies": {
    "node-fetch": {
      "version": "1.7.3",
      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
      "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
      "requires": {
        "encoding": "^0.1.11",
        "is-stream": "^1.0.1"
      }
    }
  }
},

And thanks a lot @yaacovCR for taking care of this!

Sorry you had to hit this. Must be very frustrating.

Must be something in graphql-tools-fork patch revision to 8.5.4.

That was about switching to eslint to avoid problems like #21170 .

Do you have a stack trace handy.

Hopeful I can dig into this soon.

The trick of it is that it isn’t the plugin that changed – the latest was 13 days ago.

It’s something it doesn’t get along with now, perhaps a library that summarily changed its interface.

You have to wonder where testing was on this one, don’t you…

@roryashfordbentley Most welcome, but it was really just close reading of @lablancas’ report, trying what he found and said 🙂

I can confirm this error using the following steps:

  1. gatsby new my-graphql-error
  2. yarn add gatsby-source-graphql
  3. add gatsby-source-graphql to gatsby-config.js:plugins
  4. yarn develop

Having the same error with v.2.1.33, v.2.1.32, v.2.1.31. Confirmed working with v.2.1.28.

Confirmed – thanks, @lablancas.

I have just the same error, on two separate long-term projects, data from two quite differing GraphQL servers.

Running gatsby-source-graphql back to 2.1.29 recovers operation.

$ npm run build

gatsby-starter-default@1.0.0 build C:\vagrant\release\lv-gatsby_html gatsby build

success open and validate gatsby-configs - 0.063s success load plugins - 1.972s success onPreInit - 0.005s success delete html and css files from previous builds - 0.011s success initialize cache - 0.022s success copy gatsby files - 0.232s success onPreBootstrap - 0.019s success createSchemaCustomization - 0.006s

ERROR #11321 PLUGIN

“gatsby-source-graphql” threw an error while running the sourceNodes lifecycle:

schema.getDirectives is not a function

99 | }; 100 |

101 | const schema = transformSchema({ | ^ 102 | schema: introspectionSchema, 103 | link 104 | }, [new StripNonQueryTransform(), new RenameTypes(name => ${typeName}_${name}), new NamespaceUnderFieldTransform({

File: node_modules\gatsby-source-graphql\gatsby-node.js:101:18

not finished source and transform nodes - 2.410s npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! gatsby-starter-default@1.0.0 build: gatsby build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the gatsby-starter-default@1.0.0 build script.