@@ -10,10 +10,7 @@ use std::sync::Arc;
1010use std:: time:: Instant ;
1111use std:: { collections:: hash_map:: DefaultHasher , convert:: TryFrom } ;
1212
13- use graph:: data:: graphql:: {
14- ext:: { DocumentExt , TypeExt } ,
15- ObjectOrInterface ,
16- } ;
13+ use graph:: data:: graphql:: { ext:: TypeExt , ObjectOrInterface } ;
1714use graph:: data:: query:: QueryExecutionError ;
1815use graph:: data:: query:: { Query as GraphDataQuery , QueryVariables } ;
1916use graph:: data:: schema:: ApiSchema ;
@@ -23,10 +20,7 @@ use crate::execution::ast as a;
2320use crate :: query:: { ast as qast, ext:: BlockConstraint } ;
2421use crate :: schema:: ast as sast;
2522use 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 } ;
3024
3125lazy_static ! {
3226 static ref GRAPHQL_VALIDATION_PLAN : ValidationPlan = ValidationPlan :: from(
@@ -209,8 +203,8 @@ impl Query {
209203
210204 let start = Instant :: now ( ) ;
211205 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 ( ) ,
214208 } ;
215209 // Use an intermediate struct so we can modify the query before
216210 // enclosing it in an Arc
@@ -368,7 +362,7 @@ pub fn coerce_variables(
368362 . flatten ( )
369363 {
370364 // 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 ) {
372366 errors. push ( QueryExecutionError :: InvalidVariableTypeError (
373367 variable_def. position ,
374368 variable_def. name . to_owned ( ) ,
@@ -423,7 +417,7 @@ fn coerce_variable(
423417) -> Result < r:: Value , Vec < QueryExecutionError > > {
424418 use crate :: values:: coercion:: coerce_value;
425419
426- let resolver = |name : & str | schema. document ( ) . get_named_type ( name) ;
420+ let resolver = |name : & str | schema. get_named_type ( name) ;
427421
428422 coerce_value ( value, & variable_def. var_type , & resolver) . map_err ( |value| {
429423 vec ! [ QueryExecutionError :: InvalidArgumentError (
@@ -482,7 +476,6 @@ impl<'s> RawQuery<'s> {
482476 . items
483477 . iter ( )
484478 . try_fold ( 0 , |total_complexity, selection| {
485- let schema = self . schema . document ( ) ;
486479 match selection {
487480 q:: Selection :: Field ( field) => {
488481 // Empty selection sets are the base case.
@@ -506,7 +499,8 @@ impl<'s> RawQuery<'s> {
506499 . ok_or ( Invalid ) ?;
507500
508501 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 ( ) )
510504 . ok_or ( Invalid ) ?,
511505 & field. selection_set ,
512506 max_depth,
@@ -535,7 +529,7 @@ impl<'s> RawQuery<'s> {
535529 q:: Selection :: FragmentSpread ( fragment) => {
536530 let def = self . fragments . get ( & fragment. fragment_name ) . unwrap ( ) ;
537531 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 ) ?;
539533
540534 // Copy `visited_fragments` on write.
541535 let mut visited_fragments = visited_fragments. clone ( ) ;
@@ -553,12 +547,12 @@ impl<'s> RawQuery<'s> {
553547 q:: Selection :: InlineFragment ( fragment) => {
554548 let ty = match & fragment. type_condition {
555549 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 ) ?
557551 }
558- _ => ty. clone ( ) ,
552+ _ => ty,
559553 } ;
560554 self . complexity_inner (
561- & ty,
555+ ty,
562556 & fragment. selection_set ,
563557 max_depth,
564558 depth + 1 ,
@@ -575,7 +569,7 @@ impl<'s> RawQuery<'s> {
575569 /// If the query is invalid, returns `Ok(0)` so that execution proceeds and
576570 /// gives a proper error.
577571 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 ( ) ;
579573
580574 match self . complexity_inner (
581575 root_type,
@@ -597,7 +591,7 @@ impl<'s> RawQuery<'s> {
597591 }
598592
599593 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 ( ) ;
601595
602596 let errors =
603597 self . validate_fields_inner ( & "Query" . to_owned ( ) , root_type. into ( ) , & self . selection_set ) ;
@@ -615,8 +609,6 @@ impl<'s> RawQuery<'s> {
615609 ty : ObjectOrInterface < ' _ > ,
616610 selection_set : & q:: SelectionSet ,
617611 ) -> Vec < QueryExecutionError > {
618- let schema = self . schema . document ( ) ;
619-
620612 selection_set
621613 . items
622614 . iter ( )
@@ -625,9 +617,9 @@ impl<'s> RawQuery<'s> {
625617 q:: Selection :: Field ( field) => match get_field ( ty, & field. name ) {
626618 Some ( s_field) => {
627619 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 ( ) {
629621 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) {
631623 errors. extend ( self . validate_fields_inner (
632624 base_type,
633625 ty,
@@ -645,7 +637,7 @@ impl<'s> RawQuery<'s> {
645637 match self . fragments . get ( & fragment. fragment_name ) {
646638 Some ( frag) => {
647639 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) {
649641 Some ( ty) => errors. extend ( self . validate_fields_inner (
650642 type_name,
651643 ty,
@@ -663,7 +655,7 @@ impl<'s> RawQuery<'s> {
663655 }
664656 q:: Selection :: InlineFragment ( fragment) => match & fragment. type_condition {
665657 Some ( q:: TypeCondition :: On ( type_name) ) => {
666- match object_or_interface ( schema , type_name) {
658+ match self . schema . object_or_interface ( type_name) {
667659 Some ( ty) => errors. extend ( self . validate_fields_inner (
668660 type_name,
669661 ty,
@@ -797,7 +789,7 @@ impl Transform {
797789 ) -> Result < ( ) , Vec < QueryExecutionError > > {
798790 let mut errors = vec ! [ ] ;
799791
800- let resolver = |name : & str | self . schema . document ( ) . get_named_type ( name) ;
792+ let resolver = |name : & str | self . schema . get_named_type ( name) ;
801793
802794 for argument_def in sast:: get_argument_definitions ( ty, field_name)
803795 . into_iter ( )
@@ -864,7 +856,7 @@ impl Transform {
864856 let field_type = parent_type. field ( & name) . expect ( "field names are valid" ) ;
865857 let ty = field_type. field_type . get_base_type ( ) ;
866858 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 ( ) ;
868860 self . expand_selection_set ( selection_set, & type_set, ty) ?
869861 } ;
870862
@@ -966,7 +958,6 @@ impl Transform {
966958 let ty = match frag_cond {
967959 Some ( q:: TypeCondition :: On ( name) ) => self
968960 . schema
969- . document ( )
970961 . object_or_interface ( name)
971962 . expect ( "type names on fragment spreads are valid" ) ,
972963 None => ty,
0 commit comments