Skip to content

Commit f34451f

Browse files
committed
Support fragments in interfaces
1 parent a6c9af4 commit f34451f

File tree

5 files changed

+82
-16
lines changed

5 files changed

+82
-16
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
root = true
22

3-
[*]
3+
[*.rs]
44
end_of_line = lf
55
insert_final_newline = true
66
charset = utf-8

tests/interfaces.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,20 @@ fn interface_not_on_everything_deserialization() {
7979

8080
assert_eq!(response_data.everything.map(|names| names.len()), Some(4));
8181
}
82+
83+
#[derive(GraphQLQuery)]
84+
#[graphql(
85+
query_path = "tests/interfaces/interface_with_fragment_query.graphql",
86+
schema_path = "tests/interfaces/interface_schema.graphql",
87+
response_derives = "Debug",
88+
)]
89+
pub struct InterfaceWithFragmentQuery;
90+
91+
const RESPONSE_FRAGMENT: &'static str =
92+
include_str!("interfaces/interface_with_fragment_response.json");
93+
94+
#[test]
95+
fn fragment_in_interface() {
96+
let response_data: interface_with_fragment_query::ResponseData =
97+
serde_json::from_str(RESPONSE_FRAGMENT).unwrap();
98+
}
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
schema {
2-
query: InterfaceQuery
2+
query: InterfaceQuery
33
}
44

55
interface Named {
6-
name: String!
6+
name: String!
7+
displayName: Boolean!
78
}
89

910
type Person implements Named {
10-
name: String!
11-
birthday: String
11+
name: String!
12+
birthday: String
1213
}
1314

1415
enum Industry {
15-
CHOCOLATE
16-
OTHER
16+
CHOCOLATE
17+
OTHER
1718
}
1819

1920
type Organization implements Named {
20-
name: String
21-
industry: Industry!
22-
createdAt: String
21+
name: String
22+
industry: Industry!
23+
createdAt: String
2324
}
2425

2526
type Dog implements Named {
26-
name: String!
27-
"""
28-
Always returns true
29-
"""
30-
isGoodDog: Boolean!
27+
name: String!
28+
"""
29+
Always returns true
30+
"""
31+
isGoodDog: Boolean!
3132
}
3233

3334
type InterfaceQuery {
34-
everything: [Named!]
35+
everything: [Named!]
3536
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
fragment PublicStatus on Named {
2+
displayName
3+
}
4+
5+
query MyQuery {
6+
everything {
7+
name
8+
__typename
9+
...PublicStatus
10+
... on Dog {
11+
isGoodDog
12+
}
13+
... on Person {
14+
birthday
15+
}
16+
... on Organization {
17+
industry
18+
}
19+
}
20+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"everything": [
3+
{
4+
"__typename": "Person",
5+
"name": "Audrey Lorde",
6+
"displayName": false,
7+
"birthday": "1934-02-18"
8+
},
9+
{
10+
"__typename": "Dog",
11+
"name": "Laïka",
12+
"displayName": true,
13+
"isGoodDog": true
14+
},
15+
{
16+
"__typename": "Organization",
17+
"name": "Mozilla",
18+
"displayName": false,
19+
"industry": "OTHER"
20+
},
21+
{
22+
"__typename": "Dog",
23+
"name": "Norbert",
24+
"displayName": true,
25+
"isGoodDog": true
26+
}
27+
]
28+
}

0 commit comments

Comments
 (0)