-
Notifications
You must be signed in to change notification settings - Fork 270
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
Query variables validation #227
Conversation
Waiting on #233 before continuing |
ec094f5
to
d5f8d25
Compare
e6186ff
to
6a6602e
Compare
If the schema change we don't want the query to be executed on a wrong schema. Unless we include the Schema to the hashing (Hash) we should make this a parameter.
...so we have less work when we change the API of this thing.
I’ll see myself out 😂🤣 |
ok so I worried more about what is said in
than about what the code is actually doing, which does not change much. A big assumption in the way we execute query is that the schema will not change during the query: if we establish a query plan from a query and schema, when formatting at the end it should still be the same schema. This is the benefit that was given by carrying the schema along with the query, it guarantees that the same schema will be used for the entire life of the query, even if the calling code in apollo-router changes. Now looking more at the code, this is mainly affecting the query cache, that caches the query parsed with apollo-rs and does not require the schema, than the CachingQueryPlanner who needs both query and schema. So it's ok. Maybe I just worry too much 😅 |
This is the key point imo |
Perf test please |
We now have automatic perf tests! ^_^ https://github.com/apollographql/router/pull/227/checks?check_run_id=4517674898 |
@cecton From what I understand, they only get triggered and show up there if you explicitly request them using the phrasing above (or some variations, like Je voudrais un test de perf 😉 ). So they are semi-automated. |
To me the key point is more like: there is a way to use the API where you can instantiate the query with a one schema and do validation/formatting with another 😅 I don't need to look at the cache to know that it is wrong. Pretty sure it was done by me and completely unintentionally. |
Oh nice! There was one available before though: |
Oh my branch makes huge perf improvement 😂 that's probably not right lol |
Perf test please |
It looks like it compares to one of my failed attempts in the mutex PR 🤭 |
OH NOW WE HAVE SCORES!! Mine: 7287 Wait... this is still wrong XD this PR should be slower.... |
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.
Minor issues around validation logic, but otherwise looks good.
) -> Result<(), InvalidValue> { | ||
match (self, value) { | ||
(FieldType::String, Value::String(_)) => Ok(()), | ||
(FieldType::Int, Value::Number(number)) if number.is_i64() || number.is_u64() => Ok(()), |
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.
Integers need to be a signed 32 bit integer https://spec.graphql.org/June2018/#sec-Int
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.
oh god really
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.
Fixed in 91d51fb
} | ||
|
||
impl FieldType { | ||
pub(crate) fn validate_value( |
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.
Float, Integer and Bool can be represented as strings, so coercion supported need to be added. Can be a followup ticket though.
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.
what, where did you see that? oh that would explain what i saw with the ID type
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.
Fixed in 41e2279
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.
Let me know what you think about the question I have on FieldTypes. Apart from that, looks good!
// should always serialize as a String." | ||
// | ||
// In practice it seems Int works too | ||
(FieldType::Id, Value::String(_) | Value::Number(_)) => Ok(()), |
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.
Does this indicate a problem somewhere. In other words, if it should serialize as a String, why are we getting Numbers?
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.
No I think it's the type coercion mentioned by Bryn there: #227 (comment)
I think there is "variation" in the benchmarking system due to "noisy neighbours" in the cloud and other source of variance. |
Ah I restarted it and now I have 6912... which seems to low |
no need to worry too much for a 5% difference. Panic when it's larger than 20% 😄 |
Changes
Remove unneededOption
aroundRequest
's variables`: this has been moved to Remove unneeded option #257 (review this first to reduce the diff size here 🧠)ValidationInvalidTypeVariable
for variables of invalid typeIntroduce new modulespec
for our higher level representation of GraphQL's Schema and Query: this has been moved to Cleanup prelude and create spec module #258 (review this first to reduce the diff size here 🧠)Clean-up prelude and added a note: this has been moved to Cleanup prelude and create spec module #258 (review this first to reduce the diff size here 🧠)schema
parameter fromQuery
's constructor: if the schema changes we don't want the query to be executed on a wrongschema. So unless we include the Schema to the hashing (Hash) we should make this a parameter of the methods of
Query
.validate_variables
onQuery
that allows type validation of the request's variable (the whole point of the damn PR, see Variable types are not validated #62)Schema
andQuery
Schema
'sis_subtype()
private: we don't need to expose that to the user (at least not for now...)Fixes #62