-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22c7cd6
commit 1908a7a
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use anyhow::{anyhow, Result}; | ||
use graphql_client::reqwest::post_graphql; | ||
use graphql_client::GraphQLQuery; | ||
use pxid::Pxid; | ||
|
||
use post_create::{ | ||
PostCreateInput, PostCreatePostCreateError, PostCreatePostCreatePost, Variables, | ||
}; | ||
|
||
use crate::{DateTime, GRAPHQL_PATH}; | ||
|
||
use super::PostClient; | ||
|
||
#[derive(GraphQLQuery)] | ||
#[graphql( | ||
response_derives = "Clone,Debug,Deserialize", | ||
schema_path = "schema.json", | ||
query_path = "src/modules/post/post_create/PostCreate.gql" | ||
)] | ||
pub struct PostCreate { | ||
pub post: Option<PostCreatePostCreatePost>, | ||
pub error: Option<PostCreatePostCreateError>, | ||
} | ||
|
||
pub async fn posts(public_client: &PostClient, input: PostCreateInput) -> Result<PostCreate> { | ||
let url = public_client.domain.join(GRAPHQL_PATH)?; | ||
let variables = Variables { input }; | ||
|
||
let res = post_graphql::<PostCreate, _>(&public_client.client, url, variables) | ||
.await | ||
.map_err(|err| anyhow!("Failed to create post. {err}"))?; | ||
let data = res.data.unwrap().post_create; | ||
|
||
Ok(PostCreate { | ||
post: data.post, | ||
error: data.error, | ||
}) | ||
} |