1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

Update juniper example (#233)

This commit is contained in:
Roman Frołow 2020-01-12 17:14:08 +01:00 committed by Yuki Okushi
parent ebdcdf8130
commit 882b9c3964
3 changed files with 13 additions and 12 deletions

View File

@ -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"

View File

@ -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;

View File

@ -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<Human> {
Ok(Human{
#[juniper::object]
impl QueryRoot {
fn human(id: String) -> FieldResult<Human> {
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<Human> {
Ok(Human{
#[juniper::object]
impl MutationRoot {
fn createHuman(new_human: NewHuman) -> FieldResult<Human> {
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>;