graphql / graphql-js

A reference implementation of GraphQL for JavaScript
http://graphql.org/graphql-js/
MIT License
19.97k stars 2k forks source link

Introduce "recommended" validation rules #4118

Closed benjie closed 2 weeks ago

benjie commented 2 weeks ago

The GraphQL specification mandates certain validation rules that all compliant GraphQL services must implement. Beyond these, services are free to add their own validation rules. The TSC has been discussing the idea of "recommended" validation rules for some time, rules that are not mandatory for compliance but are recommended to enhance the resilience of GraphQL schemas.

@enisdenjo has developed a new validation rule to limit introspection query depth; the TSC saw this as an excellent opportunity to introduce the new "recommended" validation rules system.

This PR introduces a new recommendedRules export to contain these recommended rules, starting with Denis' rule. To ensure seamless integration we are merging these recommendedRules into the existing specifiedRules export, which acts as the default list of validation rules (we may adjust this approach in a future major release, possibly by exposing a defaultRules export, but for now we aim to ease adoption).

Services can opt-out of the recommended rules by creating their own rules list without them:

const rules = specifiedRules.filter(rule => !recommendedRules.includes(rule));

We anticipate adding to these recommended rules over time and iterating them based on community feedback. Ultimately they may become recommended as part of the official specification, or be removed from the defaults.

netlify[bot] commented 2 weeks ago

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
Latest commit 73e216650a6938fe02df0f2680d61527705327c2
Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/667565064feae80008d4d3d7
Deploy Preview https://deploy-preview-4118--compassionate-pike-271cb3.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

github-actions[bot] commented 2 weeks ago

Hi @benjie, I'm @github-actions bot happy to help you with this PR πŸ‘‹

Supported commands Please post this commands in separate comments and only one per comment: * `@github-actions run-benchmark` - Run benchmark comparing base and merge commits for this PR * `@github-actions publish-pr-on-npm` - Build package from this PR and publish it on NPM