Skip to content

Commit 5ece0fc

Browse files
committed
Implement the --output option for schema introspection
1 parent a06de43 commit 5ece0fc

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

graphql_client_cli/src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ fn main() -> Result<(), failure::Error> {
6060
fn introspect_schema(location: String, output: Option<PathBuf>) -> Result<(), failure::Error> {
6161
use reqwest::header::*;
6262
use reqwest::mime;
63+
use std::io::Write;
6364

64-
// let dest_file = ::std::fs::File::open(&output)?;
65+
let mut out: Box<Write> = match output {
66+
Some(path) => Box::new(::std::fs::File::create(path)?),
67+
None => Box::new(::std::io::stdout()),
68+
};
6569

6670
let request_body: graphql_client::GraphQLQueryBody<()> = graphql_client::GraphQLQueryBody {
6771
variables: (),
@@ -83,8 +87,9 @@ fn introspect_schema(location: String, output: Option<PathBuf>) -> Result<(), fa
8387
}
8488

8589
let json: graphql_client::GraphQLResponse<introspection_query::ResponseData> = res.json()?;
90+
let json = serde_json::to_string(&json)?;
8691

87-
println!("{:?}", json);
92+
write!(out, "{}", json)?;
8893

8994
Ok(())
9095
}

graphql_query_derive/src/fragments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl GqlFragment {
1919
let fields = object.response_fields_for_selection(context, &self.selection, &self.name);
2020

2121
quote!{
22-
#[derive(Debug, Deserialize)]
22+
#[derive(Debug, Deserialize, Serialize)]
2323
pub struct #name_ident {
2424
#(#fields,)*
2525
}

graphql_query_derive/src/objects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl GqlObject {
3131
Ok(quote! {
3232
#(#field_impls)*
3333

34-
#[derive(Debug, Deserialize)]
34+
#[derive(Debug, Serialize, Deserialize)]
3535
pub struct #name {
3636
#(#fields,)*
3737
}

graphql_query_derive/src/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Schema {
169169

170170
#variables_struct
171171

172-
#[derive(Debug, Deserialize)]
172+
#[derive(Debug, Serialize, Deserialize)]
173173
pub struct ResponseData {
174174
#(#response_data_fields)*,
175175
}

0 commit comments

Comments
 (0)