Allow setting per-schema scalar overrides explicitly via SchemaConfig#1927
Open
tmoitie wants to merge 2 commits into
Open
Allow setting per-schema scalar overrides explicitly via SchemaConfig#1927tmoitie wants to merge 2 commits into
tmoitie wants to merge 2 commits into
Conversation
When scalar overrides are not set explicitly, they are discovered by scanning the types config. Since the executor resolves built-in scalars through Schema::getType() on essentially every operation, the first such lookup fully resolves a lazily provided types callable - silently making the documented lazy schema pattern (typeLoader + lazy types) eager for every schema, including those that define no overrides at all. Passing scalar overrides explicitly (including an empty array for none) through the new scalarOverrides option skips the scan entirely, keeping lazy type loading lazy. The default behaviour of discovering overrides by scanning types is unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
8229f5a to
34ef7b5
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 the silent loss of lazy type loading introduced with per-schema scalar overrides (#1869, v15.31.0), by allowing overrides to be set explicitly on
SchemaConfigso the discovery scan oftypescan be skipped. Related to #1874.The problem
The executor and validator resolve built-in scalars (
Boolean,String,Int,Float,ID) viaSchema::getType()on essentially every operation — including a bare{ __typename }.Since #1869 (and after #1884 moved scalar overrides exclusively to
types), the first such lookup goes:getType()callsloadType(), which returnsnullfor built-in scalar names when atypeLoaderis set (theTODOreferencing After Upgrading from v15.30.2 => v15.31.0 Error: " {"exception":"[object] (GraphQL\\Error\\Error(code: 0): Config element \"String\" is not declared in GraphQL schema at " #1874).getType()falls through togetScalarOverrides(), which callsmaterializeTypes()— fully resolving thetypesconfig to scan it forScalarTypeinstances shadowing built-in names.When
typesis a lazy callable, that scan resolves it entirely. This silently turns the documented lazy schema pattern —typeLoaderfor per-name loading plus a lazytypescallable for types not reachable from the root types — eager on the first executed query, for every schema, including the overwhelming majority that define no scalar overrides at all. The cost lives inside the user's callable, so the library cannot be lazy after invoking it; the only fix is to not invoke it on the hot path.In PHP-FPM the
Schemais rebuilt per request, so this is a per-request cost. Downstream impact observed in a Lighthouse (nuwave/lighthouse) app: every GraphQL operation became 1.5–3.4× slower wall-clock between 15.30.2 and 15.32.3 (~6× more PHP work, xdebug cachegrind 9.1 MB → 57 MB for an authed{ __typename }request). Lighthouse'sSchemaBuilder::build()is exactly this pattern:Repro
getType('Boolean')scalarOverridesset (e.g.[])The fix
Overrides cannot be discovered from a lazy
typescallable without resolving it — that is fundamental. So this PR makes explicitness possible instead: a newSchemaConfigoptionscalarOverrides.null(default): discover by scanningtypes, exactly as before — zero behaviour change for existing users.[]for "none"): use exactly these overrides, never scan. Explicit overrides take precedence ingetTypeMap()the same way discovered ones do.The setter validates entries are
ScalarTypeinstances named after built-in scalars.This gives lazy-schema users a one-line opt-out while keeping the scalar-overrides feature fully intact. If this lands, Lighthouse's
SchemaBuilder::build()could pass its known overrides (usually[]) explicitly and restore its pre-15.31 per-request performance — happy to file the companion PR there.Downstream context: we currently pin 15.30.2 to avoid the regression, which re-exposes GHSA-r7cg-qjjm-xhqq, GHSA-fc86-6rv6-2jpm and the 15.31.5 quadratic-validation fix — this change is what would let us (and others in the same spot) unpin.
🤖 Generated with Claude Code