Last active
May 21, 2021 19:13
-
-
Save oscartbeaumont/a5bf6374ce4d81a572a521def66d59c4 to your computer and use it in GitHub Desktop.
async-graphql Renaming Fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "async-graphql-issue" | |
version = "0.1.0" | |
authors = ["Oscar Beaumont <[email protected]>"] | |
edition = "2018" | |
[dependencies] | |
async-graphql = "2.8.5" | |
tokio = { version = "0.2.22", features = ["full"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use async_graphql::{EmptyMutation, EmptySubscription, Object, SimpleObject}; | |
#[derive(SimpleObject)] | |
#[graphql(rename_fields = "camelCase")] | |
pub struct User { | |
pub id: String, | |
pub first_name: String, | |
} | |
pub type Schema = async_graphql::Schema<QueryRoot, EmptyMutation, EmptySubscription>; | |
pub struct QueryRoot; | |
#[Object] | |
impl QueryRoot { | |
async fn user(&self) -> User { | |
User { | |
id: "92ba0c2d-4b4e-4e29-91dd-8f96a078c3ff".to_string(), | |
first_name: "Oscar".to_string(), | |
} | |
} | |
} | |
#[tokio::main] | |
async fn main() { | |
let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription); | |
let query = "{ user { id, firstName } }"; | |
let result = schema.execute(query).await; | |
println!("{}", result.data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment