From 882b9c39641e12c868df3a252580a74c3dfdd3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Fro=C5=82ow?= Date: Sun, 12 Jan 2020 17:14:08 +0100 Subject: [PATCH] Update juniper example (#233) --- juniper/Cargo.toml | 2 +- juniper/src/main.rs | 3 --- juniper/src/schema.rs | 20 ++++++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/juniper/Cargo.toml b/juniper/Cargo.toml index 3dd9829b..5cddd3a9 100644 --- a/juniper/Cargo.toml +++ b/juniper/Cargo.toml @@ -11,4 +11,4 @@ env_logger = "0.7.1" serde = "1.0.103" serde_json = "1.0.44" serde_derive = "1.0.103" -juniper = "0.14.1" +juniper = "0.14.2" diff --git a/juniper/src/main.rs b/juniper/src/main.rs index 1e65e953..fd29faa1 100644 --- a/juniper/src/main.rs +++ b/juniper/src/main.rs @@ -4,9 +4,6 @@ use std::io; use std::sync::Arc; -#[macro_use] -extern crate juniper; - use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer}; use juniper::http::graphiql::graphiql_source; use juniper::http::GraphQLRequest; diff --git a/juniper/src/schema.rs b/juniper/src/schema.rs index 2b4cf304..889ae954 100644 --- a/juniper/src/schema.rs +++ b/juniper/src/schema.rs @@ -8,6 +8,8 @@ enum Episode { Jedi, } +use juniper::{GraphQLEnum, GraphQLInputObject, GraphQLObject}; + #[derive(GraphQLObject)] #[graphql(description = "A humanoid creature in the Star Wars universe")] struct Human { @@ -27,29 +29,31 @@ struct NewHuman { pub struct QueryRoot; -graphql_object!(QueryRoot: () |&self| { - field human(&executor, id: String) -> FieldResult { - Ok(Human{ +#[juniper::object] +impl QueryRoot { + fn human(id: String) -> FieldResult { + Ok(Human { id: "1234".to_owned(), name: "Luke".to_owned(), appears_in: vec![Episode::NewHope], home_planet: "Mars".to_owned(), }) } -}); +} pub struct MutationRoot; -graphql_object!(MutationRoot: () |&self| { - field createHuman(&executor, new_human: NewHuman) -> FieldResult { - Ok(Human{ +#[juniper::object] +impl MutationRoot { + fn createHuman(new_human: NewHuman) -> FieldResult { + Ok(Human { id: "1234".to_owned(), name: new_human.name, appears_in: new_human.appears_in, home_planet: new_human.home_planet, }) } -}); +} pub type Schema = RootNode<'static, QueryRoot, MutationRoot>;