Skip to content

fix(graphql-language-service): do not require non-null variables with default values in JSON schema - #4764

Open
khangb2306668 wants to merge 1 commit into
graphql:mainfrom
khangb2306668:fix/variable-default-value-json-schema
Open

khangb2306668 wants to merge 1 commit into
graphql:mainfrom
khangb2306668:fix/variable-default-value-json-schema

Conversation

@khangb2306668

Copy link
Copy Markdown

Summary

Resolves #4762.

According to the GraphQL specification (§5.8.3 "Variable Values"), if an operation variable is omitted in the client's variables dictionary and has a default value, the execution algorithm automatically applies the default value. Previously, getVariablesJSONSchema marked all non-null variables as required in the generated JSON Schema because collectVariables only collected types and dropped variable default values, causing GraphiQL/Monaco variables editor to erroneously report Missing property "intro".

Changes

  • collectVariables.ts: Added VariableInfo, VariableToInfo, and collectVariableInfo() to retain variable AST information including defaultValue, while keeping collectVariables backward-compatible.
  • getVariablesJSONSchema.ts: Updated to check for default values and omit non-null variables with defaults from jsonSchema.required. Also safely populates JSON Schema definition.default using valueFromAST.
  • getOperationFacts.ts & packages/monaco-graphql/src/LanguageService.ts: Threaded variableInfo to getVariablesJSONSchema.
  • collectVariables.test.ts & getVariablesJSONSchema.test.ts: Added unit tests verifying default value tracking, spec compliance for non-null variables with defaults, and legacy compatibility.
  • Added patch changeset for graphql-language-service.

How to verify

Run the unit test suites:

npx vitest run src/utils/__tests__/collectVariables.test.ts src/utils/__tests__/getVariablesJSONSchema.test.ts

@changeset-bot

changeset-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8bc1c65

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
graphql-language-service Patch
codemirror-graphql Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: khangb2306668 / name: Ho Vi Khang (8bc1c65)

@khangb2306668

Copy link
Copy Markdown
Author

Hi team,

I've opened this PR to resolve #4762 regarding non-null variables with default values in JSON schema. All unit tests pass locally.

Could a maintainer please approve the CI workflow execution and take a look when you have a moment? Thanks!

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[graphiql] Variables editor flags a non-null variable with a default value as missing

1 participant