-
Notifications
You must be signed in to change notification settings - Fork 283
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
Include request variables in demand control scoring #5995
Conversation
This comment has been minimized.
This comment has been minimized.
CI performance tests
|
apollo-router/src/json_ext.rs
Outdated
Value::Null => apollo_compiler::ast::Value::Null, | ||
Value::Bool(b) => apollo_compiler::ast::Value::Boolean(*b), | ||
Value::Number(n) => { | ||
if n.is_f64() { |
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.
Is there a better way to do this conversion? This inner n
is private so it's not so easy to cleanly convert it to the underlying numeric 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.
An alternative is:
Value::Number(n) if n.is_f64() => {
apollo_compiler::ast::Value::Float(n.as_f64().expect("is float").into())
}
Value::Number(n) => {
apollo_compiler::ast::Value::Int((n.as_i64().expect("is int") as i32).into())
}
.with_lock(|mut lock| lock.insert(strategy.clone())); | ||
req.context.extensions().with_lock(|mut lock| { | ||
lock.insert(strategy.clone()); | ||
lock.insert(req.supergraph_request.body().variables.clone()); |
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.
This is going to insert an entry of type Map<ByteString, Value>
into the context. This type is used both for graphql request variables and graphql response extensions. Should we create some wrapper type to make sure it's disambiguated in context?
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.
Hmm, I'm not sure about doing this. Gonna take a look and see if there is something better.
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.
Yeah, I agree that a wrapper type needs to be used. Maybe also include cost strategy in it so there is just one entry?
I spent a bit of time trying to figure out why we need variables for the response. This is because input fields can have a cost directive right?
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.
Yes, we need to include argument cost for a field when scoring responses, and we can't score arguments purely from the schema because we may over/under count optional fields.
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.
Needs a wrapper for variables in context.
…ated in context extensions
We're missing variable support in demand control scoring, so they're currently not counted. Additionally, they don't get passed through to the list size directive, which prevents users from using variables as slicing arguments. This change includes the request variables in context extensions so they can be accessed from the demand control plugin pipeline.
This includes a small refactor to wrap some of the common scoring arguments (schema, request document, etc) into a scoring context to reduce the number of arguments to each function.
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. ↩