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

View file

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