@@ -19,9 +19,9 @@ use types::base::GraphQLType;
19
19
/// The registry gathers metadata for all types in a schema. It provides
20
20
/// convenience methods to convert types implementing the `GraphQLType` trait
21
21
/// into `Type` instances and automatically registers them.
22
- pub struct Registry {
22
+ pub struct Registry < ' r > {
23
23
/// Currently registered types
24
- pub types : HashMap < String , MetaType > ,
24
+ pub types : HashMap < String , MetaType < ' r > > ,
25
25
}
26
26
27
27
#[ derive( Clone ) ]
@@ -38,7 +38,7 @@ pub struct Executor<'a, CtxT> where CtxT: 'a {
38
38
fragments : & ' a HashMap < & ' a str , & ' a Fragment > ,
39
39
variables : & ' a HashMap < String , InputValue > ,
40
40
current_selection_set : Option < & ' a [ Selection ] > ,
41
- schema : & ' a SchemaType ,
41
+ schema : & ' a SchemaType < ' a > ,
42
42
context : & ' a CtxT ,
43
43
errors : & ' a RwLock < Vec < ExecutionError > > ,
44
44
field_path : FieldPath < ' a > ,
@@ -353,9 +353,9 @@ pub fn execute_validated_query<'a, QueryT, MutationT, CtxT>(
353
353
Ok ( ( value, errors) )
354
354
}
355
355
356
- impl Registry {
356
+ impl < ' r > Registry < ' r > {
357
357
/// Construct a new registry
358
- pub fn new ( types : HashMap < String , MetaType > ) -> Registry {
358
+ pub fn new ( types : HashMap < String , MetaType < ' r > > ) -> Registry < ' r > {
359
359
Registry {
360
360
types : types,
361
361
}
@@ -365,10 +365,10 @@ impl Registry {
365
365
///
366
366
/// If the registry hasn't seen a type with this name before, it will
367
367
/// 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 {
369
369
if let Some ( name) = T :: name ( ) {
370
370
if !self . types . contains_key ( name) {
371
- self . insert_placeholder ( name, Type :: NonNullNamed ( name. to_owned ( ) ) ) ;
371
+ self . insert_placeholder ( name, Type :: NonNullNamed ( name) ) ;
372
372
let meta = T :: meta ( self ) ;
373
373
self . types . insert ( name. to_owned ( ) , meta) ;
374
374
}
@@ -380,7 +380,7 @@ impl Registry {
380
380
}
381
381
382
382
/// 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 {
384
384
Field {
385
385
name : name. to_owned ( ) ,
386
386
description : None ,
@@ -391,7 +391,7 @@ impl Registry {
391
391
}
392
392
393
393
#[ 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 >
395
395
where I : GraphQLType
396
396
{
397
397
Field {
@@ -404,7 +404,7 @@ impl Registry {
404
404
}
405
405
406
406
/// 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 {
408
408
Argument :: new ( name, self . get_type :: < T > ( ) )
409
409
}
410
410
@@ -417,14 +417,14 @@ impl Registry {
417
417
name : & str ,
418
418
value : & T ,
419
419
)
420
- -> Argument
420
+ -> Argument < ' r >
421
421
where T : GraphQLType + ToInputValue + FromInputValue
422
422
{
423
423
Argument :: new ( name, self . get_type :: < Option < T > > ( ) )
424
424
. default_value ( value. to ( ) )
425
425
}
426
426
427
- fn insert_placeholder ( & mut self , name : & str , of_type : Type ) {
427
+ fn insert_placeholder ( & mut self , name : & str , of_type : Type < ' r > ) {
428
428
if !self . types . contains_key ( name) {
429
429
self . types . insert (
430
430
name. to_owned ( ) ,
@@ -435,22 +435,21 @@ impl Registry {
435
435
/// Create a scalar meta type
436
436
///
437
437
/// 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 >
440
439
where T : FromInputValue + GraphQLType
441
440
{
442
441
let name = T :: name ( ) . expect ( "Scalar types must be named. Implement name()" ) ;
443
442
ScalarMeta :: new :: < T > ( name)
444
443
}
445
444
446
445
/// 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 > {
448
447
let of_type = self . get_type :: < T > ( ) ;
449
448
ListMeta :: new ( of_type)
450
449
}
451
450
452
451
/// 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 > {
454
453
let of_type = self . get_type :: < T > ( ) ;
455
454
NullableMeta :: new ( of_type)
456
455
}
@@ -459,62 +458,51 @@ impl Registry {
459
458
///
460
459
/// To prevent infinite recursion by enforcing ordering, this returns a
461
460
/// 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 >
464
462
where T : GraphQLType
465
463
{
466
464
let name = T :: name ( ) . expect ( "Object types must be named. Implement name()" ) ;
467
- let typename_field = self . field :: < String > ( "__typename" ) ;
468
465
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)
474
469
}
475
470
476
471
/// 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 >
479
473
where T : FromInputValue + GraphQLType
480
474
{
481
475
let name = T :: name ( ) . expect ( "Enum types must be named. Implement name()" ) ;
482
476
483
- Box :: new ( move | values : & [ EnumValue ] | EnumMeta :: new :: < T > ( name, values) )
477
+ EnumMeta :: new :: < T > ( name, values)
484
478
}
485
479
486
480
/// 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 >
489
482
where T : GraphQLType
490
483
{
491
484
let name = T :: name ( ) . expect ( "Interface types must be named. Implement name()" ) ;
492
- let typename_field = self . field :: < String > ( "__typename" ) ;
493
485
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)
499
489
}
500
490
501
491
/// 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 >
504
493
where T : GraphQLType
505
494
{
506
495
let name = T :: name ( ) . expect ( "Union types must be named. Implement name()" ) ;
507
496
508
- Box :: new ( move | ts : & [ Type ] | UnionMeta :: new ( name, ts ) )
497
+ UnionMeta :: new ( name, types )
509
498
}
510
499
511
500
/// 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 >
514
502
where T : FromInputValue + GraphQLType
515
503
{
516
504
let name = T :: name ( ) . expect ( "Input object types must be named. Implement name()" ) ;
517
505
518
- Box :: new ( move | args : & [ Argument ] | InputObjectMeta :: new :: < T > ( name, args) )
506
+ InputObjectMeta :: new :: < T > ( name, args)
519
507
}
520
508
}
0 commit comments