-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from geofmureithi/chore/v0.1.0-beta
v0.1.0 beta
- Loading branch information
Showing
18 changed files
with
355 additions
and
164 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
[build] | ||
target = "index.html" | ||
dist = "dist" | ||
dist = "dist" | ||
|
||
[[proxy]] | ||
rewrite = "/api/v1/graphql" | ||
backend = "http://localhost:3001/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use gloo_net::http::Request; | ||
use serde::{Deserialize, Serialize}; | ||
#[derive(Serialize)] | ||
struct GraphQLQuery { | ||
query: String, | ||
variables: Variables, | ||
} | ||
|
||
#[derive(Serialize)] | ||
struct Variables { | ||
path: String, | ||
renderer: Option<String>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct GraphQLResponse<T> { | ||
data: T, | ||
errors: Option<Vec<GraphQLError>>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct GraphQLError { | ||
message: String, | ||
// other fields... | ||
} | ||
|
||
#[derive(Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct RenderFileResponse { | ||
pub render_file: String, | ||
} | ||
|
||
pub async fn render_file( | ||
path: String, | ||
renderer: Option<String>, | ||
) -> Result<RenderFileResponse, String> { | ||
let query = GraphQLQuery { | ||
query: "query RenderFile($path: String!, $renderer: String) { renderFile(path: $path, renderer: $renderer) }".to_string(), | ||
variables: Variables { path, renderer }, | ||
}; | ||
let response = Request::post("/api/v1/graphql") | ||
.json(&query) | ||
.expect("Failed to build request") | ||
.send() | ||
.await | ||
.map_err(|err| err.to_string())?; | ||
|
||
if !response.ok() { | ||
return Err("Network error".to_string()); | ||
} | ||
|
||
let response_body: GraphQLResponse<RenderFileResponse> = | ||
response.json().await.map_err(|err| err.to_string())?; | ||
|
||
if let Some(errors) = response_body.errors { | ||
return Err(errors[0].message.clone()); | ||
} | ||
|
||
Ok(response_body.data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.