Skip to content

feat(validation)!: default to strict variable usage validation - #4994

Open
andimarek wants to merge 3 commits into
graphql:17.x.xfrom
andimarek:codex/strict-variable-usage
Open

andimarek wants to merge 3 commits into
graphql:17.x.xfrom
andimarek:codex/strict-variable-usage

Conversation

@andimarek

@andimarek andimarek commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Nullable variables with defaults currently pass validation in non-null positions but can still cause field errors when explicitly supplied as null. This implements the strict and legacy algorithms proposed in graphql/graphql-spec#1059: strict type compatibility is the default, and allowLegacyVariableUsage: true preserves the previous acceptance behavior.

Applications can audit existing operations while continuing to accept them:

validate(schema, document, undefined, {
  allowLegacyVariableUsage: true,
  onLegacyVariableUsage(warning, operation) {
    logger.warn({
      operationName: operation.name?.value,
      message: warning.message,
      locations: warning.locations,
    });
  },
});
  • Keep both algorithms in VariablesInAllowedPositionRule, sharing the existing traversal and preserving custom rule lists and OneOf validation.
  • Deliver strict incompatibilities through an optional synchronous callback, separately from validation errors. Warnings do not consume maxErrors.
  • Support the options through validate, graphql, and graphqlSync, with migration documentation and an executable API example.
  • Cover defaults, list positions, directives, fragments and fragment arguments with isolated rule tests and explicit error messages and locations. Keep warning callback and option integration tests in the existing validation suite, including operation attribution and warnings independent of errors.

This follows the per-call compatibility-option pattern used by allowEmptySelectionSets (#4852) and earlier allowLegacy… parser options.

Release consideration: the strict default is a breaking change. The spec PR is still at stage 1, so this is a draft for reviewing the proposed behavior and API; release timing and spec advancement need to be coordinated before merging into a release branch.

@vercel

vercel Bot commented Nov 5, 2026

Copy link
Copy Markdown

@andimarek is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@yaacovCR yaacovCR added PR: breaking change 💥 implementation requires increase of "major" version number spec RFC Implementation of a proposed change to the GraphQL specification labels Nov 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: breaking change 💥 implementation requires increase of "major" version number spec RFC Implementation of a proposed change to the GraphQL specification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants