1
0
mirror of https://github.com/actix/examples synced 2024-11-23 14:31:07 +01:00

Update async-graphql-demo for async-graphql v2.0.0 (#378)

This commit is contained in:
Sunli 2020-10-13 15:45:19 +08:00 committed by GitHub
parent 0e9203d319
commit 66d27bbe61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 492 additions and 429 deletions

897
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,8 +6,6 @@ edition = "2018"
[dependencies] [dependencies]
actix-web = "3.0.0" actix-web = "3.0.0"
async-graphql = "2.0.0"
async-graphql = "=2.0.0-alpha.13" async-graphql-actix-web = "2.0.0"
async-graphql-actix-web = "=2.0.0-alpha.13"
slab = "0.4.2" slab = "0.4.2"

View File

@ -3,10 +3,10 @@ mod starwars;
use actix_web::{guard, web, App, HttpResponse, HttpServer, Result}; use actix_web::{guard, web, App, HttpResponse, HttpServer, Result};
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig}; use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::{EmptyMutation, EmptySubscription, Schema}; use async_graphql::{EmptyMutation, EmptySubscription, Schema};
use async_graphql_actix_web::{GQLRequest, GQLResponse}; use async_graphql_actix_web::{Request, Response};
use starwars::{QueryRoot, StarWars, StarWarsSchema}; use starwars::{QueryRoot, StarWars, StarWarsSchema};
async fn index(schema: web::Data<StarWarsSchema>, req: GQLRequest) -> GQLResponse { async fn index(schema: web::Data<StarWarsSchema>, req: Request) -> Response {
schema.execute(req.into_inner()).await.into() schema.execute(req.into_inner()).await.into()
} }

View File

@ -92,7 +92,7 @@ impl QueryRoot {
async fn hero( async fn hero(
&self, &self,
ctx: &Context<'_>, ctx: &Context<'_>,
#[arg( #[graphql(
desc = "If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode." desc = "If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode."
)] )]
episode: Episode, episode: Episode,
@ -107,7 +107,7 @@ impl QueryRoot {
async fn human( async fn human(
&self, &self,
ctx: &Context<'_>, ctx: &Context<'_>,
#[arg(desc = "id of the human")] id: String, #[graphql(desc = "id of the human")] id: String,
) -> Option<Human> { ) -> Option<Human> {
ctx.data_unchecked::<StarWars>().human(&id).map(Human) ctx.data_unchecked::<StarWars>().human(&id).map(Human)
} }
@ -134,7 +134,7 @@ impl QueryRoot {
async fn droid( async fn droid(
&self, &self,
ctx: &Context<'_>, ctx: &Context<'_>,
#[arg(desc = "id of the droid")] id: String, #[graphql(desc = "id of the droid")] id: String,
) -> Option<Droid> { ) -> Option<Droid> {
ctx.data_unchecked::<StarWars>().droid(&id).map(Droid) ctx.data_unchecked::<StarWars>().droid(&id).map(Droid)
} }
@ -161,10 +161,10 @@ impl QueryRoot {
#[derive(Interface)] #[derive(Interface)]
#[graphql( #[graphql(
field(name = "id", type = "&str", context), field(name = "id", type = "&str"),
field(name = "name", type = "&str", context), field(name = "name", type = "&str"),
field(name = "friends", type = "Vec<Character>", context), field(name = "friends", type = "Vec<Character>"),
field(name = "appears_in", type = "&'ctx [Episode]", context) field(name = "appears_in", type = "&'ctx [Episode]")
)] )]
pub enum Character { pub enum Character {
Human(Human), Human(Human),