Skip to content

Commit 889c49d

Browse files
authored
Merge pull request #49 from tomhoule/cli-whole-schema
(CLI) Write the whole response into schema.json
2 parents 154d0a1 + 966a51c commit 889c49d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

graphql_client_cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn introspect_schema(location: String, output: Option<PathBuf>) -> Result<(), fa
8585
}
8686

8787
let json: graphql_client::GraphQLResponse<introspection_query::ResponseData> = res.json()?;
88-
let json = serde_json::to_string(&json.data.expect("data field"))?;
88+
let json = serde_json::to_string(&json)?;
8989

9090
write!(out, "{}", json)?;
9191

graphql_query_derive/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ fn read_file(
6565
Ok(out)
6666
}
6767

68+
#[derive(Serialize, Deserialize, Debug)]
69+
pub(crate) struct FullResponse<T> {
70+
data: T,
71+
}
72+
6873
fn impl_gql_query(input: &syn::DeriveInput) -> Result<TokenStream, failure::Error> {
6974
let cargo_manifest_dir =
7075
::std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR env variable is defined");
@@ -92,8 +97,8 @@ fn impl_gql_query(input: &syn::DeriveInput) -> Result<TokenStream, failure::Erro
9297
schema::Schema::from(s)
9398
}
9499
"json" => {
95-
let parsed: introspection_response::IntrospectionResponse = ::serde_json::from_str(&schema_string)?;
96-
schema::Schema::from(parsed)
100+
let parsed: FullResponse<introspection_response::IntrospectionResponse> = ::serde_json::from_str(&schema_string)?;
101+
schema::Schema::from(parsed.data)
97102
}
98103
extension => panic!("Unsupported extension for the GraphQL schema: {} (only .json and .graphql are supported)", extension)
99104
};

0 commit comments

Comments
 (0)