-
Notifications
You must be signed in to change notification settings - Fork 271
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 the query hashing algorithm #6205
base: dev
Are you sure you want to change the base?
Conversation
this makes sure there will be no possible collision by extension (example: hashing `ab` then `cd` VS hashing `a` then `bcd`)
Ok(visitor) | ||
} | ||
|
||
pub(crate) fn hash_schema(&mut self) -> Result<(), BoxError> { |
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.
As an idea for follow up PR: What if use struct destructuring (without ...
) for accessing fields on schema
?
In that way, we can ensure that all fields are considered for hashing, so if new fields are added to apollo-rs
, they will result in compiler errors.
That way, we protect against stuff that would be added to the GraphQL spec in the future, e.g., support for directives in a new location.
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.
it could be useful for the other structures we use elsewhere in the visitor. Here, the schema also holds a list of types, but the point of this algorithm would be to ignore irrelevant types
Co-authored-by: Ivan Goncharov <[email protected]>
We do not need to hash the same field's definition multiple times, but the query's field usage needs to always be done
|
||
"^ARGUMENT_DEF_LIST".hash(self); | ||
for argument in &field_def.arguments { | ||
self.hash_input_value_definition(argument)?; |
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'm not 100% sure, but it looks like it also should hash @fromContext
:
https://www.apollographql.com/docs/graphos/reference/federation/directives#fromcontext
I looked into apollo-federation,
and it seems that Rust QP doesn't support it, but it is implemented in JS QP.
I don't think this directive will affect entity cache, because you also hash the selection set of subgraph query (I'm just assuming here)
However, this directive should affect QP (at least for the JS planner), so it's breaking QP caching.
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.
@Geal I triple checked this PR and it looks great 👍
The only thing I found is @fromContext
, otherwise it is ready to be merged.
If @fromContext
is not an issue, then just ping me on Slack and I will approve this one ASAP.
@IvanGoncharov I added the initial support for the context directives. I will take another look tomorrow, but I think the approach is sound:
There are some assumptions in there that we might want to check, like what happens when a |
Converting to draft as result of internal discussion regarding the risks introduced by parent PR, see details in #5255 |
This splits part of the work from #5255 to make it easier to merge. This PR only covers the fixes for the query hashing algorithm, which is currently used in entity caching, without integrating the changes to the query planner cache key.
Checklist
Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.
Exceptions
Note any exceptions here
Notes
Footnotes
It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. ↩
Configuration is an important part of many changes. Where applicable please try to document configuration examples. ↩
Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions. ↩