@@ -15,6 +15,106 @@ use crate::{
15
15
signal:: SignalHandler ,
16
16
} ;
17
17
18
+ const SCHEMA_QUERY : & str = "query IntrospectionQuery {
19
+ __schema {
20
+ queryType {
21
+ name
22
+ }
23
+ mutationType {
24
+ name
25
+ }
26
+ subscriptionType {
27
+ name
28
+ }
29
+ types {
30
+ ...FullType
31
+ }
32
+ directives {
33
+ name
34
+ description
35
+ locations
36
+ args {
37
+ ...InputValue
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ fragment FullType on __Type {
44
+ kind
45
+ name
46
+ description
47
+ fields(includeDeprecated: true) {
48
+ name
49
+ description
50
+ args {
51
+ ...InputValue
52
+ }
53
+ type {
54
+ ...TypeRef
55
+ }
56
+ isDeprecated
57
+ deprecationReason
58
+ }
59
+ inputFields {
60
+ ...InputValue
61
+ }
62
+ interfaces {
63
+ ...TypeRef
64
+ }
65
+ enumValues(includeDeprecated: true) {
66
+ name
67
+ description
68
+ isDeprecated
69
+ deprecationReason
70
+ }
71
+ possibleTypes {
72
+ ...TypeRef
73
+ }
74
+ }
75
+
76
+ fragment InputValue on __InputValue {
77
+ name
78
+ description
79
+ type {
80
+ ...TypeRef
81
+ }
82
+ defaultValue
83
+ }
84
+
85
+ fragment TypeRef on __Type {
86
+ kind
87
+ name
88
+ ofType {
89
+ kind
90
+ name
91
+ ofType {
92
+ kind
93
+ name
94
+ ofType {
95
+ kind
96
+ name
97
+ ofType {
98
+ kind
99
+ name
100
+ ofType {
101
+ kind
102
+ name
103
+ ofType {
104
+ kind
105
+ name
106
+ ofType {
107
+ kind
108
+ name
109
+ }
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }" ;
117
+
18
118
#[ derive( Debug , Diagnostic , Error ) ]
19
119
#[ error( "{message}" ) ]
20
120
struct QueryError {
@@ -59,6 +159,7 @@ pub async fn run(
59
159
telemetry : CommandEventBuilder ,
60
160
query : Option < String > ,
61
161
variables_path : Option < & Utf8Path > ,
162
+ include_schema : bool ,
62
163
) -> Result < i32 , Error > {
63
164
let signal = get_signal ( ) ?;
64
165
let handler = SignalHandler :: new ( signal) ;
@@ -67,7 +168,7 @@ pub async fn run(
67
168
. add_all_tasks ( )
68
169
. do_not_validate_engine ( ) ;
69
170
let run = run_builder. build ( & handler, telemetry) . await ?;
70
-
171
+ let query = query . as_deref ( ) . or ( include_schema . then_some ( SCHEMA_QUERY ) ) ;
71
172
if let Some ( query) = query {
72
173
let trimmed_query = query. trim ( ) ;
73
174
// If the arg starts with "query" or "mutation", and ends in a bracket, it's
@@ -80,7 +181,7 @@ pub async fn run(
80
181
{
81
182
query
82
183
} else {
83
- fs:: read_to_string ( AbsoluteSystemPathBuf :: from_unknown ( run. repo_root ( ) , query) ) ?
184
+ & fs:: read_to_string ( AbsoluteSystemPathBuf :: from_unknown ( run. repo_root ( ) , query) ) ?
84
185
} ;
85
186
86
187
let schema = Schema :: new (
@@ -98,13 +199,13 @@ pub async fn run(
98
199
. transpose ( ) ?
99
200
. unwrap_or_default ( ) ;
100
201
101
- let request = Request :: new ( & query) . variables ( variables) ;
202
+ let request = Request :: new ( query) . variables ( variables) ;
102
203
103
204
let result = schema. execute ( request) . await ;
104
205
println ! ( "{}" , serde_json:: to_string_pretty( & result) ?) ;
105
206
if !result. errors . is_empty ( ) {
106
207
for error in result. errors {
107
- let error = QueryError :: new ( error, query. clone ( ) ) ;
208
+ let error = QueryError :: new ( error, query. to_string ( ) ) ;
108
209
eprintln ! ( "{:?}" , Report :: new( error) ) ;
109
210
}
110
211
}
0 commit comments