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:
parent
ebdcdf8130
commit
882b9c3964
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user