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.

Introspection fails to load schema from server

See original GitHub issue

Describe the bug

I have installed the latest version of graphql-codegen and used the same config from another project to generate the types. It works on the old project, but fails in the new one.

It seems to me that cross-undici-fetch dependency is the cause of the problems, I tried to override the version but I can’t get it to work.

Old project uses:

  • “cross-undici-fetch”: “0.1.24”

New Project:

  • “cross-undici-fetch”: “0.4.5”

I can exclude the server as the source of problem, because introspection via phpstorm or from the old project works find.

To Reproduce

1.) Create a blank nextjs project 2.) Setup graphql codegen 3.) Create a codegen.yml that loads the schema from remote 4.) Execute codegen

Steps to reproduce the behavior:

  1. My GraphQL schema:

The schema works fine its the fetch that fails.

  1. My GraphQL operations:

Doesn’t load the schema from the server.

  1. My codegen.yml config file:
`
schema: 'http://127.0.0.1/service'
documents: ./src/**/*.gql
config:
  strictScalars: true
  scalars:
    Date: string
    DateTime: string
    DateTimeTz: string
    DateTimeUtc: string
    Mixed: any
    Upload: File
    JSON: any
hooks:
  afterAllFileWrite: prettier --write
generates:
  ./src/types/graphql.generated.ts:
    plugins:
      - typescript
    config:
      namingConvention: keep
  src/:
    preset: near-operation-file
    presetConfig:
      extension: .generated.ts
      folder: generated
      baseTypesPath: types/graphql.generated.ts
    plugins:
      - typescript-operations
      - typescript-urql

`

Expected behavior

It should load the schema from the server and generate the types as it did.

Environment:

Additional context

  • I tried to override versions to older packages but can’t get this to work
  • Switched between localhost and 127.0.0.1
Something went wrong Failed to load schema for "src/"
        Failed to load schema from http://127.0.0.1/service:

        terminated
        TypeError: terminated
    at Fetch.onAborted (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/fetch/index.js:1893:49)
    at Fetch.emit (node:events:390:28)
    at Fetch.terminate (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/fetch/index.js:77:10)
    at Object.onError (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/fetch/index.js:2027:34)
    at Request.onError (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/core/request.js:237:27)
    at errorRequest (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/client.js:1711:13)
    at Socket.onSocketClose (/home/eduard/Projects/ecommerce/frontend/node_modules/undici/lib/client.js:985:5)
    at Socket.emit (node:events:390:28)
    at TCP.<anonymous> (node:net:687:12)
    
        GraphQL Code Generator supports:
          - ES Modules and CommonJS exports (export as default or named export "schema")
          - 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.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

2reactions
denis-gorincommented, Jul 7, 2022

I found a workaround by just fetching and saving my schema via node and using this instead.

another way for laravel and local server (http://127.0.0.1:8000/graphql) is to force response header with Content Length

index.php


$response = $kernel->handle(
    $request = Request::capture()
);

$response->header('Content-Length', strlen($response->getContent()))->send();

PS

or create custom middleware and register it for lighthouse (the right way)

2reactions
thomasaullcommented, Jul 6, 2022

I found a workaround by just fetching and saving my schema via node and using this instead. It’s just a small script: https://www.apollographql.com/blog/backend/schema-design/three-ways-to-represent-your-graphql-schema/#786d

Note: There is no export for introspectionQuery anymore, instead use:

const { getIntrospectionQuery } = require('graphql')

// In fetch method:
{ query: getIntrospectionQuery() }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why You Should Disable GraphQL Introspection In Production
Use a schema registry to update, browse, and maintain your production Graph. Now that we've turned off introspection in production, how do we: ......
Read more >
MSSQL database introspection failing? Unable to resolve ...
I setup new connection to a MSSQL Azure AG database. I am able to connect fine, and when I sync all the schemas,...
Read more >
GraphQL - Failed to load schema from http://localhost:5555 ...
I have seen this github issue which indicates that some people with this problem found a resolution by deleting their yarn.lock file and...
Read more >
schema field - GraphQL Code Generator
The schema field should point to your GraphQLSchema - there are multiple ways you can specify it and load your GraphQLSchema .
Read more >
Remote GraphQL Schema Introspection Codegen - YouTube
Automatically introspect your stitched GraphQL schemas endpoints, and use the results to execute requests to remote schemas with the GraphQL ...
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