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.

Error loading schema from URL or GraphQL Endpoint

See original GitHub issue

Describe 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:open
  • Created a year ago
  • Reactions:16
  • Comments:14

github_iconTop GitHub Comments

20reactions
tylermenezescommented, Jul 1, 2022

That worked for me too!

@franzwilhelm if you’re using yarn, try adding this to your package.json:

  "resolutions": {
    "undici": "5.5.1"
  }
11reactions
adam-nielsencommented, Jul 1, 2022

I just found the problem. It’s in the undici package. You can fix it temporarily by running:

npm install undici@5.5.1
npm remove undici

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotansimha/graphql-code-generator - Failed to load schema
It seems like codegen is failing to load your schema because of a network interruption. Are you sure that the URL is http://localhost:8000/gql ......
Read more >
Failed to load schema from http://localhost:8000/graphql ...
Experiencing the same now. My localhost is serving the GraphiQL interface just fine, showing the correct schema and all, but the code-generator ...
Read more >
Full Stack Error Handling with GraphQL and Apollo
graphQLErrors : Any error that is thrown within your resolvers. Since we have multiple resolvers executing that are all potential sources of ...
Read more >
Loading GraphQL Schemas from Different Sources
This loader generates (a fully executable remote schema using @graphql-tools/wrap) from a URL endpoint. import { loadSchema } from '@graphql- ...
Read more >
GraphQL Content API - Contentful
The GraphQL Content API responses via GitHub contains errors that occur during the different phases of a request (authentication, validation, schema generation ...
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