Error loading schema from URL or GraphQL Endpoint
See original GitHub issueDescribe the bug
When attempting to run the code generator with a schema variable that is a URL it fail with the following error:
Failed to load schema from http://my-graphql-api.com/graphql: Request with GET/HEAD method cannot have body.
Stack Trace:
TypeError: Request with GET/HEAD method cannot have body.
at new Request (graphql-code-generator-issue-sandbox-template\node_modules\undici\lib\fetch\request.js:437:13)
at Agent.fetch (graphql-code-generator-issue-sandbox-template\node_modules\undici\lib\fetch\index.js:114:21)
at fetch (graphql-code-generator-issue-sandbox-template\node_modules\undici\index.js:90:22)
at fetch (graphql-code-generator-issue-sandbox-template\node_modules\cross-undici-fetch\dist\create-node-ponyfill.js:130:16)
at fetch (graphql-code-generator-issue-sandbox-template\node_modules\cross-undici-fetch\dist\create-node-ponyfill.js:125:18)
at defaultAsyncFetch (graphql-code-generator-issue-sandbox-template\node_modules\@graphql-tools\url-loader\cjs\defaultAsyncFetch.js:6:43)
at graphql-code-generator-issue-sandbox-template\node_modules\@graphql-tools\url-loader\cjs\index.js:212:36
at new ValueOrPromise (graphql-code-generator-issue-sandbox-template\node_modules\value-or-promise\build\main\ValueOrPromise.js:14:21)
at executor (graphql-code-generator-issue-sandbox-template\node_modules\@graphql-tools\url-loader\cjs\index.js:186:20)
at graphql-code-generator-issue-sandbox-template\node_modules\@graphql-tools\url-loader\cjs\index.js:504:35
Your Example Website or App
https://github.com/edramos-97/graphql-code-generator-issue-sandbox-template
Steps to Reproduce the Bug or Issue
Execute npm install
followed by npm run generate
See error “Failed to load schema from http://my-graphql-api.com/graphql: Request with GET/HEAD method cannot have body.”
Expected behavior
As a User, I expected the code generator to support loading the schema from a URL/GraphQL endpoint but I’m seeing a fatal error that prevent the schema from being loaded
Screenshots or Videos
No response
Platform
- OS: Windows 10
- PowerShell: 7.2.5
- NodeJS: 16.13.2
- npm: 8.5.5
npm tree as of reporting:
graphql-codegen-issue-template@1.0.0 ├── @graphql-codegen/add@3.1.1 ├── @graphql-codegen/cli@2.6.4 ├── @graphql-codegen/typescript-operations@2.4.1 ├── @graphql-codegen/typescript@2.5.0 └── graphql@16.5.0
Codegen Config File
schema: http://my-graphql-api.com/graphql documents: ‘./src/**/*.tsx’ generates: ./graphql/generated.ts: plugins: - typescript - typescript-operations - typescript-react-query config: fetcher: fetch
# Copied from the guide https://www.graphql-code-generator.com/docs/guides/react
Additional context
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:16
- Comments:14
That worked for me too!
@franzwilhelm if you’re using
yarn
, try adding this to yourpackage.json
:I just found the problem. It’s in the
undici
package. You can fix it temporarily by running:This has the effect of reverting the dependent version from 5.6.0 (broken) to 5.5.1 (previous release, working), without leaving it in your package.json.
5.5.1 is the previous version (released 18 days ago), it only broke in the version following this (5.6.0) released 11 hours ago.
After doing this I was able to run the code generator again successfully.