Failed to load schema - TypeError: crossUndiciFetch.fetch is not a function (cont)
See original GitHub issueThis 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:
- My
codegen.jsonconfig 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:
- Created 2 years ago
- Comments:8

Top Related StackOverflow Question
I ran into this and fixed it by replacing
localhostwith127.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
Ok, I resolved the issue by removing the lockfile and reinstalling dependencies. So I guess this is fixed?