changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / rust/bin/alik/graphql.rs

changeset 698: 96958d3eb5b0
parent: 1816f9c53453
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 //! alik/graphql.rs --- Alik GraphQL API Service
2 
3 //
4 
5 //! Code:
6 use net::axum::{
7  response::{self, IntoResponse},
8  routing::get,
9  Router,
10 };
11 
12 use net::http::graphql::http::GraphiQLSource;
13 use tokio::net::TcpListener;
14 // use net::http::graphql::http::{EmptyMutation, EmptySubscription, Schema};
15 // use net::http::graphql_axum::GraphQL;
16 
17 pub async fn graphiql() -> impl IntoResponse {
18  response::Html(GraphiQLSource::build().endpoint("/").finish())
19 }
20 
21 pub async fn start_graphiql(addr: &str) {
22  // let schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription)
23  // .data(Vec::new())
24  // .finish();
25 
26  let app = Router::new().route("/", get(graphiql));
27  // .post_service(GraphQL::new(schema)));
28 
29  let listener = TcpListener::bind(addr).await.unwrap();
30  println!(
31  "graphiql running on: http://{}",
32  listener.local_addr().unwrap()
33  );
34  net::axum::serve(TcpListener::bind(addr).await.unwrap(), app)
35  .await
36  .unwrap();
37 }