-
Notifications
You must be signed in to change notification settings - Fork 9
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
[ShopifyVM] Add schema analyzer using blue to function-runner #343
Conversation
1e3cad1
to
09dce95
Compare
d486f94
to
7742cfb
Compare
f2969a4
to
a5d5782
Compare
yolo-query.graphql
Outdated
@@ -0,0 +1,7 @@ | |||
query { |
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.
Left in for tophatting, will not merge. Same with other .graphql
and json
files added.
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.
Looking better!
… - could be better way
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.
Looks good to me! I'll defer to others on the logic for analyzing the schema though. Also I'll be out of office for the next two weeks.
src/bluejay_schema_analyzer.rs
Outdated
let cache = | ||
bluejay_validator::executable::Cache::new(&executable_document, &schema_definition); | ||
|
||
let input_str = to_json_string(input).unwrap_or_else(|_| "<invalid JSON>".to_string()); |
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.
Instead of passing along <invalid JSON>
, should we just return an error 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.
I think we can remove this error here, looking at code again, we check if the input is valid here. (Although we create a string from that buffer).
Given that, I think we can just propagate this error up one level, and when we catch it in the main.rs
, we will just default to the 1.0
.
…ts verifying output
ad53e51
to
c8ea84c
Compare
Splitting this up into 2 PRs so we ca isolate the analyzer and then the usage in function-runner.
Appreciate all the the reviews on the PR, i will re-tag on the new ones. |
Closing as this was implemented in another PR. |
#gsd37875
Addresses:
Description
Current scaling implementation: https://github.com/Shopify/shopify/pull/518219/files#diff-bef9ccfcca30dfc391c6ad9d0a3e0739bf8a2ab27e659473894e4e62d43bad08
We currently scale our function run limits based on the directive
scaleLimits
with an argumentrate
oncartLines
. We scale by the length of the field. We multiply the directiverate
found on the fields definition, by the length of that fields (seem by either array length or string length) to determine how much to scale limits our default limits by.This PR adds an analyzer that will determine the maximum scale factor from all fields with the scale limits directive on it. We chose to use this implementation because we want to ability to add directives for scale limits of different fields in the future. Currently we only scale on cart lines.
Note: Currently have a few
.graphql
andjson
files used for testing, I will remove these before merging, but will keep in this PR for now incase anyone wants to tophat.Run Commands:
See Scaled Limits
We will traverse the query alongside the input, and determine the scale factor.
Example Query:
Notes on Visitor implementation:
Initialization: An instance of ScaleLimits is created, initializing the value_stack with the entire input JSON. The path_stack and rates are initialized as empty. The path stack, will keep track of the current field we are visiting. The value stack will keep track of what part of the json we are focused on. The rates hashmap will be used to track different rates (different fields with the directive).
Visiting cart Field: The visitor enters the cart field.
Visiting lines Field: The visitor moves to the lines field inside cart.
Final Output: After the traversal is complete, the
into_output
method of the Analyzer trait is called.After we call the analyzer, we then use that result when we display the output. I applied the same logic in showing red color for the usage when the run is over the limit, and regular text when it is within the limits. Limts are now calculated by multiplying the scaling rate determined by the analyzer, to the defaults.
Tophatting
Normal Cart:
With Scaled Limits:
These files no longest exist in this PR, but can copy them over from any the spin app.
When Query or Schema are not passed to function-runner