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: README.md
+16-11Lines changed: 16 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ A typed GraphQL client library for Rust.
29
29
30
30
- In order to provide precise types for a response, graphql_client needs to read the query and the schema at compile-time.
31
31
32
-
To download the schema, you have multiple options. This projects provides a [CLI](https://github.com/graphql-rust/graphql-client/tree/master/graphql_client_cli), but there are also more mature tools like [apollo-cli](https://github.com/apollographql/apollo-cli). It does not matter which one you use, the resulting `schema.json` is the same.
32
+
To download the schema, you have multiple options. This projects provides a [CLI](https://github.com/graphql-rust/graphql-client/tree/master/graphql_client_cli), however it does not matter what tool you use, the resulting `schema.json` is the same.
33
33
34
34
- We now have everything we need to derive Rust types for our query. This is achieved through a procedural macro, as in the following snippet:
35
35
@@ -47,10 +47,10 @@ A typed GraphQL client library for Rust.
let request_body = MyQuery::build_query(variables);
82
+
let request_body = UnionQuery::build_query(variables);
83
83
84
84
let client = reqwest::Client::new();
85
85
let mut res = client.post("/graphql").json(&request_body).send()?;
86
-
let response_body: Response<my_query::ResponseData> = res.json()?;
86
+
let response_body: Response<union_query::ResponseData> = res.json()?;
87
87
println!("{:#?}", response_body);
88
88
Ok(())
89
89
}
@@ -105,7 +105,7 @@ extern crate graphql_client;
105
105
query_path = "tests/unions/union_query.graphql",
106
106
response_derives = "Serialize,PartialEq",
107
107
)]
108
-
struct SearchQuery;
108
+
struct UnionQuery;
109
109
```
110
110
111
111
## Custom scalars
@@ -127,7 +127,7 @@ extern crate graphql_client;
127
127
query_path = "tests/unions/union_query.graphql",
128
128
deprecated = "warn"
129
129
)]
130
-
pub struct MyQuery;
130
+
pub struct UnionQuery;
131
131
```
132
132
133
133
Valid values are:
@@ -143,15 +143,20 @@ The default is `warn`.
143
143
144
144
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.
145
145
146
-
If you want to name the struct different from query name, you can use ``selected_operation`` argument like this.
146
+
Note that the struct and the operation in the GraphQL file *must* have the same name. We enforce this to make the generated code more predictable.
0 commit comments