@@ -9,6 +9,7 @@ struct DefaultName(i32);
9
9
struct OtherOrder ( i32 ) ;
10
10
struct Named ( i32 ) ;
11
11
struct ScalarDescription ( i32 ) ;
12
+ struct Generated ( String ) ;
12
13
13
14
struct Root ;
14
15
@@ -86,6 +87,32 @@ impl GraphQLScalar for ScalarDescription {
86
87
}
87
88
}
88
89
90
+ macro_rules! impl_scalar {
91
+ ( $name: ident) => {
92
+ #[ graphql_scalar]
93
+ impl <S > GraphQLScalar for $name
94
+ where
95
+ S : ScalarValue ,
96
+ {
97
+ fn resolve( & self ) -> Value {
98
+ Value :: scalar( self . 0 . clone( ) )
99
+ }
100
+
101
+ fn from_input_value( v: & InputValue ) -> Option <Self > {
102
+ v. as_scalar_value( )
103
+ . and_then( |v| v. as_str( ) )
104
+ . and_then( |s| Some ( Self ( s. to_owned( ) ) ) )
105
+ }
106
+
107
+ fn from_str<' a>( value: ScalarToken <' a>) -> ParseScalarResult <' a, S > {
108
+ <String as ParseScalarValue <S >>:: from_str( value)
109
+ }
110
+ }
111
+ } ;
112
+ }
113
+
114
+ impl_scalar ! ( Generated ) ;
115
+
89
116
#[ graphql_object( scalar = DefaultScalarValue ) ]
90
117
impl Root {
91
118
fn default_name ( ) -> DefaultName {
@@ -100,6 +127,9 @@ impl Root {
100
127
fn scalar_description ( ) -> ScalarDescription {
101
128
ScalarDescription ( 0 )
102
129
}
130
+ fn generated ( ) -> Generated {
131
+ Generated ( "foo" . to_owned ( ) )
132
+ }
103
133
}
104
134
105
135
struct WithCustomScalarValue ( i32 ) ;
@@ -274,6 +304,30 @@ async fn scalar_description_introspection() {
274
304
. await ;
275
305
}
276
306
307
+ #[ tokio:: test]
308
+ async fn generated_scalar_introspection ( ) {
309
+ let doc = r#"
310
+ {
311
+ __type(name: "Generated") {
312
+ name
313
+ description
314
+ }
315
+ }
316
+ "# ;
317
+
318
+ run_type_info_query ( doc, |type_info| {
319
+ assert_eq ! (
320
+ type_info. get_field_value( "name" ) ,
321
+ Some ( & Value :: scalar( "Generated" ) )
322
+ ) ;
323
+ assert_eq ! (
324
+ type_info. get_field_value( "description" ) ,
325
+ Some ( & Value :: null( ) )
326
+ ) ;
327
+ } )
328
+ . await ;
329
+ }
330
+
277
331
#[ tokio:: test]
278
332
async fn resolves_with_custom_scalar_value ( ) {
279
333
const DOC : & str = r#"{ withCustomScalarValue }"# ;
0 commit comments