Skip to content

feat: add validateFullSchema and assertValidFullSchema#4798

Open
vishwakt wants to merge 2 commits into
graphql:17.x.xfrom
vishwakt:add-validate-full-schema
Open

feat: add validateFullSchema and assertValidFullSchema#4798
vishwakt wants to merge 2 commits into
graphql:17.x.xfrom
vishwakt:add-validate-full-schema

Conversation

@vishwakt

@vishwakt vishwakt commented Jun 4, 2026

Copy link
Copy Markdown

Motivation

Closes #4415.

validateSchema() validates a source schema and rejects any name beginning with __, since those are reserved by GraphQL introspection. However, tools that work with a full schema (for example one reconstructed from an introspection result, as in GraphiQL or codegen) may legitimately encounter reserved names, including ones added by a newer version of GraphQL than the running version of graphql-js implements.

The reproducer from the issue fails today purely on the reserved-name rule, even though the SDL is otherwise valid:

const schema = buildSchema(`
  type Query { hello: String }

  enum __ErrorBehavior { NULL PROPAGATE HALT }

  directive @behavior(onError: __ErrorBehavior) on SCHEMA
`);

validateSchema(schema);
// GraphQLError: Name "__ErrorBehavior" must not begin with "__", which is reserved by GraphQL introspection.

See the Full Schemas RFC for the broader context on source vs. full schemas.

Changes

  • Add experimentalValidateFullSchema(schema) and experimentalAssertValidFullSchema(schema), mirroring validateSchema / assertValidSchema.
  • They run every existing type-system check except the reserved-name (__) restriction, so a full schema validates without spurious errors.
  • Internally, both modes share the existing validation pipeline via a single allowReservedNames flag threaded through SchemaValidationContext.
  • The two modes use independent validation caches (__validationErrors vs. __fullSchemaValidationErrors) so their results never collide regardless of call order.
  • The functions use the experimental name prefix (matching experimentalExecuteIncrementally) to signal the API may change while behavior and test coverage for full schemas converge.

Tests

Added coverage for: the issue's reproducer, reserved names on types/fields/args/enum values/input fields, that non-name errors are still reported when validating a full schema, independent caching, and the assert variant.

npm run check, npm run lint, and the full test suite pass locally.

validateSchema validates a source schema and rejects any name beginning
with "__", which is reserved by GraphQL introspection. Tools that work
with a full schema (for example one reconstructed from introspection)
may legitimately encounter reserved names, including ones added by a
newer version of GraphQL than this library implements.

Add validateFullSchema and assertValidFullSchema, which run the same
checks as validateSchema except that reserved names are permitted. The
two modes use separate validation caches so their results never collide.

Closes graphql#4415
@vercel

vercel Bot commented Jun 4, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 4, 2026

Copy link
Copy Markdown

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

  • ✅ login: vishwakt / name: Vishwak Thatikonda (44c9266)

@martinbonnin martinbonnin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM although not a graphql-js expert.

Might be worth marking this function as experimental until we collectivelly converge on a bigger test suite?

Per review feedback, rename validateFullSchema and assertValidFullSchema
to experimentalValidateFullSchema and experimentalAssertValidFullSchema,
matching the existing experimental* naming convention used for
experimentalExecuteIncrementally. This signals the API may change while
the behavior and test coverage for full schemas converge.
@vishwakt

vishwakt commented Jun 4, 2026

Copy link
Copy Markdown
Author

Good idea, thanks. I marked both functions as experimental by adopting the existing experimental name prefix convention (as used by experimentalExecuteIncrementally / experimentalExecuteRootSelectionSet), since that seems to be the established pattern in the repo for signalling an unstable API rather than a JSDoc tag. They're now experimentalValidateFullSchema and experimentalAssertValidFullSchema, and I added a note in the JSDoc too. Happy to revisit the names once the behavior and test coverage for full schemas converge.

@martinbonnin martinbonnin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for addressing the feedback.

Pinging @yaacovCR @benjie @jerelmiller for more expert eyes.

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.

Allow to validate a full schema

2 participants