Skip to content
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

feat: cache graphql query in query plan. #3106

Merged
merged 40 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8b40336
- render the selection set directly.
laststylebender14 Nov 13, 2024
11b7733
- store selection at graphql IO level.
laststylebender14 Nov 14, 2024
aa521de
- revert: selection from IO.
laststylebender14 Nov 14, 2024
a775b68
- store selection in request_template while generating the plan.
laststylebender14 Nov 14, 2024
e502f3e
- fix indentation
laststylebender14 Nov 14, 2024
2171fd7
- filter out args that has values.
laststylebender14 Nov 14, 2024
4ce9e4e
- skip IR fields.
laststylebender14 Nov 14, 2024
d66a424
impl JsonLike for Value.
laststylebender14 Nov 14, 2024
cea0573
- add support for directives.
laststylebender14 Nov 14, 2024
64e3dc2
- impl to_string_value for JsonLike
laststylebender14 Nov 14, 2024
fee9ea2
- we can apply GraphQL transformation only when selection set is enri…
laststylebender14 Nov 14, 2024
ccb918a
- add transformation to plan.
laststylebender14 Nov 14, 2024
44ddda1
- refactor: const_directive_to_sdl
laststylebender14 Nov 14, 2024
96df89e
- there's no point re-creating selection set during each request.
laststylebender14 Nov 14, 2024
186ab9f
- impl pathstring for Variables
laststylebender14 Nov 14, 2024
f8734dd
- compute the variables at runtime query with mustache
laststylebender14 Nov 14, 2024
8327582
- show query in info logger
laststylebender14 Nov 14, 2024
91db9ef
- handle modify directive scenario
laststylebender14 Nov 14, 2024
0b092e3
- lint changes
laststylebender14 Nov 14, 2024
3cd304c
- clean up of transform
laststylebender14 Nov 14, 2024
eae3162
- minor clean up
laststylebender14 Nov 14, 2024
c12de8b
- make pos inline
laststylebender14 Nov 14, 2024
8bcd4df
- clean up the selection API.
laststylebender14 Nov 14, 2024
57ee895
- rename func
laststylebender14 Nov 14, 2024
afd8ce4
- lint changes
laststylebender14 Nov 14, 2024
d70ddf7
- refactor: remove duplicate code.
laststylebender14 Nov 14, 2024
ab5ef48
- revert: change in eval context.
laststylebender14 Nov 14, 2024
600a769
- use to_string method instead
laststylebender14 Nov 14, 2024
a24351c
- test case fix: it's okay to send the directive to upstream.
laststylebender14 Nov 14, 2024
67ba766
Merge branch 'main' into fix/render-selection-set-directly
tusharmath Nov 18, 2024
d58e496
- add helper method modify_io, which allows user to modify io nodes.
laststylebender14 Nov 19, 2024
e6b7ee4
- resolve the variables in selection set of graphql query with modify_io
laststylebender14 Nov 19, 2024
f2ed3fb
- remove unused import
laststylebender14 Nov 19, 2024
e3c428a
- lint changes
laststylebender14 Nov 19, 2024
5c28ea1
Merge branch 'main' into fix/render-selection-set-directly
laststylebender14 Nov 19, 2024
a44d1b1
Merge branch 'main' into fix/render-selection-set-directly
laststylebender14 Nov 25, 2024
f46f4d1
- drop to_string_value method and use display instead.
laststylebender14 Nov 20, 2024
00bb2c3
- fix merge conflicts
laststylebender14 Nov 25, 2024
9953d08
Merge remote-tracking branch 'origin/main' into fix/render-selection-…
tusharmath Nov 28, 2024
b10fa32
Merge branch 'main' into fix/render-selection-set-directly
tusharmath Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/core/ir/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,20 @@ impl<Ctx: ResolverContextLike> GraphQLOperationContext for EvalContext<'_, Ctx>
.map(|directives| print_directives(directives.iter()))
}

