@@ -10,10 +10,7 @@ use std::sync::Arc;
10
10
use std:: time:: Instant ;
11
11
use std:: { collections:: hash_map:: DefaultHasher , convert:: TryFrom } ;
12
12
13
- use graph:: data:: graphql:: {
14
- ext:: { DocumentExt , TypeExt } ,
15
- ObjectOrInterface ,
16
- } ;
13
+ use graph:: data:: graphql:: { ext:: TypeExt , ObjectOrInterface } ;
17
14
use graph:: data:: query:: QueryExecutionError ;
18
15
use graph:: data:: query:: { Query as GraphDataQuery , QueryVariables } ;
19
16
use graph:: data:: schema:: ApiSchema ;
@@ -23,10 +20,7 @@ use crate::execution::ast as a;
23
20
use crate :: query:: { ast as qast, ext:: BlockConstraint } ;
24
21
use crate :: schema:: ast as sast;
25
22
use crate :: values:: coercion;
26
- use crate :: {
27
- execution:: { get_field, get_named_type, object_or_interface} ,
28
- schema:: api:: ErrorPolicy ,
29
- } ;
23
+ use crate :: { execution:: get_field, schema:: api:: ErrorPolicy } ;
30
24
31
25
lazy_static ! {
32
26
static ref GRAPHQL_VALIDATION_PLAN : ValidationPlan = ValidationPlan :: from(
@@ -209,8 +203,8 @@ impl Query {
209
203
210
204
let start = Instant :: now ( ) ;
211
205
let root_type = match kind {
212
- Kind :: Query => schema. document ( ) . get_root_query_type ( ) . unwrap ( ) ,
213
- Kind :: Subscription => schema. document ( ) . get_root_subscription_type ( ) . unwrap ( ) ,
206
+ Kind :: Query => schema. query_type . as_ref ( ) ,
207
+ Kind :: Subscription => schema. subscription_type . as_ref ( ) . unwrap ( ) ,
214
208
} ;
215
209
// Use an intermediate struct so we can modify the query before
216
210
// enclosing it in an Arc
@@ -368,7 +362,7 @@ pub fn coerce_variables(
368
362
. flatten ( )
369
363
{
370
364
// Skip variable if it has an invalid type
371
- if !sast :: is_input_type ( schema. document ( ) , & variable_def. var_type ) {
365
+ if !schema. is_input_type ( & variable_def. var_type ) {
372
366
errors. push ( QueryExecutionError :: InvalidVariableTypeError (
373
367
variable_def. position ,
374
368
variable_def. name . to_owned ( ) ,
@@ -423,7 +417,7 @@ fn coerce_variable(
423
417
) -> Result < r:: Value , Vec < QueryExecutionError > > {
424
418
use crate :: values:: coercion:: coerce_value;
425
419
426
- let resolver = |name : & str | schema. document ( ) . get_named_type ( name) ;
420
+ let resolver = |name : & str | schema. get_named_type ( name) ;
427
421
428
422
coerce_value ( value, & variable_def. var_type , & resolver) . map_err ( |value| {
429
423
vec ! [ QueryExecutionError :: InvalidArgumentError (
@@ -482,7 +476,6 @@ impl<'s> RawQuery<'s> {
482
476
. items
483
477
. iter ( )
484
478
. try_fold ( 0 , |total_complexity, selection| {
485
- let schema = self . schema . document ( ) ;
486
479
match selection {
487
480
q:: Selection :: Field ( field) => {
488
481
// Empty selection sets are the base case.
@@ -506,7 +499,8 @@ impl<'s> RawQuery<'s> {
506
499
. ok_or ( Invalid ) ?;
507
500
508
501
let field_complexity = self . complexity_inner (
509
- & get_named_type ( schema, s_field. field_type . get_base_type ( ) )
502
+ self . schema
503
+ . get_named_type ( s_field. field_type . get_base_type ( ) )
510
504
. ok_or ( Invalid ) ?,
511
505
& field. selection_set ,
512
506
max_depth,
@@ -535,7 +529,7 @@ impl<'s> RawQuery<'s> {
535
529
q:: Selection :: FragmentSpread ( fragment) => {
536
530
let def = self . fragments . get ( & fragment. fragment_name ) . unwrap ( ) ;
537
531
let q:: TypeCondition :: On ( type_name) = & def. type_condition ;
538
- let ty = get_named_type ( schema , & type_name) . ok_or ( Invalid ) ?;
532
+ let ty = self . schema . get_named_type ( & type_name) . ok_or ( Invalid ) ?;
539
533
540
534
// Copy `visited_fragments` on write.
541
535
let mut visited_fragments = visited_fragments. clone ( ) ;
@@ -553,12 +547,12 @@ impl<'s> RawQuery<'s> {
553
547
q:: Selection :: InlineFragment ( fragment) => {
554
548
let ty = match & fragment. type_condition {
555
549
Some ( q:: TypeCondition :: On ( type_name) ) => {
556
- get_named_type ( schema , & type_name) . ok_or ( Invalid ) ?
550
+ self . schema . get_named_type ( type_name) . ok_or ( Invalid ) ?
557
551
}
558
- _ => ty. clone ( ) ,
552
+ _ => ty,
559
553
} ;
560
554
self . complexity_inner (
561
- & ty,
555
+ ty,
562
556
& fragment. selection_set ,
563
557
max_depth,
564
558
depth + 1 ,
@@ -575,7 +569,7 @@ impl<'s> RawQuery<'s> {
575
569
/// If the query is invalid, returns `Ok(0)` so that execution proceeds and
576
570
/// gives a proper error.
577
571
fn complexity ( & self , max_depth : u8 ) -> Result < u64 , QueryExecutionError > {
578
- let root_type = sast :: get_root_query_type_def ( self . schema . document ( ) ) . unwrap ( ) ;
572
+ let root_type = self . schema . get_root_query_type_def ( ) . unwrap ( ) ;
579
573
580
574
match self . complexity_inner (
581
575
root_type,
@@ -597,7 +591,7 @@ impl<'s> RawQuery<'s> {
597
591
}
598
592
599
593
fn validate_fields ( & self ) -> Result < ( ) , Vec < QueryExecutionError > > {
600
- let root_type = self . schema . document ( ) . get_root_query_type ( ) . unwrap ( ) ;
594
+ let root_type = self . schema . query_type . as_ref ( ) ;
601
595
602
596
let errors =
603
597
self . validate_fields_inner ( & "Query" . to_owned ( ) , root_type. into ( ) , & self . selection_set ) ;
@@ -615,8 +609,6 @@ impl<'s> RawQuery<'s> {
615
609
ty : ObjectOrInterface < ' _ > ,
616
610
selection_set : & q:: SelectionSet ,
617
611
) -> Vec < QueryExecutionError > {
618
- let schema = self . schema . document ( ) ;
619
-
620
612
selection_set
621
613
. items
622
614
. iter ( )
@@ -625,9 +617,9 @@ impl<'s> RawQuery<'s> {
625
617
q:: Selection :: Field ( field) => match get_field ( ty, & field. name ) {
626
618
Some ( s_field) => {
627
619
let base_type = s_field. field_type . get_base_type ( ) ;
628
- if get_named_type ( schema , base_type) . is_none ( ) {
620
+ if self . schema . get_named_type ( base_type) . is_none ( ) {
629
621
errors. push ( QueryExecutionError :: NamedTypeError ( base_type. into ( ) ) ) ;
630
- } else if let Some ( ty) = object_or_interface ( schema , base_type) {
622
+ } else if let Some ( ty) = self . schema . object_or_interface ( base_type) {
631
623
errors. extend ( self . validate_fields_inner (
632
624
base_type,
633
625
ty,
@@ -645,7 +637,7 @@ impl<'s> RawQuery<'s> {
645
637
match self . fragments . get ( & fragment. fragment_name ) {
646
638
Some ( frag) => {
647
639
let q:: TypeCondition :: On ( type_name) = & frag. type_condition ;
648
- match object_or_interface ( schema , type_name) {
640
+ match self . schema . object_or_interface ( type_name) {
649
641
Some ( ty) => errors. extend ( self . validate_fields_inner (
650
642
type_name,
651
643
ty,
@@ -663,7 +655,7 @@ impl<'s> RawQuery<'s> {
663
655
}
664
656
q:: Selection :: InlineFragment ( fragment) => match & fragment. type_condition {
665
657
Some ( q:: TypeCondition :: On ( type_name) ) => {
666
- match object_or_interface ( schema , type_name) {
658
+ match self . schema . object_or_interface ( type_name) {
667
659
Some ( ty) => errors. extend ( self . validate_fields_inner (
668
660
type_name,
669
661
ty,
@@ -797,7 +789,7 @@ impl Transform {
797
789
) -> Result < ( ) , Vec < QueryExecutionError > > {
798
790
let mut errors = vec ! [ ] ;
799
791
800
- let resolver = |name : & str | self . schema . document ( ) . get_named_type ( name) ;
792
+ let resolver = |name : & str | self . schema . get_named_type ( name) ;
801
793
802
794
for argument_def in sast:: get_argument_definitions ( ty, field_name)
803
795
. into_iter ( )
@@ -864,7 +856,7 @@ impl Transform {
864
856
let field_type = parent_type. field ( & name) . expect ( "field names are valid" ) ;
865
857
let ty = field_type. field_type . get_base_type ( ) ;
866
858
let type_set = a:: ObjectTypeSet :: from_name ( & self . schema , ty) ?;
867
- let ty = self . schema . document ( ) . object_or_interface ( ty) . unwrap ( ) ;
859
+ let ty = self . schema . object_or_interface ( ty) . unwrap ( ) ;
868
860
self . expand_selection_set ( selection_set, & type_set, ty) ?
869
861
} ;
870
862
@@ -966,7 +958,6 @@ impl Transform {
966
958
let ty = match frag_cond {
967
959
Some ( q:: TypeCondition :: On ( name) ) => self
968
960
. schema
969
- . document ( )
970
961
. object_or_interface ( name)
971
962
. expect ( "type names on fragment spreads are valid" ) ,
972
963
None => ty,
0 commit comments