Pass scalar overrides explicitly to keep lazy type loading lazy on graphql-php >= 15.31#2772
Draft
tmoitie wants to merge 1 commit into
Draft
Pass scalar overrides explicitly to keep lazy type loading lazy on graphql-php >= 15.31#2772tmoitie wants to merge 1 commit into
tmoitie wants to merge 1 commit into
Conversation
On webonyx/graphql-php >= 15.31.0, the first lookup of a built-in scalar triggers scalar-override discovery, which resolves the lazy types callable and eagerly builds every type in the schema from the AST on every request. When SchemaConfig::setScalarOverrides is available, determine the overrides cheaply from the document AST and pass them explicitly so the scan is skipped and the types callable stays unresolved. Fixes nuwave#2771. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Resolves #2771
Changes
On
webonyx/graphql-php >= 15.31.0, the executor's first built-in scalar lookup triggers scalar-override discovery, which resolves the lazytypescallable (TypeRegistry::possibleTypes()) and eagerly builds every type in the schema from the AST — on every request under PHP-FPM. Details and measurements in #2771.webonyx/graphql-php#1927 adds
SchemaConfig::setScalarOverrides(?array): when overrides are passed explicitly (including an empty array), the scan oftypesis skipped entirely and lazy loading stays lazy.This PR makes
SchemaBuilder::build()determine the overrides cheaply from the document AST — a scalar override is a user-defined type named after a built-in scalar, and$documentAST->typesis keyed by name — and pass them explicitly. For the common case (no built-in scalar names redefined in the SDL) this is fiveisset()checks and an explicit empty array.The call is guarded with
method_exists($config, 'setScalarOverrides'), following the pattern of the query complexity guard from #2637, so thewebonyx/graphql-php: ^15constraint is unchanged. The guard (and the corresponding test skips) can be removed once the minimum graphql-php version includes the method.Tests added:
scalar String @scalar(class: "Email")) is passed as an overrideSchemaBuilderchange when running against graphql-php with Fix phpbench #1927 applied)All three tests are skipped on graphql-php versions without
setScalarOverrides; I verified them locally against the #1927 branch (15 tests, 41 assertions, 0 skipped) and confirmed the regression test fails without the fix.Draft status: marked draft until webonyx/graphql-php#1927 is merged and released.
Breaking changes
None. Behavior is unchanged on graphql-php versions without
setScalarOverrides; on versions with it, schemas behave identically but built-in scalar lookups no longer force full type resolution.🤖 Generated with Claude Code