apollo-tooling icon indicating copy to clipboard operation
apollo-tooling copied to clipboard

Apollo codegen doesn't return non-zero exit code when errors have been found

Open tiagovtristao opened this issue 5 years ago • 3 comments

Intended outcome: Running apollo client:codegen ... should exit with a number different than 0, when there are errors.

Actual outcome: Running apollo client:codegen ... exits by returning 0, even when there are errors. Such as Error: ️️There are multiple definitions for the AccountSelectorInputQuery operation. All operations in a project must have unique names. If generating types, only the types for the first definition found will be generated.. This turns out to be problematic on a pipeline where the next command shouldn't be executed, if there are errors on the previous one.

How to reproduce the issue: Create two queries with the same name and run the apollo client:codegen ... command. Then run echo $? to get its return value. It is 0 but should be different, since there was an error.

Versions 2.21.3

tiagovtristao avatar Jun 03 '20 11:06 tiagovtristao

Problem still exists in 2.30.3.

royra avatar Sep 07 '20 09:09 royra

+1 - I'm working on a CI pipeline using codegen that would benefit greatly from a non-zero exit code. I was really hoping apollo would do this for me instead of building something to interface directly with getValidationErrors). Looking forward to action around this.

wwwidmer avatar Sep 25 '20 16:09 wwwidmer

A quick solution until this is merged: You can run the following bash script on a CI environment which will fail if the apollo codegen output contains fail anywhere

            # https://stackoverflow.com/a/47560475/5279269
            if ( (apollo codegen:generate ... 2>&1) | tee /dev/fd/2) | grep -i 'fail'; then
                echo "Found 'fail' in command output, exiting..."
                exit 1
            fi

definitely not ideal, but works well. An improved version could instead check if there are any lines existing in stderr. Right now this script just checks for the keywords fail in both stdout and stderr for simplicty.

Ry-DS avatar Nov 12 '21 11:11 Ry-DS