fix response typing on graphqlclient trait

This commit is contained in:
Tyler Beckman 2024-10-16 01:44:57 -06:00
parent b0e785a2fc
commit 7fda8a97c3
Signed by: Ty
GPG key ID: 2813440C772555A4
2 changed files with 7 additions and 13 deletions

View file

@ -1,6 +1,5 @@
use anyhow::Context as _; use anyhow::Context as _;
use graphql_client::GraphQLQuery; use graphql_client::GraphQLQuery;
use serde::Deserialize;
pub mod create_submission; pub mod create_submission;
pub mod get_course_assignments; pub mod get_course_assignments;
@ -8,11 +7,8 @@ pub mod get_courses;
const CANVAS_GRAPHQL_URL: &str = "https://elearning.mines.edu/api/graphql"; const CANVAS_GRAPHQL_URL: &str = "https://elearning.mines.edu/api/graphql";
#[derive(Deserialize, Debug)] /// A trait that allows .send_query to be used on HTTP Clients (only implemented
pub struct GraphQLResponse<T: GraphQLQuery> { /// for reqwest because thats whats used here and this isn't a library)
pub data: T::ResponseData
}
pub trait GraphQLClient { pub trait GraphQLClient {
/// Sends a GraphQL query using this HTTP Client. The query is /// Sends a GraphQL query using this HTTP Client. The query is
/// specified using generics, which can be explicitly specified /// specified using generics, which can be explicitly specified
@ -20,18 +16,17 @@ pub trait GraphQLClient {
async fn send_query<T: GraphQLQuery>( async fn send_query<T: GraphQLQuery>(
&self, &self,
variables: T::Variables, variables: T::Variables,
authorization: &str authorization: &str,
) -> anyhow::Result<GraphQLResponse<T>>; ) -> anyhow::Result<graphql_client::Response<T::ResponseData>>;
} }
impl GraphQLClient for reqwest::Client { impl GraphQLClient for reqwest::Client {
async fn send_query<T: GraphQLQuery>( async fn send_query<T: GraphQLQuery>(
&self, &self,
variables: T::Variables, variables: T::Variables,
token: &str token: &str,
) -> anyhow::Result<GraphQLResponse<T>> { ) -> anyhow::Result<graphql_client::Response<T::ResponseData>> {
self self.post(CANVAS_GRAPHQL_URL)
.post(CANVAS_GRAPHQL_URL)
.bearer_auth(token) .bearer_auth(token)
.json(&T::build_query(variables)) .json(&T::build_query(variables))
.send() .send()

View file

@ -5,7 +5,6 @@ use graphql::{
GraphQLClient as _, GraphQLClient as _,
}; };
use graphql_client::GraphQLQuery;
use types::user::CanvasUser; use types::user::CanvasUser;
mod command; mod command;