Skip to content

Commit

Permalink
setup basic playground server
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanwebster committed Nov 28, 2023
1 parent 1643fa4 commit be1443a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
juniper = "0.15.11"
juniper_warp = "0.7.0"
tokio = { version = "1.34.0", features = ["macros"] }
warp = "0.3.6"
41 changes: 39 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
fn main() {
println!("Hello, world!");
use juniper::graphql_object;
use juniper::EmptyMutation;
use juniper::EmptySubscription;
use juniper::RootNode;
use warp::Filter;

#[derive(Clone)]
struct Context;

impl juniper::Context for Context {}

struct Query;

#[graphql_object(context = Context)]
impl Query {
fn hello() -> &'static str {
"hello world"
}
}

type Schema = RootNode<'static, Query, EmptyMutation<Context>, EmptySubscription<Context>>;

fn schema() -> Schema {
Schema::new(Query, EmptyMutation::new(), EmptySubscription::new())
}

#[tokio::main]
async fn main() {
let routes = (warp::post()
.and(warp::path("graphql"))
.and(juniper_warp::make_graphql_filter(
schema(),
warp::any().map(|| Context).boxed(),
)))
.or(warp::get()
.and(warp::path("playground"))
.and(juniper_warp::playground_filter("/graphql", None)));

warp::serve(routes).run(([127, 0, 0, 1], 8080)).await;
}

0 comments on commit be1443a

Please sign in to comment.