11use crate :: error:: Error ;
22use crate :: CliResult ;
3- use graphql_client:: GraphQLQuery ;
3+ use graphql_client:: { GraphQLQuery , QueryBody } ;
44use reqwest:: header:: { HeaderMap , HeaderValue , ACCEPT , CONTENT_TYPE } ;
5+ use serde_json:: json;
6+ use std:: fmt;
57use std:: path:: PathBuf ;
68use std:: str:: FromStr ;
79
10+ use clap:: ValueEnum ;
11+ use introspection_query:: Variables ;
12+
813#[ derive( GraphQLQuery ) ]
914#[ graphql(
1015 schema_path = "src/graphql/introspection_schema.graphql" ,
@@ -21,6 +26,7 @@ pub fn introspect_schema(
2126 authorization : Option < String > ,
2227 headers : Vec < Header > ,
2328 no_ssl : bool ,
29+ options : Option < Vec < IntrospectionOptions > > ,
2430) -> CliResult < ( ) > {
2531 use std:: io:: Write ;
2632
@@ -29,11 +35,8 @@ pub fn introspect_schema(
2935 None => Box :: new ( std:: io:: stdout ( ) ) ,
3036 } ;
3137
32- let request_body: graphql_client:: QueryBody < ( ) > = graphql_client:: QueryBody {
33- variables : ( ) ,
34- query : introspection_query:: QUERY ,
35- operation_name : introspection_query:: OPERATION_NAME ,
36- } ;
38+ let request_body: QueryBody < introspection_query:: Variables > =
39+ IntrospectionQuery :: build_query ( construct_options ( options) ) ;
3740
3841 let client = reqwest:: blocking:: Client :: builder ( )
3942 . danger_accept_invalid_certs ( no_ssl)
@@ -126,6 +129,41 @@ impl FromStr for Header {
126129 }
127130}
128131
132+ #[ derive( ValueEnum , Clone , Debug , PartialEq ) ]
133+ pub enum IntrospectionOptions {
134+ /// Enable the @oneOf directive in the introspection query.
135+ IsOneOf ,
136+ /// SpecifiedBy is is used within the type system definition language to
137+ /// provide a scalar specification URL for specifying the behavior of custom scalar types.
138+ SpecifiedBy ,
139+ }
140+
141+ fn construct_options ( options : Option < Vec < IntrospectionOptions > > ) -> introspection_query:: Variables {
142+ match options {
143+ Some ( opts) => introspection_query:: Variables {
144+ is_one_of : opts. contains ( & IntrospectionOptions :: IsOneOf ) ,
145+ } ,
146+ None => introspection_query:: Variables { is_one_of : false } ,
147+ }
148+ }
149+
150+ impl FromStr for IntrospectionOptions {
151+ type Err = String ;
152+
153+ fn from_str ( input : & str ) -> Result < Self , Self :: Err > {
154+ match input. to_lowercase ( ) . as_str ( ) {
155+ "isoneof" => Ok ( IntrospectionOptions :: IsOneOf ) ,
156+ _ => Err ( format ! ( "unknown option {:?}" , input) ) ,
157+ }
158+ }
159+ }
160+
161+ impl fmt:: Debug for Variables {
162+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
163+ write ! ( f, "{}" , json!( self ) )
164+ }
165+ }
166+
129167#[ cfg( test) ]
130168mod tests {
131169 use super :: * ;
0 commit comments