@@ -8,19 +8,19 @@ use juniper::graphql_object;
88use std:: sync:: { atomic, Arc } ;
99use tide:: { error:: ResultExt , response, App , Context , EndpointResult } ;
1010
11- // First, we define `Data ` that holds accumulator state. This is accessible as App data in
11+ // First, we define `State ` that holds accumulator state. This is accessible as App data in
1212// Tide, and as executor context in Juniper.
1313#[ derive( Clone , Default ) ]
14- struct Data ( Arc < atomic:: AtomicIsize > ) ;
14+ struct State ( Arc < atomic:: AtomicIsize > ) ;
1515
16- impl juniper:: Context for Data { }
16+ impl juniper:: Context for State { }
1717
1818// We define `Query` unit struct here. GraphQL queries will refer to this struct. The struct itself
1919// doesn't have any associated data (and there's no need to do so), but instead it exposes the
2020// accumulator state from the context.
2121struct Query ;
2222
23- graphql_object ! ( Query : Data |& self | {
23+ graphql_object ! ( Query : State |& self | {
2424 // GraphQL integers are signed and 32 bits long.
2525 field accumulator( & executor) -> i32 as "Current value of the accumulator" {
2626 executor. context( ) . 0 . load( atomic:: Ordering :: Relaxed ) as i32
@@ -31,7 +31,7 @@ graphql_object!(Query: Data |&self| {
3131// `Query`, but it provides the way to "mutate" the accumulator state.
3232struct Mutation ;
3333
34- graphql_object ! ( Mutation : Data |& self | {
34+ graphql_object ! ( Mutation : State |& self | {
3535 field add( & executor, by: i32 ) -> i32 as "Add given value to the accumulator." {
3636 executor. context( ) . 0 . fetch_add( by as isize , atomic:: Ordering :: Relaxed ) as i32 + by
3737 }
@@ -43,7 +43,7 @@ type Schema = juniper::RootNode<'static, Query, Mutation>;
4343
4444// Finally, we'll bridge between Tide and Juniper. `GraphQLRequest` from Juniper implements
4545// `Deserialize`, so we use `Json` extractor to deserialize the request body.
46- async fn handle_graphql ( mut cx : Context < Data > ) -> EndpointResult {
46+ async fn handle_graphql ( mut cx : Context < State > ) -> EndpointResult {
4747 let query: juniper:: http:: GraphQLRequest = cx. body_json ( ) . await . client_err ( ) ?;
4848 let schema = Schema :: new ( Query , Mutation ) ;
4949 let response = query. execute ( & schema, cx. state ( ) ) ;
@@ -58,7 +58,7 @@ async fn handle_graphql(mut cx: Context<Data>) -> EndpointResult {
5858}
5959
6060fn main ( ) {
61- let mut app = App :: with_state ( Data :: default ( ) ) ;
61+ let mut app = App :: with_state ( State :: default ( ) ) ;
6262 app. at ( "/graphql" ) . post ( handle_graphql) ;
63- app. serve ( "127.0.0.1:8000" ) . unwrap ( ) ;
63+ app. run ( "127.0.0.1:8000" ) . unwrap ( ) ;
6464}
0 commit comments