@@ -21,11 +21,11 @@ use graph::prelude::*;
21
21
use graph:: util:: lfu_cache:: LfuCache ;
22
22
23
23
use super :: QueryHash ;
24
+ use crate :: execution:: ast as a;
24
25
use crate :: introspection:: {
25
26
is_introspection_field, INTROSPECTION_DOCUMENT , INTROSPECTION_QUERY_TYPE ,
26
27
} ;
27
28
use crate :: prelude:: * ;
28
- use crate :: query:: ast as qast;
29
29
use crate :: schema:: ast as sast;
30
30
use crate :: values:: coercion;
31
31
@@ -136,8 +136,8 @@ impl Default for WeightedResult {
136
136
137
137
struct HashableQuery < ' a > {
138
138
query_schema_id : & ' a DeploymentHash ,
139
- query_fragments : & ' a HashMap < String , q :: FragmentDefinition > ,
140
- selection_set : & ' a q :: SelectionSet ,
139
+ query_fragments : & ' a HashMap < String , a :: FragmentDefinition > ,
140
+ selection_set : & ' a a :: SelectionSet ,
141
141
block_ptr : & ' a BlockPtr ,
142
142
}
143
143
@@ -165,14 +165,12 @@ impl StableHash for HashableQuery<'_> {
165
165
// Not stable! Uses to_string()
166
166
self . query_fragments
167
167
. iter ( )
168
- . map ( |( k, v) | ( k, v . to_string ( ) ) )
168
+ . map ( |( k, v) | ( k, format ! ( "{:?}" , v ) ) )
169
169
. collect :: < HashMap < _ , _ > > ( )
170
170
. stable_hash ( sequence_number. next_child ( ) , state) ;
171
171
172
172
// Not stable! Uses to_string
173
- self . selection_set
174
- . to_string ( )
175
- . stable_hash ( sequence_number. next_child ( ) , state) ;
173
+ format ! ( "{:?}" , self . selection_set) . stable_hash ( sequence_number. next_child ( ) , state) ;
176
174
177
175
self . block_ptr
178
176
. stable_hash ( sequence_number. next_child ( ) , state) ;
@@ -182,7 +180,7 @@ impl StableHash for HashableQuery<'_> {
182
180
// The key is: subgraph id + selection set + variables + fragment definitions
183
181
fn cache_key (
184
182
ctx : & ExecutionContext < impl Resolver > ,
185
- selection_set : & q :: SelectionSet ,
183
+ selection_set : & a :: SelectionSet ,
186
184
block_ptr : & BlockPtr ,
187
185
) -> QueryHash {
188
186
// It is very important that all data used for the query is included.
@@ -279,24 +277,24 @@ where
279
277
280
278
pub fn execute_root_selection_set_uncached (
281
279
ctx : & ExecutionContext < impl Resolver > ,
282
- selection_set : & q :: SelectionSet ,
280
+ selection_set : & a :: SelectionSet ,
283
281
root_type : & s:: ObjectType ,
284
282
) -> Result < Object , Vec < QueryExecutionError > > {
285
283
// Split the top-level fields into introspection fields and
286
284
// regular data fields
287
- let mut data_set = q :: SelectionSet {
285
+ let mut data_set = a :: SelectionSet {
288
286
span : selection_set. span ,
289
287
items : Vec :: new ( ) ,
290
288
} ;
291
- let mut intro_set = q :: SelectionSet {
289
+ let mut intro_set = a :: SelectionSet {
292
290
span : selection_set. span ,
293
291
items : Vec :: new ( ) ,
294
292
} ;
295
293
let mut meta_items = Vec :: new ( ) ;
296
294
297
295
for ( _, fields) in collect_fields ( ctx, root_type, iter:: once ( selection_set) ) {
298
296
let name = fields[ 0 ] . name . clone ( ) ;
299
- let selections = fields. into_iter ( ) . map ( |f| q :: Selection :: Field ( f. clone ( ) ) ) ;
297
+ let selections = fields. into_iter ( ) . map ( |f| a :: Selection :: Field ( f. clone ( ) ) ) ;
300
298
// See if this is an introspection or data field. We don't worry about
301
299
// non-existent fields; those will cause an error later when we execute
302
300
// the data_set SelectionSet
@@ -336,7 +334,7 @@ pub fn execute_root_selection_set_uncached(
336
334
/// Executes the root selection set of a query.
337
335
pub async fn execute_root_selection_set < R : Resolver > (
338
336
ctx : Arc < ExecutionContext < R > > ,
339
- selection_set : Arc < q :: SelectionSet > ,
337
+ selection_set : Arc < a :: SelectionSet > ,
340
338
root_type : Arc < s:: ObjectType > ,
341
339
block_ptr : Option < BlockPtr > ,
342
340
) -> Arc < QueryResult > {
@@ -480,7 +478,7 @@ pub async fn execute_root_selection_set<R: Resolver>(
480
478
/// Allows passing in a parent value during recursive processing of objects and their fields.
481
479
fn execute_selection_set < ' a > (
482
480
ctx : & ' a ExecutionContext < impl Resolver > ,
483
- selection_sets : impl Iterator < Item = & ' a q :: SelectionSet > ,
481
+ selection_sets : impl Iterator < Item = & ' a a :: SelectionSet > ,
484
482
object_type : & s:: ObjectType ,
485
483
prefetched_value : Option < r:: Value > ,
486
484
) -> Result < r:: Value , Vec < QueryExecutionError > > {
@@ -494,7 +492,7 @@ fn execute_selection_set<'a>(
494
492
495
493
fn execute_selection_set_to_map < ' a > (
496
494
ctx : & ' a ExecutionContext < impl Resolver > ,
497
- selection_sets : impl Iterator < Item = & ' a q :: SelectionSet > ,
495
+ selection_sets : impl Iterator < Item = & ' a a :: SelectionSet > ,
498
496
object_type : & s:: ObjectType ,
499
497
prefetched_value : Option < r:: Value > ,
500
498
) -> Result < Object , Vec < QueryExecutionError > > {
@@ -574,8 +572,8 @@ fn execute_selection_set_to_map<'a>(
574
572
pub fn collect_fields < ' a > (
575
573
ctx : & ' a ExecutionContext < impl Resolver > ,
576
574
object_type : & s:: ObjectType ,
577
- selection_sets : impl Iterator < Item = & ' a q :: SelectionSet > ,
578
- ) -> IndexMap < & ' a str , Vec < & ' a q :: Field > > {
575
+ selection_sets : impl Iterator < Item = & ' a a :: SelectionSet > ,
576
+ ) -> IndexMap < & ' a str , Vec < & ' a a :: Field > > {
579
577
let mut grouped_fields = IndexMap :: new ( ) ;
580
578
collect_fields_inner (
581
579
ctx,
@@ -590,26 +588,26 @@ pub fn collect_fields<'a>(
590
588
pub fn collect_fields_inner < ' a > (
591
589
ctx : & ' a ExecutionContext < impl Resolver > ,
592
590
object_type : & s:: ObjectType ,
593
- selection_sets : impl Iterator < Item = & ' a q :: SelectionSet > ,
591
+ selection_sets : impl Iterator < Item = & ' a a :: SelectionSet > ,
594
592
visited_fragments : & mut HashSet < & ' a str > ,
595
- output : & mut IndexMap < & ' a str , Vec < & ' a q :: Field > > ,
593
+ output : & mut IndexMap < & ' a str , Vec < & ' a a :: Field > > ,
596
594
) {
597
595
for selection_set in selection_sets {
598
596
// Only consider selections that are not skipped and should be included
599
597
let selections = selection_set
600
598
. items
601
599
. iter ( )
602
- . filter ( |selection| !qast :: skip_selection ( selection) )
603
- . filter ( |selection| qast :: include_selection ( selection) ) ;
600
+ . filter ( |selection| !selection. skip ( ) )
601
+ . filter ( |selection| selection. include ( ) ) ;
604
602
605
603
for selection in selections {
606
604
match selection {
607
- q :: Selection :: Field ( ref field) => {
608
- let response_key = qast :: get_response_key ( field) ;
605
+ a :: Selection :: Field ( ref field) => {
606
+ let response_key = field. response_key ( ) ;
609
607
output. entry ( response_key) . or_default ( ) . push ( field) ;
610
608
}
611
609
612
- q :: Selection :: FragmentSpread ( spread) => {
610
+ a :: Selection :: FragmentSpread ( spread) => {
613
611
// Only consider the fragment if it hasn't already been included,
614
612
// as would be the case if the same fragment spread ...Foo appeared
615
613
// twice in the same selection set.
@@ -632,7 +630,7 @@ pub fn collect_fields_inner<'a>(
632
630
}
633
631
}
634
632
635
- q :: Selection :: InlineFragment ( fragment) => {
633
+ a :: Selection :: InlineFragment ( fragment) => {
636
634
let applies = match & fragment. type_condition {
637
635
Some ( cond) => does_fragment_type_apply ( ctx, object_type, & cond) ,
638
636
None => true ,
@@ -657,10 +655,10 @@ pub fn collect_fields_inner<'a>(
657
655
fn does_fragment_type_apply (
658
656
ctx : & ExecutionContext < impl Resolver > ,
659
657
object_type : & s:: ObjectType ,
660
- fragment_type : & q :: TypeCondition ,
658
+ fragment_type : & a :: TypeCondition ,
661
659
) -> bool {
662
660
// This is safe to do, as TypeCondition only has a single `On` variant.
663
- let q :: TypeCondition :: On ( ref name) = fragment_type;
661
+ let a :: TypeCondition :: On ( ref name) = fragment_type;
664
662
665
663
// Resolve the type the fragment applies to based on its name
666
664
let named_type = ctx. query . schema . document ( ) . get_named_type ( name) ;
@@ -689,9 +687,9 @@ fn execute_field(
689
687
ctx : & ExecutionContext < impl Resolver > ,
690
688
object_type : & s:: ObjectType ,
691
689
field_value : Option < r:: Value > ,
692
- field : & q :: Field ,
690
+ field : & a :: Field ,
693
691
field_definition : & s:: Field ,
694
- fields : Vec < & q :: Field > ,
692
+ fields : Vec < & a :: Field > ,
695
693
) -> Result < r:: Value , Vec < QueryExecutionError > > {
696
694
coerce_argument_values ( & ctx. query , object_type, field)
697
695
. and_then ( |argument_values| {
@@ -713,7 +711,7 @@ fn resolve_field_value(
713
711
ctx : & ExecutionContext < impl Resolver > ,
714
712
object_type : & s:: ObjectType ,
715
713
field_value : Option < r:: Value > ,
716
- field : & q :: Field ,
714
+ field : & a :: Field ,
717
715
field_definition : & s:: Field ,
718
716
field_type : & s:: Type ,
719
717
argument_values : & HashMap < & str , r:: Value > ,
@@ -756,7 +754,7 @@ fn resolve_field_value_for_named_type(
756
754
ctx : & ExecutionContext < impl Resolver > ,
757
755
object_type : & s:: ObjectType ,
758
756
field_value : Option < r:: Value > ,
759
- field : & q :: Field ,
757
+ field : & a :: Field ,
760
758
field_definition : & s:: Field ,
761
759
type_name : & str ,
762
760
argument_values : & HashMap < & str , r:: Value > ,
@@ -809,7 +807,7 @@ fn resolve_field_value_for_list_type(
809
807
ctx : & ExecutionContext < impl Resolver > ,
810
808
object_type : & s:: ObjectType ,
811
809
field_value : Option < r:: Value > ,
812
- field : & q :: Field ,
810
+ field : & a :: Field ,
813
811
field_definition : & s:: Field ,
814
812
inner_type : & s:: Type ,
815
813
argument_values : & HashMap < & str , r:: Value > ,
@@ -890,9 +888,9 @@ fn resolve_field_value_for_list_type(
890
888
/// Ensures that a value matches the expected return type.
891
889
fn complete_value (
892
890
ctx : & ExecutionContext < impl Resolver > ,
893
- field : & q :: Field ,
891
+ field : & a :: Field ,
894
892
field_type : & s:: Type ,
895
- fields : & Vec < & q :: Field > ,
893
+ fields : & Vec < & a :: Field > ,
896
894
resolved_value : r:: Value ,
897
895
) -> Result < r:: Value , Vec < QueryExecutionError > > {
898
896
match field_type {
@@ -1037,7 +1035,7 @@ fn resolve_abstract_type<'a>(
1037
1035
pub fn coerce_argument_values < ' a > (
1038
1036
query : & crate :: execution:: Query ,
1039
1037
ty : impl Into < ObjectOrInterface < ' a > > ,
1040
- field : & q :: Field ,
1038
+ field : & a :: Field ,
1041
1039
) -> Result < HashMap < & ' a str , r:: Value > , Vec < QueryExecutionError > > {
1042
1040
let mut coerced_values = HashMap :: new ( ) ;
1043
1041
let mut errors = vec ! [ ] ;
@@ -1048,7 +1046,7 @@ pub fn coerce_argument_values<'a>(
1048
1046
. into_iter ( )
1049
1047
. flatten ( )
1050
1048
{
1051
- let value = qast :: get_argument_value ( & field. arguments , & argument_def. name ) . cloned ( ) ;
1049
+ let value = field. argument_value ( & argument_def. name ) . cloned ( ) ;
1052
1050
match coercion:: coerce_input_value ( value, & argument_def, & resolver) {
1053
1051
Ok ( Some ( value) ) => {
1054
1052
if argument_def. name == "text" . to_string ( ) {
0 commit comments