@@ -19,9 +19,9 @@ use types::base::GraphQLType;
1919/// The registry gathers metadata for all types in a schema. It provides
2020/// convenience methods to convert types implementing the `GraphQLType` trait
2121/// into `Type` instances and automatically registers them.
22- pub struct Registry {
22+ pub struct Registry < ' r > {
2323 /// Currently registered types
24- pub types : HashMap < String , MetaType > ,
24+ pub types : HashMap < String , MetaType < ' r > > ,
2525}
2626
2727#[ derive( Clone ) ]
@@ -38,7 +38,7 @@ pub struct Executor<'a, CtxT> where CtxT: 'a {
3838 fragments : & ' a HashMap < & ' a str , & ' a Fragment > ,
3939 variables : & ' a HashMap < String , InputValue > ,
4040 current_selection_set : Option < & ' a [ Selection ] > ,
41- schema : & ' a SchemaType ,
41+ schema : & ' a SchemaType < ' a > ,
4242 context : & ' a CtxT ,
4343 errors : & ' a RwLock < Vec < ExecutionError > > ,
4444 field_path : FieldPath < ' a > ,
@@ -353,9 +353,9 @@ pub fn execute_validated_query<'a, QueryT, MutationT, CtxT>(
353353 Ok ( ( value, errors) )
354354}
355355
356- impl Registry {
356+ impl < ' r > Registry < ' r > {
357357 /// Construct a new registry
358- pub fn new ( types : HashMap < String , MetaType > ) -> Registry {
358+ pub fn new ( types : HashMap < String , MetaType < ' r > > ) -> Registry < ' r > {
359359 Registry {
360360 types : types,
361361 }
@@ -365,10 +365,10 @@ impl Registry {
365365 ///
366366 /// If the registry hasn't seen a type with this name before, it will
367367 /// construct its metadata and store it.
368- pub fn get_type < T > ( & mut self ) -> Type where T : GraphQLType {
368+ pub fn get_type < T > ( & mut self ) -> Type < ' r > where T : GraphQLType {
369369 if let Some ( name) = T :: name ( ) {
370370 if !self . types . contains_key ( name) {
371- self . insert_placeholder ( name, Type :: NonNullNamed ( name. to_owned ( ) ) ) ;
371+ self . insert_placeholder ( name, Type :: NonNullNamed ( name) ) ;
372372 let meta = T :: meta ( self ) ;
373373 self . types . insert ( name. to_owned ( ) , meta) ;
374374 }
@@ -380,7 +380,7 @@ impl Registry {
380380 }
381381
382382 /// Create a field with the provided name
383- pub fn field < T > ( & mut self , name : & str ) -> Field where T : GraphQLType {
383+ pub fn field < T > ( & mut self , name : & str ) -> Field < ' r > where T : GraphQLType {
384384 Field {
385385 name : name. to_owned ( ) ,
386386 description : None ,
@@ -391,7 +391,7 @@ impl Registry {
391391 }
392392
393393 #[ doc( hidden) ]
394- pub fn field_convert < ' a , T : IntoResolvable < ' a , I , C > , I , C > ( & mut self , name : & str ) -> Field
394+ pub fn field_convert < ' a , T : IntoResolvable < ' a , I , C > , I , C > ( & mut self , name : & str ) -> Field < ' r >
395395 where I : GraphQLType
396396 {
397397 Field {
@@ -404,7 +404,7 @@ impl Registry {
404404 }
405405
406406 /// Create an argument with the provided name
407- pub fn arg < T > ( & mut self , name : & str ) -> Argument where T : GraphQLType + FromInputValue {
407+ pub fn arg < T > ( & mut self , name : & str ) -> Argument < ' r > where T : GraphQLType + FromInputValue {
408408 Argument :: new ( name, self . get_type :: < T > ( ) )
409409 }
410410
@@ -417,14 +417,14 @@ impl Registry {
417417 name : & str ,
418418 value : & T ,
419419 )
420- -> Argument
420+ -> Argument < ' r >
421421 where T : GraphQLType + ToInputValue + FromInputValue
422422 {
423423 Argument :: new ( name, self . get_type :: < Option < T > > ( ) )
424424 . default_value ( value. to ( ) )
425425 }
426426
427- fn insert_placeholder ( & mut self , name : & str , of_type : Type ) {
427+ fn insert_placeholder ( & mut self , name : & str , of_type : Type < ' r > ) {
428428 if !self . types . contains_key ( name) {
429429 self . types . insert (
430430 name. to_owned ( ) ,
@@ -435,22 +435,21 @@ impl Registry {
435435 /// Create a scalar meta type
436436 ///
437437 /// This expects the type to implement `FromInputValue`.
438- pub fn build_scalar_type < T > ( & mut self )
439- -> ScalarMeta
438+ pub fn build_scalar_type < T > ( & mut self ) -> ScalarMeta < ' r >
440439 where T : FromInputValue + GraphQLType
441440 {
442441 let name = T :: name ( ) . expect ( "Scalar types must be named. Implement name()" ) ;
443442 ScalarMeta :: new :: < T > ( name)
444443 }
445444
446445 /// Create a list meta type
447- pub fn build_list_type < T : GraphQLType > ( & mut self ) -> ListMeta {
446+ pub fn build_list_type < T : GraphQLType > ( & mut self ) -> ListMeta < ' r > {
448447 let of_type = self . get_type :: < T > ( ) ;
449448 ListMeta :: new ( of_type)
450449 }
451450
452451 /// Create a nullable meta type
453- pub fn build_nullable_type < T : GraphQLType > ( & mut self ) -> NullableMeta {
452+ pub fn build_nullable_type < T : GraphQLType > ( & mut self ) -> NullableMeta < ' r > {
454453 let of_type = self . get_type :: < T > ( ) ;
455454 NullableMeta :: new ( of_type)
456455 }
@@ -459,62 +458,51 @@ impl Registry {
459458 ///
460459 /// To prevent infinite recursion by enforcing ordering, this returns a
461460 /// function that needs to be called with the list of fields on the object.
462- pub fn build_object_type < T > ( & mut self )
463- -> Box < Fn ( & [ Field ] ) -> ObjectMeta >
461+ pub fn build_object_type < T > ( & mut self , fields : & [ Field < ' r > ] ) -> ObjectMeta < ' r >
464462 where T : GraphQLType
465463 {
466464 let name = T :: name ( ) . expect ( "Object types must be named. Implement name()" ) ;
467- let typename_field = self . field :: < String > ( "__typename" ) ;
468465
469- Box :: new ( move |fs : & [ Field ] | {
470- let mut v = fs. to_vec ( ) ;
471- v. push ( typename_field. clone ( ) ) ;
472- ObjectMeta :: new ( name, & v)
473- } )
466+ let mut v = fields. to_vec ( ) ;
467+ v. push ( self . field :: < String > ( "__typename" ) ) ;
468+ ObjectMeta :: new ( name, & v)
474469 }
475470
476471 /// Create an enum meta type
477- pub fn build_enum_type < T > ( & mut self )
478- -> Box < Fn ( & [ EnumValue ] ) -> EnumMeta >
472+ pub fn build_enum_type < T > ( & mut self , values : & [ EnumValue ] ) -> EnumMeta < ' r >
479473 where T : FromInputValue + GraphQLType
480474 {
481475 let name = T :: name ( ) . expect ( "Enum types must be named. Implement name()" ) ;
482476
483- Box :: new ( move | values : & [ EnumValue ] | EnumMeta :: new :: < T > ( name, values) )
477+ EnumMeta :: new :: < T > ( name, values)
484478 }
485479
486480 /// Create an interface meta type builder
487- pub fn build_interface_type < T > ( & mut self )
488- -> Box < Fn ( & [ Field ] ) -> InterfaceMeta >
481+ pub fn build_interface_type < T > ( & mut self , fields : & [ Field < ' r > ] ) -> InterfaceMeta < ' r >
489482 where T : GraphQLType
490483 {
491484 let name = T :: name ( ) . expect ( "Interface types must be named. Implement name()" ) ;
492- let typename_field = self . field :: < String > ( "__typename" ) ;
493485
494- Box :: new ( move |fs : & [ Field ] | {
495- let mut v = fs. to_vec ( ) ;
496- v. push ( typename_field. clone ( ) ) ;
497- InterfaceMeta :: new ( name, & v)
498- } )
486+ let mut v = fields. to_vec ( ) ;
487+ v. push ( self . field :: < String > ( "__typename" ) ) ;
488+ InterfaceMeta :: new ( name, & v)
499489 }
500490
501491 /// Create a union meta type builder
502- pub fn build_union_type < T > ( & mut self )
503- -> Box < Fn ( & [ Type ] ) -> UnionMeta >
492+ pub fn build_union_type < T > ( & mut self , types : & [ Type < ' r > ] ) -> UnionMeta < ' r >
504493 where T : GraphQLType
505494 {
506495 let name = T :: name ( ) . expect ( "Union types must be named. Implement name()" ) ;
507496
508- Box :: new ( move | ts : & [ Type ] | UnionMeta :: new ( name, ts ) )
497+ UnionMeta :: new ( name, types )
509498 }
510499
511500 /// Create an input object meta type builder
512- pub fn build_input_object_type < T > ( & mut self )
513- -> Box < Fn ( & [ Argument ] ) -> InputObjectMeta >
501+ pub fn build_input_object_type < T > ( & mut self , args : & [ Argument < ' r > ] ) -> InputObjectMeta < ' r >
514502 where T : FromInputValue + GraphQLType
515503 {
516504 let name = T :: name ( ) . expect ( "Input object types must be named. Implement name()" ) ;
517505
518- Box :: new ( move | args : & [ Argument ] | InputObjectMeta :: new :: < T > ( name, args) )
506+ InputObjectMeta :: new :: < T > ( name, args)
519507 }
520508}
0 commit comments