Skip to content

Pass scalar overrides explicitly to keep lazy type loading lazy on graphql-php >= 15.31#2772

Draft
tmoitie wants to merge 1 commit into
nuwave:masterfrom
deskpro:explicit-scalar-overrides
Draft

Pass scalar overrides explicitly to keep lazy type loading lazy on graphql-php >= 15.31#2772
tmoitie wants to merge 1 commit into
nuwave:masterfrom
deskpro:explicit-scalar-overrides

Conversation

@tmoitie

@tmoitie tmoitie commented Jun 11, 2026

Copy link
Copy Markdown

Resolves #2771

  • Added or updated tests
  • Documented user facing changes
  • Updated CHANGELOG.md (skip for docs-only changes)

Changes

On webonyx/graphql-php >= 15.31.0, the executor's first built-in scalar lookup triggers scalar-override discovery, which resolves the lazy types callable (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 of types is 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->types is keyed by name — and pass them explicitly. For the common case (no built-in scalar names redefined in the SDL) this is five isset() 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 the webonyx/graphql-php: ^15 constraint is unchanged. The guard (and the corresponding test skips) can be removed once the minimum graphql-php version includes the method.

Tests added:

  • explicit empty overrides are set for a plain schema
  • a redefined built-in scalar (scalar String @scalar(class: "Email")) is passed as an override
  • regression: looking up a built-in scalar on the schema does not resolve unrelated types (this test fails without the SchemaBuilder change 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lazy schema becomes eager on every request with graphql-php >= 15.31: built-in scalar lookup resolves possibleTypes()

1 participant