nuxt-graphql-client icon indicating copy to clipboard operation
nuxt-graphql-client copied to clipboard

"GraphQL Document Validation failed" prevents other build tools to fix the problem in dev mode

Open sheggi opened this issue 1 year ago • 3 comments

Environment

  • Operating System: Darwin
  • Node Version: v18.13.0
  • Nuxt Version: 3.1.0
  • Nitro Version: 2.0.0
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: modules, runtimeConfig, css, components, postcss, vite
  • Runtime Modules: [email protected]
  • Build Modules: -

Describe the bug

When starting nuxt dev the process stops/fails if any gql file has an invalid query. This may happen if the schema changes meanwhile.

Error Message:

 ERROR  GraphQL Document Validation failed with 1 errors;

This would prevent any rebuild or regeneration of the gql file later during the startup.

Expected behaviour

In dev is true just log the error and continue.

In dev is false stop process to prevent build success.

Reproduction

No response

Additional context

No response

Logs

In this example, an invalid property xxx prevents codegen working properly

---
ERROR  GraphQL Document Validation failed with 1 errors;                                                                                                              16:28:37
  Error 0: Cannot query field "xxx" on type "Set_Components_ImageWithText".
    at ./gql-dx-playground/web/queries/generated/uri.gql:23:3

  Error 0: Cannot query field "xxx" on type "Set_Components_ImageWithText".
  at queries/generated/uri.gql:23:3
  at executeCodegen (node_modules/@graphql-codegen/cli/dist/shared/graphql-codegen-cli-nuxt.111a00cc.mjs:953:20)
  at async generate (node_modules/@graphql-codegen/cli/dist/shared/graphql-codegen-cli-nuxt.111a00cc.mjs:1254:23)
  at async generate (node_modules/nuxt-graphql-client/dist/module.mjs:62:10)
  at async generateGqlTypes (node_modules/nuxt-graphql-client/dist/module.mjs:340:46)
  at async setup (node_modules/nuxt-graphql-client/dist/module.mjs:443:5)
  at async normalizedModule (node_modules/@nuxt/kit/dist/index.mjs:167:5)
  at async installModule (node_modules/@nuxt/kit/dist/index.mjs:435:3)
  at async initNuxt (node_modules/nuxt/dist/index.mjs:2034:7)
  at async load (node_modules/nuxi/dist/chunks/dev.mjs:6797:9)
  at async Object.invoke (node_modules/nuxi/dist/chunks/dev.mjs:6858:5)

  Error: GraphQL Document Validation failed with 1 errors;
  Error 0: Cannot query field "xxx" on type "Set_Components_ImageWithText".
  at queries/generated/uri.gql:23:3
  at codegen (node_modules/@graphql-codegen/core/esm/codegen.js:69:19)
  at async process2 (node_modules/@graphql-codegen/cli/dist/shared/graphql-codegen-cli-nuxt.111a00cc.mjs:902:44)
  at async Promise.all (index 0)
  at async node_modules/@graphql-codegen/cli/dist/shared/graphql-codegen-cli-nuxt.111a00cc.mjs:915:27
  at async node_modules/@graphql-codegen/cli/dist/shared/graphql-codegen-cli-nuxt.111a00cc.mjs:682:11
  at async Task.run (node_modules/listr2/dist/index.js:960:11)
  at async node_modules/p-map/index.js:57:22

sheggi avatar Mar 01 '23 15:03 sheggi

Same error in situation when a *.gql file contain more than one request.

If the file has been splitted into files which one request=one file, that error gone.

Parse gql file with more than one request effects the error

leaderit avatar Mar 08 '23 19:03 leaderit

@leaderit If your concern is, that multiple requests in a single .gql file should be supported, you'll be better served raising your issue in the GraphQL code generation project https://the-guild.dev/graphql/codegen. This nuxt module just uses the codegen features and has no influence in it.

In your case, I'd rather guess that there is an error in your .gql file with multiple requests because I didn't have had any problems with multiple requests in one single file.

sheggi avatar Mar 09 '23 10:03 sheggi

I'd also really appreciate this, as it would allow for hot-reloading to continue to work even if errors have been typed.

This could also just be a configuration flag failOnErroror similar.

arcs- avatar Feb 21 '24 13:02 arcs-