dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.79k stars 1.32k forks source link

Could generate from local `.schema` or local `introspection.json` file. #8329

Open vsDizzy opened 2 years ago

vsDizzy commented 2 years ago

Describe the bug

If I split the generations into two steps:

  1. Download shema.
  2. Generate types from local .schema file.

Then the generation fails:

 ✖
      Failed to load schema from schema.graphql,introspection.json:
      Unable to find any GraphQL type definitions for the following pointers:
      - schema.graphql
      ,
      - introspection.json
      Error:
      Unable to find any GraphQL type definitions for the following pointers:
      - schema.graphql
      ,
      - introspection.json
      at prepareResult (/workspaces/!gql/node_modules/@graphql-tools/load/cjs/load-typedefs.js:75:15)
      at loadTypedefs (/workspaces/!gql/node_modules/@graphql-tools/load/cjs/load-typedefs.js:39:12)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

However it works when https schema is specified.

Your Example Website or App

https://github.com/vsDizzy/gql-codegen-bug

Steps to Reproduce the Bug or Issue

  1. npm i
  2. npm run get-schema
  3. npm start

Expected behavior

There should be no error.

Screenshots or Videos

image

Platform

Codegen Config File

schema:
  - schema.graphql
  - introspection.json
generates:
  types.ts:
    plugins:
      - typescript

Additional context

This is also not working for shema downloaded with apollo client:download-schema.

ardatan commented 2 years ago

I don't see any errors here; https://codesandbox.io/p/github/vsDizzy/gql-codegen-bug/csb-lzb4fl/draft/misty-cloud?file=%2Fget-schema.codegen.yml&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A16%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A16%7D%5D Could you reproduce it on CodeSandbox or StackBlitz using our template?

vsDizzy commented 2 years ago

It works online and under docker run -it node:16 sh But it fails under remote-containers or locally on Windows.

There is .devcontainer folder in the example repo above. You can use remote containers extension in VS code.