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

Codegen with 2 outputs: 1 succeeds, 1 fails but both not written to file

Open eyalw opened this issue 5 years ago • 7 comments

Describe the bug I have two outputs, one schema-ast, the other typescript types. both run in the same config, the schema completes with a green checkmark, the typescript fails (as expected, because of an intentional code error). But the schema is not written to file although it says it did.

image As you can see, 2 outputs, one finishes with success, the other fails. but the successful output is not written to file either. It is important the schema outputs correctly even though the typescript output does not, because i use the schema for eslint/vscode-autocompletion to fix the error.

To Reproduce Just use 2 outputs have one fail the other succeed.

  1. My GraphQL schema:
# not relevant
  1. My GraphQL operations:
# not relevant
  1. My codegen.yml config file:
schema:
  # Stitch all other microservices schemas into one
  # We are being as specific as we can, not to watch hundreds of files, because then CPU goes 100%
  - '../gqlgen/**/*.graphql'
  # Define Apollo custom directives that eslint doesn't know about so we don't get errors
  - './apolloFederationSpec.graphql'
overwrite: true
generates:
  ./schema.generated.graphql:
    plugins:
      - 'schema-ast'
    config:
      includeDirectives: true
  ./src/@generated/graphqlTypes.ts:
    documents:
      - './src/**/*.{ts,tsx}'
      # Exclude the generated files, so we don't get duplications
      - '!./src/@generated/**'
    plugins:
      - typescript
      - typescript-operations
      # for useQuery hooks:
      - typescript-react-apollo
      # for client-side mocks in apollo
      - typescript-resolvers
    # See: graphql-code-generator.com/docs/plugins/typescript-react-apollo#configuration
    config:
      # scalar => TS type mapping
      scalars:
        DateTime: number
        JSON: string
      withHOC: false
      withHooks: true
      withComponent: false
      reactApolloVersion: 3

Expected behavior

Environment:

  • OS: Mac OS 10.15.4
  • NodeJS: 12.14.1 "@graphql-codegen/cli": "^1.13.3", "@graphql-codegen/introspection": "1.13.3", "@graphql-codegen/schema-ast": "^1.13.3", "@graphql-codegen/typescript": "1.13.3", "@graphql-codegen/typescript-operations": "1.13.3", "@graphql-codegen/typescript-react-apollo": "1.13.3", "@graphql-codegen/typescript-resolvers": "^1.13.3",

eyalw avatar Apr 20 '20 10:04 eyalw

@kamilkisiela I think this is because we run everything in listr, and then do a single fs after it's done, right? maybe the fs write should be part of the listr flow?

dotansimha avatar Apr 28 '20 12:04 dotansimha

I'm running into the same issue with a very comparable codegen file. The reason why I want the GraphQL json schema still written to the file system even when the other output fails is that I use vscode-graphql which uses the GraphQL json schema to show the errors from the other output file in vscode.

SpaceK33z avatar Apr 30 '20 11:04 SpaceK33z

Hello, I have the same problem. Is there any way to solve this problem?

alSergey avatar Feb 03 '22 13:02 alSergey

Hi @alSergey, could you provide a simple reproduction repo? And I help you!

dimaMachina avatar Feb 03 '22 19:02 dimaMachina

@B2o5T hi ,I created a repository for you, where I described all the problems that I find while using code generation

alSergey avatar Feb 05 '22 22:02 alSergey

@B2o5T hi, have you looked at the repository I sent you?

alSergey avatar Feb 16 '22 13:02 alSergey

@alSergey, I do reproduce the issue which is linked to the current design of codegen. I'm moving this issue to our v3 roadmap so we can take a closer look and consider it.

charlypoly avatar Jul 29 '22 12:07 charlypoly