Skip to content

expose query plan in extensions in GraphQL Response#1470

Merged
bnjjj merged 16 commits intomainfrom
bnjjj/feat_1075
Aug 12, 2022
Merged

expose query plan in extensions in GraphQL Response#1470
bnjjj merged 16 commits intomainfrom
bnjjj/feat_1075

Conversation

@bnjjj
Copy link
Contributor

@bnjjj bnjjj commented Aug 5, 2022

close #1075

  • Discussed with @abernix, for now do not add a configuration key to configure the plugin. Just add an environment key and check for a specific header to enable the feature.

bnjjj added 2 commits August 4, 2022 16:36
…1075

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@bnjjj bnjjj self-assigned this Aug 5, 2022
bnjjj added 4 commits August 5, 2022 12:42
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@github-actions

This comment has been minimized.

bnjjj added 3 commits August 9, 2022 15:26
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Copy link
Member

@abernix abernix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! No implementation review from me, just some naming things that I've left as comments. 😉

Thanks for getting this together!

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@bnjjj
Copy link
Contributor Author

bnjjj commented Aug 10, 2022

thanks @abernix it was exactly what I was looking for when asking for review :)

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Copy link
Contributor

@o0Ignition0o o0Ignition0o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall,

Saw a couple of nits here and there, and I believe we can (and should!) iterate on the tests once #1487 lands. Maybe this should have been an integration test.

where
K: Into<String>,
{
self.entries.get(&key.into()).map(|v| v.value().clone())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like and_then Oo

Copy link
Contributor Author

@bnjjj bnjjj Aug 11, 2022

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 to understand what you mean. I think it's not an and_then but I might be wrong

req.context.insert(ENABLED_CONTEXT_KEY, true).unwrap();
}
(req.originating_request.body().query.clone(), is_enabled)
}, move |(query, is_enabled): (Option<String>, bool), f| async move {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty smart! 🎉

bnjjj added 4 commits August 11, 2022 17:47
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@bnjjj bnjjj requested review from Geal and abernix August 11, 2022 15:58
@bnjjj bnjjj requested a review from Geal August 12, 2022 09:12
@bnjjj bnjjj merged commit b04e0ff into main Aug 12, 2022
@bnjjj bnjjj deleted the bnjjj/feat_1075 branch August 12, 2022 10:00
Copy link
Member

@abernix abernix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that this actually didn't quite hit the requirements in the original issue so there's a slight adjustment that needs to be made. I could have probably made that more clear in the original issue but I think there's also a couple patterns that we've adopted (more generally) that make this subtle nuance harder to catch. I've left comments within, so let me know what y'all think!

{
first
.extensions
.insert("apolloQueryPlan", json!({ "object": { "kind": "QueryPlan", "node": plan, "text": query } }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops! This turns out to have been not quite what was needed from the original requirements which actually ask for object and text to be at the same level — not nested within each other.

Suggested change
.insert("apolloQueryPlan", json!({ "object": { "kind": "QueryPlan", "node": plan, "text": query } }));
.insert("apolloQueryPlan", json!({ "object": { "kind": "QueryPlan", "node": plan }, "text": query }));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an observation, I think this would have been easier to detect in review against the requirements if the JSON blob wasn't wrapped onto one line! (Something like this, but I wrote this on GitHub, so don't it's not necessarily perfect.)

Suggested change
.insert("apolloQueryPlan", json!({ "object": { "kind": "QueryPlan", "node": plan, "text": query } }));
.insert("apolloQueryPlan", json!({
"object": {
"kind": "QueryPlan",
"node": plan
},
"text": query
}));

@@ -0,0 +1 @@
{"data":{"topProducts":[{"upc":"1","name":"Table","reviews":[{"id":"1","product":{"name":"Table"},"author":{"id":"1","name":"Ada Lovelace"}},{"id":"4","product":{"name":"Table"},"author":{"id":"2","name":"Alan Turing"}}]},{"upc":"2","name":"Couch","reviews":[{"id":"2","product":{"name":"Couch"},"author":{"id":"1","name":"Ada Lovelace"}}]}]},"extensions":{"apolloQueryPlan":{"object":{"kind":"QueryPlan","node":{"kind":"Sequence","nodes":[{"kind":"Fetch","serviceName":"products","variableUsages":["first"],"operation":"query TopProducts__products__0($first:Int){topProducts(first:$first){__typename upc name}}","operationName":"TopProducts__products__0","operationKind":"query","id":null},{"kind":"Flatten","path":["topProducts","@"],"node":{"kind":"Fetch","serviceName":"reviews","requires":[{"kind":"InlineFragment","typeCondition":"Product","selections":[{"kind":"Field","name":"__typename"},{"kind":"Field","name":"upc"}]}],"variableUsages":[],"operation":"query TopProducts__reviews__1($representations:[_Any!]!){_entities(representations:$representations){...on Product{reviews{id product{__typename upc}author{__typename id}}}}}","operationName":"TopProducts__reviews__1","operationKind":"query","id":null}},{"kind":"Parallel","nodes":[{"kind":"Flatten","path":["topProducts","@","reviews","@","product"],"node":{"kind":"Fetch","serviceName":"products","requires":[{"kind":"InlineFragment","typeCondition":"Product","selections":[{"kind":"Field","name":"__typename"},{"kind":"Field","name":"upc"}]}],"variableUsages":[],"operation":"query TopProducts__products__2($representations:[_Any!]!){_entities(representations:$representations){...on Product{name}}}","operationName":"TopProducts__products__2","operationKind":"query","id":null}},{"kind":"Flatten","path":["topProducts","@","reviews","@","author"],"node":{"kind":"Fetch","serviceName":"accounts","requires":[{"kind":"InlineFragment","typeCondition":"User","selections":[{"kind":"Field","name":"__typename"},{"kind":"Field","name":"id"}]}],"variableUsages":[],"operation":"query TopProducts__accounts__3($representations:[_Any!]!){_entities(representations:$representations){...on User{name}}}","operationName":"TopProducts__accounts__3","operationKind":"query","id":null}}]}]},"text":"query TopProducts($first: Int) { topProducts(first: $first) { upc name reviews { id product { name } author { id name } } } }"}}}} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a meta level, these too would be so much simpler to review and get the requirements right and avoid the subtle bug missed during implementation and review if they were formatted JSON!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Runtime request query plan

4 participants