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

Improve errors output from codegen cli #5064

Closed
xenoterracide opened this issue Nov 10, 2020 · 8 comments
Closed

Improve errors output from codegen cli #5064

xenoterracide opened this issue Nov 10, 2020 · 8 comments

Comments

@xenoterracide
Copy link

xenoterracide commented Nov 10, 2020

this is what I'm running

    "codegen": "DEBUG=1 graphql-codegen --config server.codegen.yml && graphql-codegen --config client.codegen.yml",
> yarn graph codegen                                                                          # services -> feature/RS2-1286 $ !
➤ YN0000: [@bb/graph]: [11:31:09] Parse configuration [started]
➤ YN0000: [@bb/graph]: [11:31:09] Parse configuration [completed]
➤ YN0000: [@bb/graph]: [11:31:09] Generate outputs [started]
➤ YN0000: [@bb/graph]: [11:31:09] Generate src/generated/schema.ts [started]
➤ YN0000: [@bb/graph]: [11:31:09] Generate src/generated/schema.graphql [started]
➤ YN0000: [@bb/graph]: [11:31:09] Load GraphQL schemas [started]
➤ YN0000: [@bb/graph]: [11:31:09] Load GraphQL schemas [started]
➤ YN0000: [@bb/graph]: [11:31:09] Load GraphQL schemas [failed]
➤ YN0000: [@bb/graph]: [11:31:09] → Failed to load schema
➤ YN0000: [@bb/graph]: [11:31:09] Generate src/generated/schema.ts [failed]
➤ YN0000: [@bb/graph]: [11:31:09] → Failed to load schema
➤ YN0000: [@bb/graph]: [11:31:09] Load GraphQL schemas [failed]
➤ YN0000: [@bb/graph]: [11:31:09] → Failed to load schema
➤ YN0000: [@bb/graph]: [11:31:09] Generate src/generated/schema.graphql [failed]
➤ YN0000: [@bb/graph]: [11:31:09] → Failed to load schema
➤ YN0000: [@bb/graph]: [11:31:09] Generate outputs [failed]
➤ YN0000: [@bb/graph]: Something went wrong
➤ YN0000: The command failed for workspaces that are depended upon by other workspaces; can't satisfy the dependency graph
➤ YN0000: Failed with errors in 2s 819ms
>                                                                                        # services -> feature/RS2-1286 $ ! RC=1

but what is it failing on? what was it looking at? please improve the failure outputs to include what was being processed at the time. Here's the schema I've been working on

type PaymentTerminal {
  id: ID!
}
type CreateStripeConnectionTokenPayload {
  token: String!
}

extend type Mutation {
  """
  Creates a Stripe Connection Token to be used to activate a Stripe Terminal reader.
  """
  createStripeConnectionToken: CreateStripeConnectionTokenPayload!
}

type StripeClientSecret {
  clientSecret: String
}

"""
Describes an Authorization entity, which represents a payment authorized by a payment processor.
"""
type PaymentAuthorization {
  createdAt: DateTime!
  code: String!
  returns: StripeClientSecret
}

"""
Describes possible values for PaymentMethodType.
"""
enum PaymentMethodType {
  Card
}

enum PaymentProcessorType {
  Stripe
}

enum PaymentTransactionType {
  CardPresent
  CardToken
}
"""
id is the card token or any other lookup identifier to be determined by the PaymentMethodType and the TransactionType
"""
input CardPaymentMethodInput {
  type: PaymentMethodType!
  transactionType: TransactionType!
  id: ID
}

input AuthorizeCardPaymentInput {
  processor: PaymentProcessorType!
  amount: Int!
  currency: Currency!
  storefrontId: ID!
  terminalId: ID
  paymentMethod: CardPaymentMethodInput!
}

extend type Mutation {
  """
  Pre-authorizes a payment.
  """
  authorizeCardPayment(payment: AuthorizeCardPaymentInput!): PaymentAuthorization!
}

"""
Describes an Authorization entity, which represents a payment authorized by a payment processor.
"""
type Authorization {
  createdAt: DateTime!
  code: String!
  returns: StripeClientSecret
}

