Skip to content

Commit 1b66062

Browse files
authored
Merge pull request #167 from graphql-rust/schema-with-data-field
Make json schemas work both with and without data field
2 parents 091ad53 + cf676ba commit 1b66062

File tree

8 files changed

+1709
-10
lines changed

8 files changed

+1709
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
- Better error messages from the derive macro stwhen the schema or the query file path is not found.
1313

14+
## Fixed
15+
16+
- Support both full introspection responses (with "data") field and just the content of the "data" field in schema.json files.
17+
1418
## 0.5.0
1519

1620
### Added

graphql_client/tests/json_schema.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#[macro_use]
2+
extern crate graphql_client;
3+
#[macro_use]
4+
extern crate serde_derive;
5+
extern crate serde;
6+
#[macro_use]
7+
extern crate serde_json;
8+
9+
type Uuid = String;
10+
11+
#[derive(GraphQLQuery)]
12+
#[graphql(
13+
query_path = "tests/json_schema/query.graphql",
14+
schema_path = "tests/json_schema/schema_1.json",
15+
response_derives = "Debug,PartialEq"
16+
)]
17+
pub struct WithSchema1;
18+
19+
#[derive(GraphQLQuery)]
20+
#[graphql(
21+
query_path = "tests/json_schema/query.graphql",
22+
schema_path = "tests/json_schema/schema_2.json",
23+
response_derives = "Debug"
24+
)]
25+
pub struct WithSchema2;
26+
27+
#[test]
28+
fn json_schemas_work_with_and_without_data_field() {
29+
let response = json!({
30+
"data": {
31+
"currentSession": null,
32+
},
33+
});
34+
35+
let schema_1_result: graphql_client::Response<with_schema1::ResponseData> =
36+
serde_json::from_value(response.clone()).unwrap();
37+
let schema_2_result: graphql_client::Response<with_schema2::ResponseData> =
38+
serde_json::from_value(response).unwrap();
39+
40+
assert_eq!(
41+
format!("{:?}", schema_1_result),
42+
format!("{:?}", schema_2_result)
43+
);
44+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
query CurrentSession {
2+
currentSession {
3+
accountId
4+
}
5+
}

0 commit comments

Comments
 (0)