feat: add validateFullSchema and assertValidFullSchema#4798
Conversation
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
|
@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. |
|
|
martinbonnin
left a comment
There was a problem hiding this comment.
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.
|
Good idea, thanks. I marked both functions as experimental by adopting the existing |
martinbonnin
left a comment
There was a problem hiding this comment.
LGTM. Thanks for addressing the feedback.
Pinging @yaacovCR @benjie @jerelmiller for more expert eyes.
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:
See the Full Schemas RFC for the broader context on source vs. full schemas.
Changes
experimentalValidateFullSchema(schema)andexperimentalAssertValidFullSchema(schema), mirroringvalidateSchema/assertValidSchema.__) restriction, so a full schema validates without spurious errors.allowReservedNamesflag threaded throughSchemaValidationContext.__validationErrorsvs.__fullSchemaValidationErrors) so their results never collide regardless of call order.experimentalname prefix (matchingexperimentalExecuteIncrementally) 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.