Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated error message #7546

Closed
Tobbe opened this issue Feb 16, 2022 · 4 comments
Closed

Duplicated error message #7546

Tobbe opened this issue Feb 16, 2022 · 4 comments
Assignees
Labels
core Related to codegen core/cli kind/enhancement New feature or request

Comments

@Tobbe
Copy link

Tobbe commented Feb 16, 2022

Describe the bug
In RedwoodJS we generate types programatically. When there are no files with gql stuff to parse we get a duplicated error message:

gen | Generating TypeScript definitions and GraphQL schemas...
gen |
gen |       Unable to find any GraphQL type definitions for the following pointers:
gen |
gen |           - ./web/src/**/!(*.d).{ts,tsx,js,jsx}
gen |
gen |
gen |       Unable to find any GraphQL type definitions for the following pointers:
gen |
gen |           - ./web/src/**/!(*.d).{ts,tsx,js,jsx}
gen |
gen |
gen | Error: Could not generate GraphQL type definitions (web)
gen |
gen | 14 files generated

It would look much better for our users if you only output the error message once.

To Reproduce

I tried to reproduce the error message in codesandbox, but I couldn't get it to look exactly the same, I get much more output there. But I hope it's close enough to be useful for you. This is what I get when I run node script.js

sandbox@sse-sandbox-2yriny:/sandbox$ node script.js
(node:1139) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

      Unable to find any GraphQL type definitions for the following pointers:

          - ./web/src/**/!(*.d).{ts,tsx,js,jsx}


      Unable to find any GraphQL type definitions for the following pointers:

          - ./web/src/**/!(*.d).{ts,tsx,js,jsx}

node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

AggregateError: Something went wrong

https://codesandbox.io/s/agitated-heyrovsky-2yriny?file=/script.js

  1. My GraphQL schema:

See codesandbox link

  1. My GraphQL operations:

See codesandbox link

  1. My codegen.yml config file:
const codegenConfig = {
  schema: "schema.graphql",
  config: {
    namingConvention: "keep",
    // to allow camelCased query names
    scalars: {
      // We need these, otherwise these scalars are mapped to any
      // @TODO is there a way we can use scalars defined in packages/graphql-server/src/rootSchema.ts
      BigInt: "number",
      DateTime: "string",
      Date: "string",
      JSON: "Record<string, unknown>",
      JSONObject: "Record<string, unknown>",
      Time: "string"
    },
    omitOperationSuffix: true // prevent type names being PetQueryQuery, RW generators already append Query/Mutation/etc
  },
  generates: {
    "/Users/tobbe/tmp/typegen/web/types/graphql.d.ts": {
      documents: "./web/src/**/!(*.d).{ts,tsx,js,jsx}",
      plugins: [{ typescript: { enumsAsTypes: true } }, "typescript-operations"]
    }
  },
  silent: false,
  errorsOnly: true
};

(Also see codesandbox link)

Expected behavior

I expect the error to only show once.

Environment:

  • OS: MacOS 12
  • @graphql-codegen/cli: 2.6.1
  • NodeJS: 14.19.0

Additional context

Issue and draft PR on our side:
redwoodjs/redwood#4393
redwoodjs/redwood#4491

@Tobbe
Copy link
Author

Tobbe commented Feb 21, 2022

If I switch this to false instead I only get one error as expected

But I guess the fix isn't as easy as that. You probably have a good reason for stoping early 🙂

@charlypoly
Copy link
Contributor

charlypoly commented Jul 20, 2022

Hi @Tobbe,

First, sorry for the enormous delay in answering your issue.
I reproduced the duplicated errors on both CLI and script scenarios.
A PR is pending for the CLI scenario: #8120

For your custom scripts, the duplicated errors come from your script implementation that does not provide a "catch" handler to cli.generate(/* ... */).then().
To avoid the errors to "bubble up" and be printed twice, ensure to pass a proper failure callback as follow:|

cli.generate(codegenConfig, true).then(
  (data) => {
    console.log("data", data);
  },
  () => Promise.resolve() // not providing this callback will trigger a nodejs "triggerUncaughtException"
);

saihaj pushed a commit that referenced this issue Jul 20, 2022
…#8120)

* fix(cli): prevent duplicated error messages on fail (without watcher)

Related to #7546

* Create smooth-beans-fetch.md
@charlypoly
Copy link
Contributor

@Tobbe the CLI duplicated error messages bug is fixed in @graphql-codegen/[email protected] 📦

@Tobbe
Copy link
Author

Tobbe commented Jul 20, 2022

Thanks @charlypoly! We've since moved to using import { codegen } from '@graphql-codegen/core'. But great to get this fixed nonetheless 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants