@@ -8,6 +8,7 @@ use interfaces::GqlInterface;
8
8
use objects:: { GqlObject , GqlObjectField } ;
9
9
use proc_macro2:: TokenStream ;
10
10
use query:: QueryContext ;
11
+ use scalars:: Scalar ;
11
12
use selection:: Selection ;
12
13
use std:: collections:: { BTreeMap , BTreeSet } ;
13
14
use unions:: GqlUnion ;
@@ -48,7 +49,7 @@ pub struct Schema {
48
49
pub inputs : BTreeMap < String , GqlInput > ,
49
50
pub interfaces : BTreeMap < String , GqlInterface > ,
50
51
pub objects : BTreeMap < String , GqlObject > ,
51
- pub scalars : BTreeSet < String > ,
52
+ pub scalars : BTreeMap < String , Scalar > ,
52
53
pub unions : BTreeMap < String , GqlUnion > ,
53
54
pub query_type : Option < String > ,
54
55
pub mutation_type : Option < String > ,
@@ -62,7 +63,7 @@ impl Schema {
62
63
inputs : BTreeMap :: new ( ) ,
63
64
interfaces : BTreeMap :: new ( ) ,
64
65
objects : BTreeMap :: new ( ) ,
65
- scalars : BTreeSet :: new ( ) ,
66
+ scalars : BTreeMap :: new ( ) ,
66
67
unions : BTreeMap :: new ( ) ,
67
68
query_type : None ,
68
69
mutation_type : None ,
@@ -179,13 +180,6 @@ impl Schema {
179
180
. or_else ( || context. _subscription_root . as_ref ( ) )
180
181
. expect ( "no selection defined" ) ;
181
182
182
- // TODO: do something smarter here
183
- let scalar_definitions = context. schema . scalars . iter ( ) . map ( |scalar_name| {
184
- use proc_macro2:: { Ident , Span } ;
185
- let ident = Ident :: new ( scalar_name, Span :: call_site ( ) ) ;
186
- quote ! ( type #ident = String ; )
187
- } ) ;
188
-
189
183
let input_object_definitions: Result < Vec < TokenStream > , _ > = context
190
184
. schema
191
185
. inputs
@@ -194,6 +188,13 @@ impl Schema {
194
188
. collect ( ) ;
195
189
let input_object_definitions = input_object_definitions?;
196
190
191
+ let scalar_definitions: Vec < TokenStream > = context
192
+ . schema
193
+ . scalars
194
+ . values ( )
195
+ . map ( |s| s. to_rust ( ) )
196
+ . collect ( ) ;
197
+
197
198
Ok ( quote ! {
198
199
type Boolean = bool ;
199
200
type Float = f64 ;
@@ -273,7 +274,13 @@ impl ::std::convert::From<graphql_parser::schema::Document> for Schema {
273
274
) ;
274
275
}
275
276
schema:: TypeDefinition :: Scalar ( scalar) => {
276
- schema. scalars . insert ( scalar. name ) ;
277
+ schema. scalars . insert (
278
+ scalar. name . clone ( ) ,
279
+ Scalar {
280
+ name : scalar. name ,
281
+ description : scalar. description ,
282
+ } ,
283
+ ) ;
277
284
}
278
285
schema:: TypeDefinition :: Union ( union) => {
279
286
let variants: BTreeSet < String > = union. types . into_iter ( ) . collect ( ) ;
@@ -369,7 +376,13 @@ impl ::std::convert::From<::introspection_response::IntrospectionResponse> for S
369
376
. find ( |s| s == & & name. as_str ( ) )
370
377
. is_none ( )
371
378
{
372
- schema. scalars . insert ( name) ;
379
+ schema. scalars . insert (
380
+ name. clone ( ) ,
381
+ Scalar {
382
+ name,
383
+ description : ty. description . as_ref ( ) . map ( |d| d. clone ( ) ) ,
384
+ } ,
385
+ ) ;
373
386
}
374
387
}
375
388
Some ( __TypeKind:: UNION ) => {
0 commit comments