Skip to content

Add types parameter to BuildSchema#1872

Open
spawnia wants to merge 6 commits into
masterfrom
681-build-schema-types-parameter
Open

Add types parameter to BuildSchema#1872
spawnia wants to merge 6 commits into
masterfrom
681-build-schema-types-parameter

Conversation

@spawnia

@spawnia spawnia commented Mar 14, 2026

Copy link
Copy Markdown
Collaborator

The existing workaround for custom scalar behavior in SDL-first schemas is typeConfigDecorator, which forces users to manually merge config arrays and cannot return a pre-built type instance at all. This creates unnecessary friction for a common need.

This PR brings the same types API that Schema/SchemaConfig already accepts to the SDL build path so both approaches are consistent.

Closes #681

spawnia and others added 2 commits March 14, 2026 21:30
…nstances from SDL

Enables users to supply custom type instances (e.g., scalars with
serialize/parseValue, enums with PHP values) when building a schema from SDL,
without having to use the more awkward typeConfigDecorator callback pattern.

Types whose names match SDL definitions replace the SDL-built instances.
Types whose names are absent from the SDL are registered as extra types.

Closes #681

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a types parameter to the SDL schema build path (BuildSchema) so callers can inject pre-built type instances (e.g., custom scalars/enums) in the same way Schema/SchemaConfig already support via types.

Changes:

  • Extend BuildSchema::build() / BuildSchema::buildAST() (and constructor) with an optional iterable $types = [] parameter.
  • Add override support in ASTDefinitionBuilder so provided named types can replace SDL-defined types by name (without mutating user instances).
  • Ensure “extra” provided types (not present in SDL) are still discoverable via Schema::getType() / getTypeMap(), and add coverage + docs/changelog updates.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Utils/BuildSchema.php Plumbs a new types parameter through SDL build, wires override/extra type behavior into SchemaConfig’s type loader and types list.
src/Utils/ASTDefinitionBuilder.php Adds a typeOverrides map and short-circuits type building to return provided instances for matching SDL names.
tests/Utils/BuildSchemaTest.php Adds a test validating SDL-defined type overrides (scalar/enum) and registration of extra types, including end-to-end scalar serialization.
docs/class-reference.md Documents the new types parameter for BuildSchema::build() and BuildSchema::buildAST().
CHANGELOG.md Notes the new capability in the Unreleased “Added” section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@spawnia
spawnia marked this pull request as ready for review March 14, 2026 21:08
@spawnia
spawnia requested a review from ruudk March 29, 2026 18:33
@spawnia spawnia changed the title Add types parameter to BuildSchema Add types parameter to BuildSchema Jul 20, 2026
@spawnia
spawnia requested a review from Copilot July 21, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/Utils/BuildSchema.php
Comment on lines +215 to +225
/** @var array<string, Type&NamedType> $typeOverrides */
$typeOverrides = [];
/** @var array<string, Type&NamedType> $extraTypesMap */
$extraTypesMap = [];
foreach ($this->types as $type) {
if (isset($typeDefinitionsMap[$type->name])) {
$typeOverrides[$type->name] = $type;
} else {
$extraTypesMap[$type->name] = $type;
}
}

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread src/Utils/BuildSchema.php
Comment on lines +219 to +225
foreach ($this->types as $type) {
if (isset($typeDefinitionsMap[$type->name])) {
$typeOverrides[$type->name] = $type;
} else {
$extraTypesMap[$type->name] = $type;
}
}
Comment on lines +273 to +275
if (isset($this->typeOverrides[$typeName])) {
return $this->cache[$typeName] = $this->typeOverrides[$typeName];
}
Comment on lines +73 to +76
$schema = BuildSchema::build(
file_get_contents('schema.graphql'),
types: [$dateType],
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to register ScalarTypes?

2 participants