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

Fix ast.Schema inferred root types on Mutation & Subscription and shema definition #144

Merged
merged 1 commit into from
Apr 7, 2021

Conversation

maoueh
Copy link
Contributor

@maoueh maoueh commented Feb 27, 2021

The GraphQL spec defines an inference rule where a valid Schema can omit the schema definition and some common root type's name will be inferred as the schema's root(s).

However, when a schema definition is explicitly provided, it should be respected and the inference rule should not apply.

Right now, the inference is performed as soon as the ast.Schema.<RootType> is nil. This causes downstream gqlgen models generator to refuse to generate this type because it uses a condition schemaType == cfg.Schema.Subscription (https://github.com/99designs/gqlgen/blob/master/plugin/modelgen/models.go#L94) to exclude the root type from being generated which ultimately breaks the code compilation since a a type is missing.

The fix applied here is to perform the inference rule only if no schema definition was provided.

Tests

I added a test, not sure if it's at the right location for the project or not. Let me know if I should put it somewhere else.

…hema` definition

The GraphQL spec defines an inference rule where a valid Schema can omit the `schema` definition and some common root type's name will be inferred as the schema's root(s).

However, when a `schema` definition is explicitely provided, it should be respected and the inference rule should not apply.

Right now, the inference is performed as soon as the `ast.Schema.<RootType>` is `nil`. This causes downstream gqlgen models generator to refuse to generate this type because it uses a condition `schemaType == cfg.Schema.Subscription` to exclude the root type from being generated which ultimately breaks the code compilation since a a type is missing.

The fix applied here is to perform the inference rule only if no `schema` definition was provided.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 92.284% when pulling 9b84c4a on maoueh:fix/default-root-operation-types into 7e475a7 on vektah:master.

@maoueh
Copy link
Contributor Author

maoueh commented Mar 17, 2021

@vektah Would like your review when you have some time. This prevent us generating one of our schema via gqlgen and managing two dependencies fork is not great.

@lwc lwc merged commit 824dec2 into vektah:master Apr 7, 2021
@maoueh
Copy link
Contributor Author

maoueh commented Apr 7, 2021

Thank you @lwc!

@maoueh maoueh deleted the fix/default-root-operation-types branch April 7, 2021 15:15
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.

3 participants