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

Add dangerouslyDisableValidation option to @apollo/server #7786

Merged
merged 5 commits into from
Nov 14, 2023

Conversation

ganemone
Copy link
Contributor

This adds a disableValidation option to @apollo/server which will skip the validation step for graphql operations.

Copy link

netlify bot commented Nov 13, 2023

👷 Deploy request for apollo-server-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c44698a

Copy link

codesandbox-ci bot commented Nov 13, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c44698a:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration

@@ -199,6 +199,21 @@ An array containing custom functions to use as additional [validation rules](htt
<tr>
<td>

###### `disableValidation`
Copy link
Member

Choose a reason for hiding this comment

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

I'd consider giving this a name like dangerouslyDisableValidation (like React — I'm not sure if we have examples of similar names in Apollo Server or other Apollo projects already), and give more context on potential side effects. My vague recollection is that graphql-js execution (and perhaps aspects of Apollo Server like the plugin system or usage reporting) does assume that some of the validations have been run and that this can have highly unexpected effects at runtime (certainly including security issues if you are assuming that values have expected types).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure - I'm fine with that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@ganemone ganemone changed the title Add disableValidation option to @apollo/server Add dangerouslyDisableValidation option to @apollo/server Nov 13, 2023
@trevor-scheer trevor-scheer enabled auto-merge (squash) November 14, 2023 00:17
@trevor-scheer trevor-scheer merged commit 869ec98 into apollographql:main Nov 14, 2023
15 checks passed
@github-actions github-actions bot mentioned this pull request Nov 14, 2023
@rupert648
Copy link

Could you document the use case of this somewhere? Would be useful to understand a bit more about when and why this option might be necessary

@ganemone
Copy link
Contributor Author

Could you document the use case of this somewhere? Would be useful to understand a bit more about when and why this option might be necessary

Validation can be pretty slow, especially for large operations. In our case we have a federation gateway server that validates the query anyway, so we end up doing validation twice. We hope to see some performance improvements by disabling validation for federated services.

@rupert648
Copy link

Ah that makes sense, thanks for the response!

@trevor-scheer
Copy link
Member

@rupert648 it's worth mentioning that validation is a cached operation, so you should only expect to perform validation for a given query one time during the life of a server instance (assuming you haven't exceeded the size of the cache and started evicting entries).

@rupert648
Copy link

Yep thank you, assuming @ganemone has subgraphs in a serverless environment where local caching of the validation isn't as effective. Thanks for taking the time to respond!

@trevor-scheer
Copy link
Member

I added an additional note in the docs: 2babd5b

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants