Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created March 23, 2020 23:47
Show Gist options
  • Save Gozala/7a31a33d3cfbfacec9fa5ff03ecd2e79 to your computer and use it in GitHub Desktop.
Save Gozala/7a31a33d3cfbfacec9fa5ff03ecd2e79 to your computer and use it in GitHub Desktop.
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