Fix ast.Schema inferred root types on Mutation & Subscription and shema
definition
#144
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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>
isnil
. This causes downstreamgqlgen
models generator to refuse to generate this type because it uses a conditionschemaType == 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.