Validate schema root operation types#876
Open
phdoerfler wants to merge 1 commit into
Open
Conversation
phdoerfler
force-pushed
the
fix/issue-174-root-type-validation
branch
from
July 17, 2026 13:07
d9ac3ff to
d0584b5
Compare
phdoerfler
force-pushed
the
fix/issue-174-root-type-validation
branch
from
July 17, 2026 19:22
d0584b5 to
1236982
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #174.
Problem
A schema with no
queryroot type — either because it has notype Queryat all and no explicitschema { }block, or because an explicitschema { }block references a root type that doesn't exist — currently either:NoSuchElementExceptionthe first time.queryTypeis accessed (e.g. on the first query execution), orTypeReffor an undefinedmutation/subscriptionroot type, sinceschema { }root-type references were never existence-checked the way ordinary field/type references are.Per the GraphQL spec, "Root Operation Types":
This should be a schema validation error, not a runtime crash or silent bad state.
Fix
Adds
SchemaValidator.validateRootTypes, wired into the existingvalidateSchemachain right aftervalidateReferences. For each ofquery(mandatory),mutation(optional),subscription(optional):No 'query' root operation type in schemaUndefined type '<name>' specified as '<op>' root operation typeType '<name>' specified as '<op>' root operation type is not an object typeBecause both the
schema"""..."""compile-time macro and the runtimeSchema(string)constructor share the sameSchemaParser → validateSchemapipeline, this closes the gap at construction time for both entry points. No changes needed toqueryType/mutationType/subscriptionTypethemselves.Test plan
SchemaSuite.scala, one per error path (missing query, dangling reference, non-object root type).type Query { foo: Int }.