This file contains 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_std::task; | |
use juniper::{EmptyMutation, RootNode}; | |
struct Concrete; | |
enum CustomName { | |
Concrete(Concrete), | |
} | |
#[juniper::graphql_object] | |
impl Concrete { | |
fn simple() -> i32 { | |
123 | |
} | |
} | |
#[juniper::graphql_union(name = "ACustomNamedUnion")] | |
impl CustomName { | |
fn resolve(&self) { | |
match self { | |
Concrete => match *self { | |
CustomName::Concrete(ref c) => Some(c), | |
}, | |
} | |
} | |
} | |
struct Query; | |
#[juniper::graphql_object(Context = State)] | |
impl Query { | |
fn custom_name() -> CustomName { | |
CustomName::Concrete(Concrete) | |
} | |
} | |
struct State {} | |
type Schema = RootNode<'static, Query, EmptyMutation<State>>; | |
fn schema() -> Schema { | |
Schema::new(Query, EmptyMutation::<State>::new()) | |
} | |
#[async_std::main] | |
async fn main() -> std::io::Result<()> { | |
let ctx = State {}; | |
// Run the executor. | |
let (res, _errors) = juniper::execute_async( | |
"query { favoriteEpisode }", | |
None, | |
&Schema::new(Query, EmptyMutation::new()), | |
&juniper::Variables::new(), | |
&ctx, | |
) | |
.await | |
.unwrap(); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment