web: add non-functional graphql.
This commit is contained in:
35
web/src/graphql.rs
Normal file
35
web/src/graphql.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use graphql_client::GraphQLQuery;
|
||||
use seed::{
|
||||
fetch,
|
||||
fetch::{Header, Method, Request},
|
||||
};
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
|
||||
// The paths are relative to the directory where your `Cargo.toml` is located.
|
||||
// Both json and the GraphQL schema language are supported as sources for the schema
|
||||
#[derive(GraphQLQuery)]
|
||||
#[graphql(
|
||||
schema_path = "graphql/schema.json",
|
||||
query_path = "graphql/front_page.graphql",
|
||||
response_derives = "Debug"
|
||||
)]
|
||||
pub struct FrontPageQuery;
|
||||
|
||||
async fn send_graphql<Body, Resp>(body: Body) -> fetch::Result<graphql_client::Response<Resp>>
|
||||
where
|
||||
Body: Serialize,
|
||||
Resp: DeserializeOwned + 'static,
|
||||
{
|
||||
use web_sys::RequestMode;
|
||||
|
||||
Request::new("/graphql")
|
||||
.method(Method::Post)
|
||||
.header(Header::content_type("application/json"))
|
||||
.mode(RequestMode::Cors)
|
||||
.json(&body)?
|
||||
.fetch()
|
||||
.await?
|
||||
.check_status()?
|
||||
.json()
|
||||
.await
|
||||
}
|
||||
Reference in New Issue
Block a user