@@ -55,6 +55,28 @@ impl Schema {
5555 Ok ( ( ) )
5656 } ) . collect ( )
5757 }
58+
59+ pub ( crate ) fn require ( & self , typename_ : & str ) {
60+ DEFAULT_SCALARS . iter ( )
61+ . find ( |& & s| s == typename_)
62+ . map ( |_| ( ) )
63+ . or_else ( || {
64+ self . enums . get ( typename_)
65+ . map ( |enm| enm. is_required . set ( true ) )
66+ } )
67+ . or_else ( || {
68+ self . inputs . get ( typename_)
69+ . map ( |input| input. require ( self ) )
70+ } )
71+ . or_else ( || {
72+ self . objects . get ( typename_)
73+ . map ( |object| object. require ( self ) )
74+ } )
75+ . or_else ( || {
76+ self . scalars . get ( typename_)
77+ . map ( |scalar| scalar. is_required . set ( true ) )
78+ } ) ;
79+ }
5880}
5981
6082impl :: std:: convert:: From < graphql_parser:: schema:: Document > for Schema {
@@ -94,6 +116,7 @@ impl ::std::convert::From<graphql_parser::schema::Document> for Schema {
94116 description : v. description . clone ( ) ,
95117 name : v. name . clone ( ) ,
96118 } ) . collect ( ) ,
119+ is_required : false . into ( ) ,
97120 } ,
98121 ) ;
99122 }
@@ -103,6 +126,7 @@ impl ::std::convert::From<graphql_parser::schema::Document> for Schema {
103126 Scalar {
104127 name : scalar. name ,
105128 description : scalar. description ,
129+ is_required : false . into ( ) ,
106130 } ,
107131 ) ;
108132 }
@@ -113,6 +137,7 @@ impl ::std::convert::From<graphql_parser::schema::Document> for Schema {
113137 GqlUnion {
114138 variants,
115139 description : union. description ,
140+ is_required : false . into ( ) ,
116141 } ,
117142 ) ;
118143 }
@@ -196,6 +221,7 @@ impl ::std::convert::From<::introspection_response::IntrospectionResponse> for S
196221 name : name. clone ( ) ,
197222 description : ty. description . clone ( ) ,
198223 variants,
224+ is_required : false . into ( ) ,
199225 } ;
200226 schema. enums . insert ( name, enm) ;
201227 }
@@ -210,6 +236,7 @@ impl ::std::convert::From<::introspection_response::IntrospectionResponse> for S
210236 Scalar {
211237 name,
212238 description : ty. description . as_ref ( ) . map ( |d| d. clone ( ) ) ,
239+ is_required : false . into ( ) ,
213240 } ,
214241 ) ;
215242 }
@@ -227,6 +254,7 @@ impl ::std::convert::From<::introspection_response::IntrospectionResponse> for S
227254 GqlUnion {
228255 description : ty. description . as_ref ( ) . map ( |d| d. to_owned ( ) ) ,
229256 variants,
257+ is_required : false . into ( ) ,
230258 } ,
231259 ) ;
232260 }
@@ -347,6 +375,7 @@ mod tests {
347375 deprecation: DeprecationStatus :: Current ,
348376 } ,
349377 ] ,
378+ is_required: false . into( ) ,
350379 } )
351380 )
352381 }
0 commit comments