mongo-graphql 0.0.2

Dynamic GraphQL schema generation from MongoDB collections, optimized for AWS Lambda
Documentation
use async_graphql::dynamic::Schema;
use async_graphql::{Data, Request, Variables};

use crate::error::GraphQLError;

/// Execute a GraphQL query against the built schema and return the JSON result.
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)))
}