Make root query operation type optional - #920
Draft
spawnia wants to merge 1 commit into
Draft
Conversation
3 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the library to support GraphQL schemas that omit the root query operation type (enabling mutation-only / subscription-only schemas), aligning behavior with the referenced GraphQL spec discussion.
Changes:
- Relax schema validation to no longer require a query root type.
- Update tests to reflect mutation-only schemas and (attempted) introspection behavior without a query root.
- Minor internal refactors/visibility tweaks in type definitions and object type construction.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Type/ValidationTest.php | Updates validation expectations for schemas without a query root type. |
| tests/Type/IntrospectionTest.php | Adjusts introspection test setup/expected results for a schema without a query root. |
| tests/Type/DefinitionTest.php | Updates schema construction to cover mutation-only schemas and renames the test accordingly. |
| src/Type/SchemaValidationContext.php | Removes validation error requiring a query root type. |
| src/Type/Schema.php | Removes an outdated TODO about assuming a query root type always exists. |
| src/Type/Definition/TypeWithFields.php | Widens visibility of field storage/initialization for subclasses. |
| src/Type/Definition/ObjectType.php | Refactors name inference/validation and tweaks doc wording. |
| src/Executor/ReferenceExecutor.php | Removes special-casing for __schema/__type meta fields (currently breaking introspection). |
Comments suppressed due to low confidence (2)
src/Executor/ReferenceExecutor.php:615
getFieldDef()no longer special-cases the introspection meta fields__schemaand__type. Since these fields are not actually defined on the query root type, removing this logic breaks standard introspection queries (they will fail field lookup). If the query root type can be absent, the special-casing should remain but be guarded when$schema->getQueryType()is null.
if ($fieldName === $typeNameMetaFieldDef->name) {
return $typeNameMetaFieldDef;
}
return $parentType->findField($fieldName);
tests/Type/IntrospectionTest.php:45
- The expected introspection result now asserts
queryType => null, butIntrospection::_schema()currently definesqueryTypeas a NonNull field (new NonNull(self::_type())) and resolves it from$schema->getQueryType(). With a schema that has no query type, execution should error due to returning null for a non-null field. If the intent is to keep introspection executable here, this expectation should be reverted toQueryRoot(or removed) until the introspection schema is updated accordingly.
'queryType' => null,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 'fields' => ['a' => Type::string()], | ||
| ]), | ||
| ]); | ||
| $emptySchema = new Schema([]); |
Comment on lines
300
to
304
| /** | ||
| * @see it('defines a mutation schema') | ||
| */ | ||
| public function testDefinesAMutationSchema(): void | ||
| public function testDefinesAMutationOnlySchema(): void | ||
| { |
Comment on lines
316
to
319
| $this->assertMatchesValidationMessage( | ||
| $schema->validate(), | ||
| [['message' => 'Query root type must be provided.']] | ||
| [] | ||
| ); |
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.
graphql/graphql-spec#631