@@ -273,10 +273,11 @@ pub struct GraphQLTypeDefiniton {
273
273
pub scalar : Option < syn:: Type > ,
274
274
pub description : Option < String > ,
275
275
pub fields : Vec < GraphQLTypeDefinitionField > ,
276
+ pub generics : syn:: Generics ,
276
277
}
277
278
278
279
impl GraphQLTypeDefiniton {
279
- pub fn to_tokens ( & self ) -> proc_macro2:: TokenStream {
280
+ pub fn into_tokens ( self ) -> proc_macro2:: TokenStream {
280
281
let name = & self . name ;
281
282
let ty = & self . _type ;
282
283
let context = self
@@ -347,8 +348,36 @@ impl GraphQLTypeDefiniton {
347
348
None => quote ! ( ) ,
348
349
} ;
349
350
351
+
352
+ let ( _, ty_generics, _) = self . generics . split_for_impl ( ) ;
353
+
354
+ let mut generics = self . generics . clone ( ) ;
355
+
356
+ if self . scalar . is_none ( ) {
357
+ generics. params . push ( parse_quote ! ( __S) ) ;
358
+ {
359
+ let where_clause = generics. where_clause . get_or_insert ( parse_quote ! ( where ) ) ;
360
+ where_clause
361
+ . predicates
362
+ . push ( parse_quote ! ( __S: juniper:: ScalarValue ) ) ;
363
+ where_clause
364
+ . predicates
365
+ . push ( parse_quote ! ( for <' __b> & ' __b __S: juniper:: ScalarRefValue <' __b>) ) ;
366
+ }
367
+ }
368
+
369
+ let scalar = self
370
+ . scalar
371
+ . as_ref ( )
372
+ . map ( |s| quote ! ( #s ) )
373
+ . unwrap_or_else ( || quote ! ( __S ) ) ;
374
+
375
+ let ( impl_generics, _, where_clause) = generics. split_for_impl ( ) ;
376
+
350
377
quote ! (
351
- impl juniper:: GraphQLType <#scalar> for #ty {
378
+ impl #impl_generics juniper:: GraphQLType <#scalar> for #ty #ty_generics
379
+ #where_clause
380
+ {
352
381
type Context = #context;
353
382
type TypeInfo = ( ) ;
354
383
@@ -361,7 +390,7 @@ impl GraphQLTypeDefiniton {
361
390
registry: & mut juniper:: Registry <' r, #scalar>
362
391
) -> juniper:: meta:: MetaType <' r, #scalar>
363
392
where #scalar : ' r,
364
- for <' z> & ' z juniper:: DefaultScalarValue : juniper:: ScalarRefValue <' z>,
393
+ // for<'z> &'z juniper::DefaultScalarValue: juniper::ScalarRefValue<'z>,
365
394
{
366
395
let fields = vec![
367
396
#( #field_definitions ) , *
@@ -377,9 +406,9 @@ impl GraphQLTypeDefiniton {
377
406
& self ,
378
407
_info: & ( ) ,
379
408
field: & str ,
380
- args: & juniper:: Arguments ,
381
- executor: & juniper:: Executor <Self :: Context >,
382
- ) -> juniper:: ExecutionResult {
409
+ args: & juniper:: Arguments <#scalar> ,
410
+ executor: & juniper:: Executor <Self :: Context , #scalar >,
411
+ ) -> juniper:: ExecutionResult <#scalar> {
383
412
match field {
384
413
#( #resolve_matches ) *
385
414
_ => {
0 commit comments