use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize)]
pub struct GraphQLRequest {
pub query: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub variables: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub operation_name: Option<String>,
}
impl GraphQLRequest {
pub fn new(query: impl Into<String>) -> Self {
Self {
query: query.into(),
variables: None,
operation_name: None,
}
}
pub fn with_variables(mut self, variables: serde_json::Value) -> Self {
self.variables = Some(variables);
self
}
pub fn with_operation_name(mut self, name: impl Into<String>) -> Self {
self.operation_name = Some(name.into());
self
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct GraphQLResponse<T> {
pub data: Option<T>,
pub errors: Option<Vec<GraphQLError>>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct GraphQLError {
pub message: String,
pub locations: Option<Vec<ErrorLocation>>,
pub path: Option<Vec<serde_json::Value>>,
pub extensions: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ErrorLocation {
pub line: u32,
pub column: u32,
}