use async_graphql::dynamic::Schema;
use async_graphql::{Data, Request, Variables};
use crate::error::GraphQLError;
pub async fn execute(
schema: &Schema,
query: &str,
variables: Variables,
data: Option<Data>,
) -> Result<serde_json::Value, GraphQLError> {
let mut request = Request::new(query).variables(variables);
if let Some(data) = data {
request.data = data;
}
let response = schema.execute(request).await;
serde_json::to_value(response)
.map_err(|e| GraphQLError::Internal(format!("Serialization error: {}", e)))
}