Skip to content

Commit

Permalink
feat: add hello-world graphql server implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Oct 30, 2023
1 parent 711d610 commit c246b85
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 3 deletions.
87 changes: 87 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion core/api-keys/BUCK
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
rust_binary(
name = "main",
name = "api-keys",
srcs = glob(["src/**/*.rs"]),
crate_root = "src/main.rs",
edition = "2021",
)

rust_binary(
name = "write-sdl",
srcs = glob(["src/**/*.rs"]),
crate_root = "src/bin/write_sdl.rs",
edition = "2021",
)
2 changes: 2 additions & 0 deletions core/api-keys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ path = "src/bin/write_sdl.rs"
[dependencies]
async-graphql = { workspace = true }
async-graphql-axum = { workspace = true }
axum = "0.6.20"
tokio = { version = "1.33.0", features = ["full"] }
50 changes: 48 additions & 2 deletions core/api-keys/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
fn main() {
println!("Hello, world!");
use async_graphql::{EmptyMutation, EmptySubscription, Object, Schema};
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
use axum::{routing::get, Extension, Router};

#[tokio::main]
async fn main() {
// Create a GraphQL schema with a simple query
let schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription).finish();

// Create an axum router
let app = Router::new()
.route(
"/graphql",
get(playground).post(axum::routing::post(graphql_handler)),
)
.layer(Extension(schema));

// Run the server
axum::Server::bind(&"0.0.0.0:8000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}

// GraphQL handler
async fn graphql_handler(
schema: Extension<Schema<QueryRoot, EmptyMutation, EmptySubscription>>,
req: GraphQLRequest,
) -> GraphQLResponse {
schema.execute(req.into_inner()).await.into()
}

// Playground handler
async fn playground() -> impl axum::response::IntoResponse {
axum::response::Html(async_graphql::http::playground_source(
async_graphql::http::GraphQLPlaygroundConfig::new("/graphql"),
))
}

// Define a simple query object
#[derive(Default)]
struct QueryRoot;

#[Object]
impl QueryRoot {
async fn hello_world(&self) -> &str {
"Hello, world!"
}
}
21 changes: 21 additions & 0 deletions dev/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@ local_resource(
]
)

def _buck2_dep_inputs(target):
cmd = [
"buck2",
"uquery",
"\"inputs(deps('{}'))\"".format(target),
]
file_paths = str(local(" ".join(cmd))).splitlines()

return file_paths

api_keys_target = "//core/api-keys:api-keys"
# if is_ci:
# consent_target = "//core/api-keys:main"
local_resource(
"api_keys",
labels = ["core"],
cmd = "buck2 build {}".format(api_keys_target),
serve_cmd = "buck2 run {}".format(api_keys_target),
deps = _buck2_dep_inputs(api_keys_target),
)

docker_compose("./docker-compose.deps.yml", project_name = "galoy-dev")

for service in groups["bitcoin"]:
Expand Down

0 comments on commit c246b85

Please sign in to comment.