dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.87k stars 1.34k forks source link

Any errors stop generation with multiple outputs #9701

Open lachtanek opened 1 year ago

lachtanek commented 1 year ago

Which packages are impacted by your issue?

@graphql-codegen/cli

Describe the bug

Note: I am filing this as a bug, because it seems to me like this was working differently in an old release, but I do not know the history of this tool and I am quite a new user, so I am sorry if this should be "Feature request" instead.

When there are multiple generates outputs, if any one of them fails, no output is generated from either of them, even though the CLI output suggests something was generated (see image below). This happens because if an error happens in any of the sub-tasks, an exception is thrown here, while file generation happens later based on results variable (see here). It looks like this behavior was introduced in this release (quite a while ago): https://github.com/dotansimha/graphql-code-generator/commit/f13d3554ed838047b62285281d0f87fd3ab20035


The last 3 lines would suggest that schemas/api.graphql, components/types.generated.ts and components/ succeeded in generating, but no files are changed:

image

Your Example Website or App

https://codesandbox.io/p/sandbox/magical-tree-nm4fs9?file=%2Fcodegen.ts%3A15%2C5

Steps to Reproduce the Bug or Issue

See linked Codesandbox example

Expected behavior

I'd either expect for the indicated generations to actually happen, or at least for the CLI output to be changed to reflect nothing was actually changed on disk. Optionally, there could be a config flag choosing which behavior to use.

Screenshots or Videos

No response

Platform

Codegen Config File

import { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  generates: {
    "types.ts": {
      plugins: ["typescript", "typescript-operations"],
      schema: "schema.graphql",
      documents: "document.graphql",
    },
    "types-failed.ts": {
      plugins: ["typescript", "typescript-operations"],
      schema: "schema-error.graphql",
      documents: "document.graphql",
    },
  },
};

export default config;

Additional context

Personally, I'd prefer for the tool to be changed to generate something even if there were errors, because it would greatly help with our use-case (I can describe this in more detail if anyone is interested, but it is unrelated to the issue at hand).

jacobmoshipco commented 6 months ago

I'm also having issues due to this bug (fetching types from multiple development microservices that aren't always all running). Has there been any progress or workarounds since this was posted?