"""
Describes possible values for PaymentMethodType.
"""
enum PaymentMethodType {
  CardPresent
}

input PaymentMethodInput {
  type: PaymentMethodType!
}

input PaymentInput {
  amount: Int!
  currency: Currency!
  storefrontId: ID!
  terminalId: ID
  paymentMethod: PaymentMethodInput!
}

"""
Describes reasons for payment rejection by a payment processor.
"""
type PaymentRejectionReason {
  message: String
  code: String
}

extend type Mutation {
  """
  @deprecated use `authorizeCardPayment` instead
  """
  preAuthorize(payment: PaymentInput!): Authorization! @deprecated
}

DEBUG is a decent solution, but I need this #4946, also I think it could be just reduced to

    '        Failed to load schema from src/**/*.schema.graphql:\n' +
    '\n' +
    '        Type "TransactionType" not found in document.\n' 
@xenoterracide xenoterracide changed the title [Feature] improve logging [Feature] improve error output Nov 10, 2020
@dotansimha
Copy link
Owner

@xenoterracide the error should be visible. Are you running this as a script from a package manager? (seems like Yarn 2?) can you please share a reproduction of that issue in a sandbox?

thanks!

@xenoterracide
Copy link
Author

xenoterracide commented Nov 16, 2020

yes, yarn2, nodelinking, I'll see what I can do sometime this week

@dotansimha
Copy link
Owner

Got it, thanks. Can you please share a reproduction with the complete set of tooling you are using?

@TheAschr
Copy link

TheAschr commented Apr 2, 2021

@dotansimha I am also getting this error. Here is a reproduction:

https://github.com/TheAschr/graphql-codegen-errors-reproduction

@dotansimha dotansimha changed the title [Feature] improve error output Improve errors output from codegen cli Jun 20, 2021
@VincentAudibert
Copy link

As a local & temporary workaround, I added a print of the document errors, here is the kind of helpful output I got this way :

Error [GraphQLDocumentError]: Variable "$serviceId" of type "String!" used in position expecting type "ID!".
at [...]/src/graphql/service-operation-mutations.graphql:3:3

I put errors.forEach(console.log); in file node_modules/@graghql-tools/utils/index.js, line 960 as of version 8.0.2.

function checkValidationErrors(loadDocumentErrors) {
    if (loadDocumentErrors.length > 0) {
        const errors = [];
        for (const loadDocumentError of loadDocumentErrors) {
            ...
        }
        errors.forEach(console.log); // ADDED THIS UGLY THING
        throw new exports.AggregateError(errors, `GraphQL Document Validation failed with ${loadDocumentErrors.length} errors`);
    }
}

I'd be happy to fill a PR if given some insight on logging strategy of codegen !

@VincentAudibert
Copy link

VincentAudibert commented Sep 15, 2021

In fact, since version 8.2.0 (see commit), the error message are much nicely built:

throw new AggregateError(
  errors,
  `GraphQL Document Validation failed with ${errors.length} errors;
  ${errors.map((error, index) => `Error ${index}: ${error.stack}`).join('\n\n')}`
);

@dotansimha Issue should be closed as on graphql-tools side & resolved.

@jlmessenger
Copy link
Contributor

I found that listr was encapsulating errors in some cases.
This PR unpacks those errors, and includes those details in the CLI error output.

#6921

charlypoly added a commit that referenced this issue Feb 3, 2022
* Display detailed errors from CLI

* feat(codegen): better Listr error handling at `executeCodegen()` level

* fix(codegen): remove useless comment

* fix(codegen): use AggregateError to keep references of original errors

* Create famous-bikes-punch.md

Co-authored-by: Charly POLY <cpoly55@gmail.com>
Co-authored-by: Charly POLY <1252066+charlypoly@users.noreply.github.com>
@charlypoly
Copy link
Contributor

Hi all!

CLI errors output has been improved in @graphql-codegen/cli@2.5.0!

Thank you @jlmessenger for your contribution ⚡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants