1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +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

@ -11,4 +11,4 @@ env_logger = "0.8"
serde = "1.0.103"
serde_json = "1.0.44"
serde_derive = "1.0.103"
juniper = "0.14.2"
juniper = "0.15"

View File

@ -20,6 +20,7 @@ cargo run (or ``cargo watch -x run``)
[http://127.0.0.1:8080/graphiql](http://127.0.0.1:8080/graphiql)
_Query example:_
```graphql
{
human(id: "1234") {
@ -29,7 +30,9 @@ _Query example:_
}
}
```
_Result:_
```json
{
"data": {
@ -58,6 +61,7 @@ mutation {
```
_Result:_
```json
{
"data": {

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())
}