-
Notifications
You must be signed in to change notification settings - Fork 130
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
fix: include validation rule names in cache key #1598
Conversation
🦋 Changeset detectedLatest commit: 2932675 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🚀 Website PreviewThe latest changes to the website are available as preview in: https://81586f0e.envelop.pages.dev |
❌ Benchmark FailedPerformance regression detected: it seems like your Pull Request adds some extra latency to the GraphQL requests, or to envelop runtime.
|
…y added validation rules
// This would cause an issue if we are constructing the cache key here already. | ||
setValidationFn((...args) => { | ||
let ruleKey = ''; | ||
if (Array.isArray(args[2])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we always have second arg
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if we don't have access - we cannot create a cache key. 😅
I assume because of the useEngine
call, these rules always exist:
engine.specifiedRules?.map(addValidationRule); |
const key: string = ruleKey + (context[rawDocumentSymbol] ?? print(params.documentAST)); | ||
const cachedResult = resultCache.get(key); | ||
|
||
if (cachedResult !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (cachedResult !== undefined) { | |
if (!!cachedResult) { |
// Note: We could also order them... but that might be too much | ||
for (const rule of args[2]) { | ||
ruleKey = ruleKey + rule.name; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also prefer to hash the validation names... but we currently have no way of doing cross-platform hashing in a sync and performant way. 😅 We could use something like emn178/js-sha1@master/src/sha1.js instead for now.
Thoughts?
Include the validation rule names within the operation cache key.
This prevents skipping conditional validation rules in other plugins.
Please make sure your validation rules always have a unique
name
property.Note: I would also prefer to hash the validation names... but we currently have no way of doing cross-platform hashing in a sync and performant way. 😅 We could use something like https://github.com/emn178/js-sha1/blob/master/src/sha1.js instead for now.
Note: In a follow-up PR we should also create a hash key per GraphQLSchema instead of resetting the whole cache in case of a schema change.