@@ -8,8 +8,8 @@ use interfaces::GqlInterface;
88use objects:: { GqlObject , GqlObjectField } ;
99use proc_macro2:: TokenStream ;
1010use query:: QueryContext ;
11- use std:: collections:: { BTreeMap , BTreeSet } ;
1211use selection:: Selection ;
12+ use std:: collections:: { BTreeMap , BTreeSet } ;
1313use unions:: GqlUnion ;
1414
1515pub const DEFAULT_SCALARS : & [ & ' static str ] = & [ "ID" , "String" , "Int" , "Float" , "Boolean" ] ;
@@ -60,16 +60,12 @@ impl Schema {
6060 let prefix = format ! ( "RUST_{}" , prefix) ;
6161 let selection = Selection :: from ( & q. selection_set ) ;
6262
63- definitions. extend ( definition. field_impls_for_selection (
64- & context,
65- & selection,
66- & prefix,
67- ) ?) ;
68- Some ( definition. response_fields_for_selection (
69- & context,
70- & selection,
71- & prefix,
72- ) )
63+ definitions. extend (
64+ definition. field_impls_for_selection ( & context, & selection, & prefix) ?,
65+ ) ;
66+ Some (
67+ definition. response_fields_for_selection ( & context, & selection, & prefix) ,
68+ )
7369 } ;
7470 }
7571 query:: Definition :: Operation ( query:: OperationDefinition :: Mutation ( q) ) => {
@@ -84,16 +80,12 @@ impl Schema {
8480 let prefix = format ! ( "RUST_{}" , prefix) ;
8581 let selection = Selection :: from ( & q. selection_set ) ;
8682
87- definitions. extend ( definition. field_impls_for_selection (
88- & context,
89- & selection,
90- & prefix,
91- ) ?) ;
92- Some ( definition. response_fields_for_selection (
93- & context,
94- & selection,
95- & prefix,
96- ) )
83+ definitions. extend (
84+ definition. field_impls_for_selection ( & context, & selection, & prefix) ?,
85+ ) ;
86+ Some (
87+ definition. response_fields_for_selection ( & context, & selection, & prefix) ,
88+ )
9789 } ;
9890 }
9991 query:: Definition :: Operation ( query:: OperationDefinition :: Subscription ( q) ) => {
@@ -110,16 +102,12 @@ impl Schema {
110102 let prefix = format ! ( "RUST_{}" , prefix) ;
111103 let selection = Selection :: from ( & q. selection_set ) ;
112104
113- definitions. extend ( definition. field_impls_for_selection (
114- & context,
115- & selection,
116- & prefix,
117- ) ?) ;
118- Some ( definition. response_fields_for_selection (
119- & context,
120- & selection,
121- & prefix,
122- ) )
105+ definitions. extend (
106+ definition. field_impls_for_selection ( & context, & selection, & prefix) ?,
107+ ) ;
108+ Some (
109+ definition. response_fields_for_selection ( & context, & selection, & prefix) ,
110+ )
123111 } ;
124112 }
125113 query:: Definition :: Operation ( query:: OperationDefinition :: SelectionSet ( _) ) => {
@@ -204,20 +192,9 @@ impl ::std::convert::From<graphql_parser::schema::Document> for Schema {
204192 . or_insert_with ( || vec ! [ name. clone( ) ] ) ;
205193 }
206194
207- schema. objects . insert (
208- obj. name . clone ( ) ,
209- GqlObject {
210- name : obj. name . clone ( ) ,
211- fields : obj
212- . fields
213- . iter ( )
214- . map ( |f| GqlObjectField {
215- name : f. name . clone ( ) ,
216- type_ : FieldType :: from ( f. field_type . clone ( ) ) ,
217- } )
218- . collect ( ) ,
219- } ,
220- ) ;
195+ schema
196+ . objects
197+ . insert ( obj. name . clone ( ) , GqlObject :: from_graphql_parser_object ( obj) ) ;
221198 }
222199 schema:: TypeDefinition :: Enum ( enm) => {
223200 schema. enums . insert (
@@ -337,21 +314,9 @@ impl ::std::convert::From<::introspection_response::IntrospectionResponse> for S
337314 . or_insert_with ( || vec ! [ name. clone( ) ] ) ;
338315 }
339316
340- let fields: Vec < GqlObjectField > = ty
341- . fields
342- . clone ( )
343- . unwrap ( )
344- . into_iter ( )
345- . filter_map ( |t| {
346- t. map ( |t| GqlObjectField {
347- name : t. name . expect ( "field name" ) ,
348- type_ : FieldType :: from ( t. type_ . expect ( "field type" ) ) ,
349- } )
350- } )
351- . collect ( ) ;
352317 schema
353318 . objects
354- . insert ( name. clone ( ) , GqlObject { name , fields } ) ;
319+ . insert ( name. clone ( ) , GqlObject :: from_introspected_schema_json ( ty ) ) ;
355320 }
356321 Some ( __TypeKind:: INTERFACE ) => {
357322 let iface = GqlInterface {
@@ -385,6 +350,7 @@ impl ::std::convert::From<::introspection_response::IntrospectionResponse> for S
385350#[ cfg( test) ]
386351mod tests {
387352 use super :: * ;
353+ use constants:: * ;
388354 use proc_macro2:: { Ident , Span } ;
389355
390356 #[ test]
@@ -397,6 +363,10 @@ mod tests {
397363 Some ( & GqlObject {
398364 name: "Droid" . to_string( ) ,
399365 fields: vec![
366+ GqlObjectField {
367+ name: TYPENAME_FIELD . to_string( ) ,
368+ type_: FieldType :: Named ( string_type( ) ) ,
369+ } ,
400370 GqlObjectField {
401371 name: "id" . to_string( ) ,
402372 type_: FieldType :: Optional ( Box :: new( FieldType :: Named ( Ident :: new(
0 commit comments