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

Failed to load schema, no error output

Open taschmidt opened this issue 3 years ago • 5 comments

Describe the bug

I had a schema from AppSync which includes an AWSJSON scalar type. If I don't define that type, graphql-codegen fails with absolutely no indication of why, just that it "Failed to load schema"

Your Example Website or App

https://codesandbox.io/s/inspiring-panna-ixxqrr?file=/schema.graphql

Steps to Reproduce the Bug or Issue

  1. Open the codesandbox link.
  2. Run yarn generate
  3. Notice the output: image

Expected behavior

Some sort of error indicating an unresolved type of AWSJSON. If I change that prop in the schema to be a String, everything works just fine.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: 16.16.0
  • graphql version: 16.5.0
  • @graphql-codegen/* version(s): [e.g. 2.6.2] "@graphql-codegen/cli": "^2.9.1", "@graphql-codegen/typed-document-node": "^2.3.2", "@graphql-codegen/typescript-operations": "^2.5.2",

Codegen Config File

overwrite: true schema:

  • src/generated/foo.graphql documents: null generates: src/generated/graphql.ts: plugins:
    • typescript
    • typescript-operations
    • typed-document-node config: preResolveTypes: true

Additional context

No response

taschmidt avatar Jul 25 '22 18:07 taschmidt

Add AWSJSON scalar to your graphql schema and codegen yaml file like so:

GraphQL Schema:

scalar AWSJSON

type Foo {
    bar: AWSJSON
}

Codegen.yaml

schema: schema.graphql
documents: null
generates:
  types.ts:
    plugins:
      - typescript
      - typescript-operations
    config:
      scalars:
        AWSJSON: string

Hoping this helps 😄

CalicoNino avatar Jul 26 '22 13:07 CalicoNino

Right, I know why it failed and how to fix it. But it's very undesirable to not get any error message as to why the schema failed to load (i.e. unknown type "AWSJSON"). This is just an MRE showing my issue, this was initially part of a much larger, complex schema and it took a decent amount of time to troubleshoot with the only output being "Failed to load schema".

taschmidt avatar Jul 26 '22 13:07 taschmidt

agreed this error message is not really helpful. We should be showing the validation error that is thrown instead of saying failed to load. The challenge is that load schema function throws and we just catch and show this error https://github.com/dotansimha/graphql-code-generator/blob/ab66ba10456a96cce0bd83ba172aae8f963bf2af/packages/graphql-codegen-cli/src/load.ts#L54-L72 rather we want to be able to differentiate Validation, Parsing and Loading which is work on @graphql-tools/ to have distinct errors for different or have more standard codes

saihaj avatar Jul 27 '22 19:07 saihaj

We have the same error here. But doesn't have any clue to fix 🥲. Hope anyone can fix that or have a solution for this 🙏.

harrytran998 avatar Aug 01 '22 14:08 harrytran998

since i removed my package-lock and node modules and reinstalled the deps of my project i get:

Left side of comma operator is unused and has no side effects.

5 (0, dotenv_1.config)({ path: (0, path_1.resolve)(__dirname, '../.env') });

my schema file is a ts file where i import dotenv

import { resolve } from 'path'

import { config } from 'dotenv'

config({ path: resolve(__dirname, '../.env') })

import { makeSchema } from '../src/server/graphql/schema'

export default makeSchema()

makeSchema just returns the new GraphQLSchema

import { GraphQLSchema } from 'graphql'

import { mutations as mutation } from './mutations'
import { queries as query } from './queries'
import { subscriptions as subscription } from './subscriptions'

export const makeSchema = () => {
  return new GraphQLSchema({ mutation, query, subscription })
}

It was working before. i try to find any strange dependency that got implicit updated. Seems like something in the transpiling does not work as before.

if i remove the dotenv part the error just moves to another import.

PS: to see the error i had to add console lot to the loader.js (thanks to @saihaj) PPS: using latest graphql-codegen deps:

"@graphql-codegen/cli": "^2.11.3",
    "@graphql-codegen/schema-ast": "^2.5.0",
    "@graphql-codegen/typescript": "^2.7.2",
    "@graphql-codegen/typescript-apollo-angular": "^3.5.2",
    "@graphql-codegen/typescript-operations": "^2.5.2",
    "@graphql-codegen/typescript-react-apollo": "^3.3.2",

And executing the file works without error when running directly with ts-node.

Idea: Maybe the tsconfig (TS_NODE_PROJECT env) gets ignored?

KillerCodeMonkey avatar Aug 04 '22 08:08 KillerCodeMonkey