-
Notifications
You must be signed in to change notification settings - Fork 275
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
do not perform nested fetches if the parent one returned null #1332
Conversation
@Ty3uK: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
✅ Deploy Preview for apollo-router-docs canceled.Built without sensitive environment variables
|
@@ -167,6 +167,22 @@ impl PlanNode { | |||
let mut value; | |||
let mut errors; | |||
|
|||
if !current_dir.is_empty() { | |||
// Check if parent data has field requested by Flatten | |||
match parent_value.pointer(¤t_dir.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.
it's not the right place to do that. The check should be performed at variables aggregation in https://github.com/apollographql/router/blob/main/apollo-router/src/query_planner/mod.rs#L492-L508
as you can see there's already a check to avoid a subquery if the list of variables is empty, this needs an additional check that the variables are not null
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.
Thanks for feedback!
Do I need to perform this check inside match
?
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.
Also, the problem is that with my example, variables are empty object ({}
) in both cases
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, fixed, hope I understood you 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.
sorry 😓 I was not very clear, I think it has to be done inside Variables::new
. If you want I can take a closer look at it and add some tests
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 have free time, so I can do it by myself 🙂
One question: do I need to add this check inside this else
branch?
And another question - do I need to extend existing tests or create a separate one?
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, check latest commit please 🙂
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.
thanks, looking into it
d900e38
to
c70b006
Compare
so, we need a bit more context to evaluate this. The code looks ok but I don't understand the use case enough to decide. Correct me if I'm wrong: this is used to "batch" mutations and do them in a specific order, right? Could you tell more about the kind of use case that warrants this design? Could you add a test to validate this code? There are examples to create a router and subgraph services in https://github.com/apollographql/router/blob/main/apollo-router/src/query_planner/mod.rs#L687 Thank you for taking the time to patch this :) |
@Geal, let's look into some production code from my work 🙂 Schematype Captcha_Captcha {
token: String!
image: String!
}
input Captcha_CaptchaCreateInput {
width: Int!
height: Int!
}
type Captcha_CaptchaCreateError implements Error @shareable {
message: String!
}
type Captcha_CaptchaCreateLimitError implements Error @shareable {
message: String!
}
input Captcha_CaptchaVerifyInput {
token: String!
text: String!
}
type Captcha_CaptchaVerificationInputError implements Error @shareable {
message: String!
}
type Captcha_CaptchaVerificationError implements Error @shareable {
message: String!
}
type Captcha_CaptchaVerificationLimitError implements Error @shareable {
message: String!
}
union Captcha_CaptchaCreateResult =
| Captcha_Captcha
| Captcha_CaptchaCreateError
| Captcha_CaptchaCreateLimitError
type Captcha_CaptchaVerifyResult {
error: Error
mutation: Mutation
}
type Captcha_CaptchaMutations {
create(input: Captcha_CaptchaCreateInput): Captcha_CaptchaCreateResult!
verify(input: Captcha_CaptchaVerifyInput!): Captcha_CaptchaVerifyResult!
}
extend type Mutation {
captcha: Captcha_CaptchaMutations
}
With this schema, I can verify captcha and do next mutation in one request. As I know, there is no limitation for doing such thing 🙂 And, as I say in first message, Question about testing: do I need to change existing |
if you can make the test schema smaller it would be nice, but otherwise that could work |
@Geal, I'm so sorry, I don't have enough experience in Rust to write tests 😕 |
just FYI, I have not forgotten about your PR, I had to handle other features this week, I'll get back to this one next week to write the test |
so we won't need to convert the path to string then reparse it
they are small enough to get inlined
flatten
when fetch
in sequence
returns null# Conflicts: # apollo-router/src/query_planner/mod.rs
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 looks great!
@Geal, @BrynCooke, @o0Ignition0o |
@Ty3uK There seems to be a merge conflict, i thinks you want to update the main branch and solve conflicts, do you know how to do this or would you like us to pair on that ? :) |
@o0Ignition0o, thanks, I'll do it 🙂 |
@o0Ignition0o, I merged |
Awesome! Let's run the Continuous Integration checks, it looks like you are getting super close to landing your first contribution to the router! 🏅 |
Tests are passing on my machine, let's land this! |
Related to https://github.com/apollographql/federation/blob/main/gateway-js/src/executeQueryPlan.ts#L179
If I have two subgraphs (simplified):
And run mutation like this:
Then,
mutationB
will be called even ifmutationA
returnsnull