wundergraph 0.1.2

A GraphQL ORM build on top of diesel
Documentation
use super::{BoxedQuery, LoadingHandler};
use crate::context::WundergraphContext;
use crate::error::Result;
use crate::query_builder::selection::offset::ApplyOffset;
use crate::scalar::WundergraphScalarValue;
use diesel::backend::Backend;
use diesel::query_builder::QueryFragment;
use diesel::{Connection, QuerySource};
use juniper::LookAheadSelection;

/// A trait to modify the query generated by the default `LoadingHandler` implementation
///
/// A blanket implementation is provided for using a connection as context, otherwise
/// this trait needs to be implemented for the user defined context.
/// There are two ways to do this:
///  * Provide a blanket implementation for all types implementing `LoadingHandler`.
///    See the default implementation for connection types for an example.
///  * Add a specialized implementation for each type that implements `LoadingHandler`/
///    derives [`#[derive(WundergraphEntity)]`](derive.WundergraphEntity.html).
///    Those types are represented by the generic
///    parameter `L`. This approach allows a fine level of control about the final
///    query to load data from the database. It is possible to cancel a query or add
///    additional query clauses depending on the provided context or the actual graphql
///    request.
pub trait QueryModifier<L, DB>: WundergraphContext + Sized
where
    L: LoadingHandler<DB, Self>,
    DB: Backend + ApplyOffset + 'static,
{
    /// A function that allows you to customize the default `LoadingHandler` implementation.
    /// See the top level documentation of this trait for more details.
    fn modify_query<'a>(
        &self,
        select: &LookAheadSelection<'_, WundergraphScalarValue>,
        query: BoxedQuery<'a, L, DB, Self>,
    ) -> Result<BoxedQuery<'a, L, DB, Self>>;
}

impl<Conn, DB, T> QueryModifier<T, DB> for Conn
where
    T: LoadingHandler<DB, Self>,
    Conn: Connection<Backend = DB> + 'static,
    DB: Backend + ApplyOffset + 'static,
    T::Table: 'static,
    <T::Table as QuerySource>::FromClause: QueryFragment<DB>,
    DB::QueryBuilder: Default,
{
    fn modify_query<'a>(
        &self,
        _select: &LookAheadSelection<'_, WundergraphScalarValue>,
        query: BoxedQuery<'a, T, DB, Self>,
    ) -> Result<BoxedQuery<'a, T, DB, Self>> {
        Ok(query)
    }
}