@@ -8,6 +8,7 @@ use interfaces::GqlInterface;
88use objects:: { GqlObject , GqlObjectField } ;
99use proc_macro2:: TokenStream ;
1010use query:: QueryContext ;
11+ use scalars:: Scalar ;
1112use selection:: Selection ;
1213use std:: collections:: { BTreeMap , BTreeSet } ;
1314use unions:: GqlUnion ;
@@ -48,7 +49,7 @@ pub struct Schema {
4849 pub inputs : BTreeMap < String , GqlInput > ,
4950 pub interfaces : BTreeMap < String , GqlInterface > ,
5051 pub objects : BTreeMap < String , GqlObject > ,
51- pub scalars : BTreeSet < String > ,
52+ pub scalars : BTreeMap < String , Scalar > ,
5253 pub unions : BTreeMap < String , GqlUnion > ,
5354 pub query_type : Option < String > ,
5455 pub mutation_type : Option < String > ,
@@ -62,7 +63,7 @@ impl Schema {
6263 inputs : BTreeMap :: new ( ) ,
6364 interfaces : BTreeMap :: new ( ) ,
6465 objects : BTreeMap :: new ( ) ,
65- scalars : BTreeSet :: new ( ) ,
66+ scalars : BTreeMap :: new ( ) ,
6667 unions : BTreeMap :: new ( ) ,
6768 query_type : None ,
6869 mutation_type : None ,
@@ -179,13 +180,6 @@ impl Schema {
179180 . or_else ( || context. _subscription_root . as_ref ( ) )
180181 . expect ( "no selection defined" ) ;
181182
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-
189183 let input_object_definitions: Result < Vec < TokenStream > , _ > = context
190184 . schema
191185 . inputs
@@ -194,6 +188,13 @@ impl Schema {
194188 . collect ( ) ;
195189 let input_object_definitions = input_object_definitions?;
196190
191+ let scalar_definitions: Vec < TokenStream > = context
192+ . schema
193+ . scalars
194+ . values ( )
195+ . map ( |s| s. to_rust ( ) )
196+ . collect ( ) ;
197+
197198 Ok ( quote ! {
198199 type Boolean = bool ;
199200 type Float = f64 ;
@@ -273,7 +274,13 @@ impl ::std::convert::From<graphql_parser::schema::Document> for Schema {
273274 ) ;
274275 }
275276 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+ ) ;
277284 }
278285 schema:: TypeDefinition :: Union ( union) => {
279286 let variants: BTreeSet < String > = union. types . into_iter ( ) . collect ( ) ;
@@ -369,7 +376,13 @@ impl ::std::convert::From<::introspection_response::IntrospectionResponse> for S
369376 . find ( |s| s == & & name. as_str ( ) )
370377 . is_none ( )
371378 {
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+ ) ;
373386 }
374387 }
375388 Some ( __TypeKind:: UNION ) => {
0 commit comments