1
0
mirror of https://github.com/actix/examples synced 2025-06-27 09:29:02 +02:00

Upgrade juniper to 0.15 (#423)

This commit is contained in:
Yuki Okushi
2021-04-26 20:32:32 +09:00
committed by GitHub
parent ef13969220
commit bb4f97ba41
11 changed files with 137 additions and 50 deletions

View File

@ -14,7 +14,7 @@ mod schema;
use crate::schema::{create_schema, Schema};
async fn graphiql() -> HttpResponse {
let html = graphiql_source("http://127.0.0.1:8080/graphql");
let html = graphiql_source("http://127.0.0.1:8080/graphql", None);
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(html)
@ -25,7 +25,7 @@ async fn graphql(
data: web::Json<GraphQLRequest>,
) -> Result<HttpResponse, Error> {
let user = web::block(move || {
let res = data.execute(&st, &());
let res = data.execute_sync(&st, &());
Ok::<_, serde_json::error::Error>(serde_json::to_string(&res)?)
})
.await?;

View File

@ -1,5 +1,5 @@
use juniper::FieldResult;
use juniper::RootNode;
use juniper::{EmptySubscription, RootNode};
#[derive(GraphQLEnum)]
enum Episode {
@ -29,9 +29,9 @@ struct NewHuman {
pub struct QueryRoot;
#[juniper::object]
#[juniper::graphql_object]
impl QueryRoot {
fn human(id: String) -> FieldResult<Human> {
fn human(_id: String) -> FieldResult<Human> {
Ok(Human {
id: "1234".to_owned(),
name: "Luke".to_owned(),
@ -43,7 +43,7 @@ impl QueryRoot {
pub struct MutationRoot;
#[juniper::object]
#[juniper::graphql_object]
impl MutationRoot {
fn create_human(new_human: NewHuman) -> FieldResult<Human> {
Ok(Human {
@ -55,8 +55,8 @@ impl MutationRoot {
}
}
pub type Schema = RootNode<'static, QueryRoot, MutationRoot>;
pub type Schema = RootNode<'static, QueryRoot, MutationRoot, EmptySubscription>;
pub fn create_schema() -> Schema {
Schema::new(QueryRoot {}, MutationRoot {})
Schema::new(QueryRoot {}, MutationRoot {}, EmptySubscription::new())
}