mongo-graphql 0.0.1

Dynamic GraphQL schema generation from MongoDB collections, optimized for AWS Lambda
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use async_graphql::dynamic::Schema;
use async_graphql::{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,
) -> Result<serde_json::Value, GraphQLError> {
    let request = Request::new(query).variables(variables);
    let response = schema.execute(request).await;
    serde_json::to_value(response)
        .map_err(|e| GraphQLError::Internal(format!("Serialization error: {}", e)))
}