-
-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Website for exploring router schema. Similar to GraphiQL #23
Comments
This idea is cool! Essentially sort of like a generated docs page for our API. |
I thought so too! I have always loved using GraphQL Playground to explore the data before the frontend has been developed. It is something I can do in rspc because I have all of the types at runtime on the Rust side as required for the rest of the system to work. Something like trpc can't do the same thing because the types do not exist at runtime (in Javascript) although I am sure if they wanted to they could find a way to store them. I have been working on this feature locally and have made some progress but I am not ready to publish it yet. Hopefully, it won't be long until an MVP of the playground is released. |
Was looking into spacedrive and found this repo. I'm in the middle of building an API for personal use, and decided to use Rust as I wanted to learn the language. I have used TRPC before and it was great to see there's an alternative in Rust, too. As for now, I'm playing around with the In axum we could use the let router = rspc::Router::<Ctx>::new()
.config(Config::new().export_ts_bindings("./generated/bindings.ts"))
.query("version", |_, _: ()| env!("CARGO_PKG_VERSION"))
.query("echo", |_, v: String| v)
.query("error", |_, _: ()| {
Err(rspc::Error::new(
rspc::ErrorCode::InternalServerError,
"Something went wrong".into(),
)) as Result<String, rspc::Error>
})
.query("transformMe", |_, _: ()| "Hello, world!".to_string())
.mutation("sendMsg", |_, v: String| {
println!("Client said '{}'", v);
v
})
.build()
.arced();
let cors = CorsLayer::new()
.allow_methods(Any)
.allow_headers(Any)
.allow_origin(Any);
let pool = MySqlPoolOptions::new()
.max_connections(5)
.connect(&env::var("DATABASE_URL")?)
.await
.expect("Failed to connect to database");
let app = axum::Router::new()
.route("/", get(|| async { "Hello 'rspc'!" }))
.route(
"/rspc/:id",
router.clone().axum_handler(|Path(path): Path<String>| {
println!("Client requested operation '{}'", path);
Ctx {}
}),
)
.route("/rspcws", router.axum_ws_handler(|| Ctx {}))
.route("/expenses", get(get_expenses))
.layer(cors)
.layer(Extension(pool)); This above is my code at the moment. |
You can technically use an Axum extractor ( The best solution is to capture the variables into the I will get onto documenting this better because it seems to be something that many people have struggled with. I would give #24 a look as it is someone with the same issue and refer to this example I created for that issue. In Spacedrive we do: tauri::Builder::default()
.plugin(sdcore::rspc::integrations::tauri::plugin(router, {
let node = node.clone();
move || node.get_request_context()
})) And then |
No description provided.
The text was updated successfully, but these errors were encountered: