@@ -20,7 +20,52 @@ use std::collections::HashMap;
2020
2121/// A convenience trait that can be used to build a GraphQL request body.
2222///
23- /// This will be implemented for you by codegen in the normal case.
23+ /// This will be implemented for you by codegen in the normal case. It is implemented on the struct you place the derive on.
24+ ///
25+ /// Example:
26+ ///
27+ ///
28+ /// ```
29+ /// extern crate failure;
30+ /// #[macro_use]
31+ /// extern crate graphql_client;
32+ /// #[macro_use]
33+ /// extern crate serde_derive;
34+ /// #[macro_use]
35+ /// extern crate serde_json;
36+ /// extern crate serde;
37+ ///
38+ /// #[derive(GraphQLQuery)]
39+ /// #[graphql(
40+ /// query_path = "graphql_query_derive/src/tests/star_wars_query.graphql",
41+ /// schema_path = "graphql_query_derive/src/tests/star_wars_schema.graphql"
42+ /// )]
43+ /// struct StarWarsQuery;
44+ ///
45+ /// fn main() -> Result<(), failure::Error> {
46+ /// use graphql_client::GraphQLQuery;
47+ ///
48+ /// let variables = star_wars_query::Variables {
49+ /// episode_for_hero: star_wars_query::Episode::NEWHOPE,
50+ /// };
51+ ///
52+ /// let expected_body = json!({
53+ /// "query": star_wars_query::QUERY,
54+ /// "variables": {
55+ /// "episodeForHero": "NEWHOPE"
56+ /// },
57+ /// });
58+ ///
59+ /// let actual_body = serde_json::to_value(
60+ /// StarWarsQuery::build_query(variables)
61+ /// )?;
62+ ///
63+ /// assert_eq!(actual_body, expected_body);
64+ ///
65+ /// Ok(())
66+ /// }
67+ /// ```
68+ /// ```
2469pub trait GraphQLQuery < ' de > {
2570 /// The shape of the variables expected by the query. This should be a generated struct most of the time.
2671 type Variables : serde:: Serialize ;
@@ -31,7 +76,7 @@ pub trait GraphQLQuery<'de> {
3176 fn build_query ( variables : Self :: Variables ) -> GraphQLQueryBody < Self :: Variables > ;
3277}
3378
34- /// The form in which queries are sent over HTTP in most implemnetations .
79+ /// The form in which queries are sent over HTTP in most implementations. This will be built using the [`GraphQLQuery`] trait normally .
3580#[ derive( Debug , Serialize , Deserialize ) ]
3681pub struct GraphQLQueryBody < Variables >
3782where
0 commit comments