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

Add more validation checks on .yml config file #542

Merged

Conversation

Elgarni
Copy link
Contributor

@Elgarni Elgarni commented Feb 9, 2019

This PR adds two validation checks after parsing gqlgen.yml:

  • Check if the config file has two package names defined in the same directory
  • Check if the same filename has been used twice. For instance using gql/gen.go for both exec and model fields.

Although this may seem intuitive, but it can get tricky in a few cases.
For instance, the following gqlgen.yml config file:

schema:
- schema.graphql
exec:
  filename: generated/exec.go
  package: graphql
model:
  filename: generated/models.go
resolver:
  filename: generated/resolver.go
  type: Resolver

When generating the code, the following error message shows up:

generating resolver failed: resolver build failed: required package was not loaded: github.com/elgarni/project/generated.User
exit status 2

The message could be more descriptive. Moreover, the code was generated for exec.go and models.go, which will not compile anyways since they have different package names.

After this PR, the error message becomes:

invalid config format: filenames generated/exec.go and generated/models.go are in the same directory but have different package definitions
exit status 1

And no code was generated.

The objective of this PR is to stop execution early on, if there are errors in the config file, and not generating any code unless everything is defined correctly in gqlgen.yml

Copy link
Collaborator

@vektah vektah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs tests, see config_test.go for some examples

codegen/config.go Outdated Show resolved Hide resolved
codegen/config.go Outdated Show resolved Hide resolved
codegen/config.go Outdated Show resolved Hide resolved
@vektah vektah merged commit 015d02e into 99designs:master Feb 18, 2019
cgxxv pushed a commit to cgxxv/gqlgen that referenced this pull request Mar 25, 2022
…cks-on-yml-config-file

Add more validation checks on .yml config file
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

Successfully merging this pull request may close these issues.

2 participants