question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to load schema - TypeError: crossUndiciFetch.fetch is not a function (cont)

See original GitHub issue

This is a continuation of #7388 . I don’t understand why such a severe bug which breaks the the application and is reported by so many users in just a few hours is being closed. The ability to comment was also blocked which is something I don’t understand the reason for. I understand it is very hard to maintain such a popular tool but this bug is important to solve. At the very least keep the ticket open for us to have a place to discuss it and debug as a group.

I suggest using a label like requires-reproduction instead of closing and locking.

About reproducing: Is there a public schema url we can try to reproduce this on?

Describe the bug

When running the generate command I get this error:

Found 1 error

  ✖ ./src/user.tsx
    Failed to load schema from http://localhost:8080/v1/graphql:

        crossUndiciFetch.fetch is not a function
        TypeError: crossUndiciFetch.fetch is not a function
    at defaultAsyncFetch (/home/doron/dev/supplize/application/application/node_modul
es/@graphql-tools/url-loader/index.js:44:29)
    at /home/doron/dev/supplize/application/application/node_modules/@graphql-tools/u
rl-loader/index.js:474:36
    at new ValueOrPromise (/home/doron/dev/supplize/application/application/node_modu
les/value-or-promise/build/main/ValueOrPromise.js:14:21)
    at executor (/home/doron/dev/supplize/application/application/node_modules/@graph
ql-tools/url-loader/index.js:442:20)
    at /home/doron/dev/supplize/application/application/node_modules/@graphql-tools/u
rl-loader/index.js:646:20
    at /home/doron/dev/supplize/application/application/node_modules/@graphql-tools/w
rap/index.js:1697:52
    at new ValueOrPromise (/home/doron/dev/supplize/application/application/node_modu
les/value-or-promise/build/main/ValueOrPromise.js:14:21)
    at Object.introspectSchema (/home/doron/dev/supplize/application/application/node
_modules/@graphql-tools/wrap/index.js:1697:12)
    at UrlLoader.load (/home/doron/dev/supplize/application/application/node_modules/
@graphql-tools/url-loader/index.js:687:40)
    at async /home/doron/dev/supplize/application/application/node_modules/@graphql-t
ools/load/index.js:75:39

        GraphQL Code Generator supports:
          - ES Modules and CommonJS exports (export as default or named export "schem
a")
          - Introspection JSON File
          - URL of GraphQL endpoint
          - Multiple files with type definitions (glob expression)
          - String in config file

        Try to use one of above options and run codegen again.
    Error: Failed to load schema
        at loadSchema (/home/doron/dev/supplize/application/application/node_modules/
@graphql-codegen/cli/bin.js:503:15)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async /home/doron/dev/supplize/application/application/node_modules/@graph
ql-codegen/cli/bin.js:857:33
        at async /home/doron/dev/supplize/application/application/node_modules/@graph
ql-codegen/cli/bin.js:972:52
        at async Task.task (/home/doron/dev/supplize/application/application/node_mod
ules/@graphql-codegen/cli/bin.js:811:17)
    Error: Failed to load schema
        at loadSchema (/home/doron/dev/supplize/application/application/node_modules/
@graphql-codegen/cli/bin.js:503:15)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async /home/doron/dev/supplize/application/application/node_modules/@graph
ql-codegen/cli/bin.js:857:33
        at async /home/doron/dev/supplize/application/application/node_modules/@graph
ql-codegen/cli/bin.js:972:52
        at async Task.task (/home/doron/dev/supplize/application/application/node_mod
ules/@graphql-codegen/cli/bin.js:811:17)

Running this command works so I believe it’s a dependency issue:

curl -X POST -H "Content-Type: application/json" -H "x-hasura-role: user" -H "x-hasura-admin-secret: secret" --data '{"query": "query IntrospectionQuery { __schema { queryType { name } mutationType { name } subscriptionType { name } types { ...FullType } directives { name description locations args { ...InputValue } } } } fragment FullType on __Type { kind name description fields(includeDeprecated: true) { name description args { ...InputValue } type { ...TypeRef } isDeprecated deprecationReason } inputFields { ...InputValue } interfaces { ...TypeRef } enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason } possibleTypes { ...TypeRef } } fragment InputValue on __InputValue { name description type { ...TypeRef } defaultValue } fragment TypeRef on __Type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } }"}' "http://localhost:8080/v1/graphql"

To Reproduce Steps to reproduce the behavior:

  1. My codegen.json config file:
{
  "overwrite": true,
  "generates": {
    "./src/user.tsx": {
      "schema": [
        {
          "http://localhost:8080/v1/graphql": {
            "headers": {
              "x-hasura-role": "user",
              "x-hasura-admin-secret": "secret"
            }
          }
        }
      ],
      "documents": ["./src/user/**/*.graphql"],
      "plugins": ["typescript", "typescript-operations", "typescript-react-apollo"],
      "config": {
        "preResolveTypes": true,
        "skipTypename": false,
        "withHooks": true,
        "withHOC": false,
        "withComponent": false,
        "enumsAsTypes": true,
        "constEnums": true,
        "reactApolloVersion": 3
      }
    }
  }
}

Expected behavior

Environment:

OS: linux React

    "@graphql-codegen/cli": "^2.4.0",
    "@graphql-codegen/introspection": "^2.1.1",
    "@graphql-codegen/typescript": "^2.4.2",
    "@graphql-codegen/typescript-operations": "^2.2.2",
    "@graphql-codegen/typescript-react-apollo": "^3.2.4",

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
stereostevecommented, Mar 17, 2022

I ran into this and fixed it by replacing localhost with 127.0.0.1.

I think it has something to do with undici’s dns resolution, based on reading https://github.com/nodejs/undici/issues/1248#issuecomment-1053517133

Also relevant for: https://github.com/dotansimha/graphql-code-generator/issues/7388

1reaction
doron-cohencommented, Jan 25, 2022

Ok, I resolved the issue by removing the lockfile and reinstalling dependencies. So I guess this is fixed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL - Failed to load schema from http://localhost:5555 ...
When I try to generate the graphql code-gen, I get an error that says: ... Load GraphQL documents > Generate TypeError: fetch failed...
Read more >
Graphql is not a function error : r/gatsbyjs - Reddit
I am getting this error and I am trying to learn how to automate the page ... File: gatsby-node.js:3:25 TypeError: graphql is not...
Read more >
graphql-inspector - Bountysource
{graphql,tsx}" hasura/schema.graphql || true (node:383) UnhandledPromiseRejectionWarning: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /usr/local ...
Read more >
Failed to load schema from http://localhost:8000/graphql
Coding example for the question GraphQL Code Generator - Failed to load schema from http://localhost:8000/graphql - Request with GET/HEAD method cannot have ...
Read more >
Playground | FastStore
forEach((cb =\u003E cb({\n type: \"error\"\n })))));\n }\n addEventListener(eventName, cb) {\n \"load\" === eventName && this.l.push(cb);\n \"error\" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found