Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce "recommended" validation rules #4118

Merged
merged 37 commits into from
Jun 21, 2024
Merged

Introduce "recommended" validation rules #4118

merged 37 commits into from
Jun 21, 2024

Conversation

benjie
Copy link
Member

@benjie benjie commented Jun 21, 2024

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.

Copy link

netlify bot commented Jun 21, 2024

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit 73e2166
🔍 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.

Copy link

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

@benjie benjie merged commit 2744f58 into main Jun 21, 2024
35 checks passed
@benjie benjie deleted the maxintfields branch June 21, 2024 11:35
@benjie benjie added the PR: feature 🚀 requires increase of "minor" version number label Jun 21, 2024
SimonSapin added a commit to apollographql/router that referenced this pull request Sep 9, 2024
This protection against introspection queries generating huge responses
was added recently in graphql-js graphql/graphql-js#4118
and ported to rust apollographql/apollo-rs#904,
but is not yet present in the graphql-js version used by router-bridge.

This disables it for now from Rust introspection, in order to match
the current state of JS introspection.

Adding this rule (in both implementations) can be revisited separately.
In particular: the depth limit is hard-coded to 3. Is that the right number?
Should it be configurable? Is the rule checking the right set of fields?
SimonSapin added a commit to apollographql/router that referenced this pull request Sep 10, 2024
This protection against introspection queries generating huge responses
was added recently in graphql-js graphql/graphql-js#4118
and ported to rust apollographql/apollo-rs#904,
but is not yet present in the graphql-js version used by router-bridge.

This disables it for now from Rust introspection, in order to match
the current state of JS introspection.

Adding this rule (in both implementations) can be revisited separately.
In particular: the depth limit is hard-coded to 3. Is that the right number?
Should it be configurable? Is the rule checking the right set of fields?
TylerBloom pushed a commit to apollographql/router that referenced this pull request Sep 16, 2024
This protection against introspection queries generating huge responses
was added recently in graphql-js graphql/graphql-js#4118
and ported to rust apollographql/apollo-rs#904,
but is not yet present in the graphql-js version used by router-bridge.

This disables it for now from Rust introspection, in order to match
the current state of JS introspection.

Adding this rule (in both implementations) can be revisited separately.
In particular: the depth limit is hard-coded to 3. Is that the right number?
Should it be configurable? Is the rule checking the right set of fields?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: feature 🚀 requires increase of "minor" version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants