graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

Failed to load schema [bug]

Open nirmaanlabs opened this issue 2 years ago • 5 comments

Describe the bug

I am unable to create typescript types from graphql schema. Discussed here discuss

Also, I found out that, it works fine on stackbliztt if i run below command npm run codegen

Your Example Website or App

https://github.com/nirmaanlabs/bug

Steps to Reproduce the Bug or Issue

npm i npm run codegen

Expected behavior

I should get a file with generated types

Screenshots or Videos

video codegen failed to read schema.zip

Platform

  • OS: [Windows]

  • NodeJS: [16.16.0]

  • graphql version: [16.5.0]

  • "@graphql-codegen/cli": "^2.9.1", "@graphql-codegen/typed-document-node": "^2.3.2", "@graphql-codegen/typescript": "^2.7.2", "@graphql-codegen/typescript-operations": "^2.5.2",

Codegen Config File

schema: schema.graphql generates: ./src/generated.ts: plugins: - typescript - typescript-operations - typed-document-node

Additional context

Coming here from the discussion

nirmaanlabs avatar Jul 23 '22 14:07 nirmaanlabs

We need to have a clear reproduction that shows the issue on that StackBlitz example. Otherwise we cannot help you, sorry.

ardatan avatar Jul 23 '22 15:07 ardatan

We need to have a clear reproduction that shows the issue on that StackBlitz example. Otherwise, we cannot help you, sorry.

Hey, @ardatan I have provided the video and GitHub link to my repo, is that not sufficient? So it does not work on my local machine and works on stackblitzz

Is there any way, I can see some more insightful logs of why my schema load command failed? As of now it just tells you failed to load schema, and it does not tell you why did it fail.

update: after console logging found this image

image

graphql-code-generator fails to read the schema.graphql file if it is in utf 16 le encoding. All my schema files are automatically generated by apollo rover cli. Read about this issue here.

Is there any flag in cli where user can inspect any error, in verbose? I had to console log in my node_modules folder. This verbose flag can potentially save some time while debugging

nirmaanlabs avatar Jul 24 '22 04:07 nirmaanlabs

I agree, it would be helpful if there was some more information about the error.

GraemeF avatar Jul 24 '22 18:07 GraemeF

Saw similar and had to do much the same, the verbose and debug flags don't emit the error. Is there a bug in the output code?

kav avatar Jul 29 '22 15:07 kav

if your GraphQL server is up and running, you can use the following to print the schema to a file:

npm install -g graphqurl
 
gq < graphql-endpoint > --introspect > schema.graphql
 
# if your graphql endpoint requires authentication:
gq < graphql-endpoint > -H "Authorization: Bearer <token>" --introspect > schema.graphql

Let me know if it helps you out

Parables avatar Aug 18 '22 08:08 Parables