fn selection_set(&self, related_fields: &RelatedFields) -> Option<String> {
fn selection_set(&self, _related_fields: &RelatedFields) -> Option<String> {
// ignore selection set and directly use selection set.
laststylebender14 marked this conversation as resolved.
Show resolved Hide resolved
let selection_field = self.graphql_ctx.field()?;
format_selection_set(selection_field.selection_set(), related_fields)
format_selection_set(selection_field.selection_set())
}
}

fn format_selection_set<'a>(
selection_set: impl Iterator<Item = &'a SelectionField>,
related_fields: &RelatedFields,
) -> Option<String> {
let set = selection_set
.filter_map(|field| {
.map(|field| {
// add to set only related fields that should be resolved with current resolver
related_fields.get(field.name()).map(|related_fields| {
format_selection_field(field, &related_fields.0, &related_fields.1)
})
format_selection_field(field, field.name())
})
.collect::<Vec<_>>();

Expand All @@ -143,13 +141,9 @@ fn format_selection_set<'a>(
Some(format!("{{ {} }}", set.join(" ")))
}

fn format_selection_field(
field: &SelectionField,
name: &str,
related_fields: &RelatedFields,
) -> String {
fn format_selection_field(field: &SelectionField, name: &str) -> String {
let arguments = format_selection_field_arguments(field);
let selection_set = format_selection_set(field.selection_set(), related_fields);
let selection_set = format_selection_set(field.selection_set());

let mut output = format!("{}{}", name, arguments);

Expand Down
23 changes: 23 additions & 0 deletions tests/core/snapshots/graphql-nested.md_0.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: tests/core/spec.rs
expression: response
---
{
"status": 200,
"headers": {
"content-type": "application/json"
},
"body": {
"data": {
"queryNodeA": {
"name": "nodeA",
"nodeB": {
"name": "nodeB"
},
"nodeC": {
"name": "nodeC"
}
}
}
}
}
30 changes: 30 additions & 0 deletions tests/core/snapshots/graphql-nested.md_client.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
source: tests/core/spec.rs
expression: formatted
---
type NodeA {
child: NodeA
name: String
nodeB: NodeB
nodeC: NodeC
}

type NodeB {
name: String
nodeA: NodeA
nodeC: NodeC
}

type NodeC {
name: String
nodeA: NodeA
nodeB: NodeB
}

type Query {
queryNodeA: NodeA
}

schema {
query: Query
}
30 changes: 30 additions & 0 deletions tests/core/snapshots/graphql-nested.md_merged.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
source: tests/core/spec.rs
expression: formatter
---
schema @server(hostname: "0.0.0.0", port: 8000) @upstream {
query: Query
}

type NodeA {
name: String
nodeA: NodeA @modify(name: "child")
nodeB: NodeB
nodeC: NodeC
}

type NodeB {
name: String
nodeA: NodeA
nodeC: NodeC
}

type NodeC {
name: String
nodeA: NodeA
nodeB: NodeB
}

type Query {
queryNodeA: NodeA @graphQL(url: "http://upstream/graphql", name: "nodeA")
}
71 changes: 71 additions & 0 deletions tests/execution/graphql-nested.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Complicated queries

```graphql @config
schema @server(port: 8000, hostname: "0.0.0.0") {
query: Query
}

type Query {
queryNodeA: NodeA @graphQL(url: "http://upstream/graphql", name: "nodeA")
}

type NodeA {
name: String
nodeB: NodeB
nodeC: NodeC
nodeA: NodeA @modify(name: "child")
}

type NodeB {
name: String
nodeA: NodeA
nodeC: NodeC
}

type NodeC {
name: String
nodeA: NodeA
nodeB: NodeB
}
```

```yml @mock
- request:
method: POST
url: http://upstream/graphql
textBody: { "query": "query { nodeA { name nodeB { name } nodeC { name } } }" }
expectedHits: 1
response:
status: 200
body:
data:
nodeA:
name: nodeA
nodeB:
name: nodeB
nodeC:
name: nodeC
nodeA:
name: nodeA
```

```yml @test
- method: POST
url: http://localhost:8080/graphql
body:
query: |
query queryNodeA {
queryNodeA {
name
nodeA {
name
}
nodeB {
name
}
nodeC {
name
}
}
}
```
Loading