You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
11
11
12
12
- (breaking) Control over which types custom scalars deserialize to is given to the user: you now have to provide type aliases for the custom scalars in the scope of the struct under derive.
13
13
- (breaking) Support for multi-operations documents. You can select a particular operation by naming the struct under derive after it. In case there is no match, we revert to the current behaviour: select the first operation.
14
+
- Support arbitrary derives on the generated response types via the `response_derives` option on the `graphql` attribute.
Copy file name to clipboardExpand all lines: README.md
+28
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,9 @@ A typed GraphQL client library for Rust.
13
13
- Works in the browser (WebAssembly)
14
14
- Subscriptions support (serialization-deserialization only at the moment)
15
15
- Copies documentation from the GraphQL schema to the generated Rust code
16
+
- Arbitrary derives on the generated responses
17
+
- Arbitrary custom scalars
18
+
- Supports multiple operations per query document
16
19
17
20
## Getting started
18
21
@@ -74,6 +77,31 @@ A typed GraphQL client library for Rust.
74
77
75
78
[A complete example using the GitHub GraphQL API is available](https://github.com/tomhoule/graphql-client/tree/master/examples/github), as well as sample [rustdoc output](https://www.tomhoule.com/docs/example_module/).
76
79
80
+
## Deriving specific traits on the response
81
+
82
+
The generated response types always derive `serde::Deserialize` but you may want to print them (`Debug`), compare them (`PartialEq`) or derive any other trait on it. You can achieve this with the `response_derives` option of the `graphql` attribute. Example:
83
+
84
+
```rust
85
+
#[derive(GraphQLQuery)]
86
+
#[graphql(
87
+
schema_path ="src/search_schema.graphql",
88
+
query_path ="src/search_query.graphql"
89
+
query_path ="src/search_query.graphql",
90
+
response_derives ="Serialize,PartialEq",
91
+
)]
92
+
structSearchQuery;
93
+
```
94
+
95
+
## Custom scalars
96
+
97
+
The generated code will reference the scalar types as defined in the server schema. This means you have to provide matching rust types in the scope of the struct under derive. It can be as simple as declarations like `type Email = String;`. This gives you complete freedom on how to treat custom scalars, as long as they can be deserialized.
98
+
99
+
## Query documents with multiple operations
100
+
101
+
You can write multiple operations in one query document (one `.graphql` file). You can then select one by naming the struct you `#[derive(GraphQLQuery)]` on with the same name as one of the operations. This is neat, as it allows sharing fragments between operations.
102
+
103
+
There is an example [in the tests](./tests/operation_selection).
0 commit comments