1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::{Env, Expressionista, IrSerializer, QueryGraph, QueryInterpreter, ResponseData};
use schema::QuerySchema;
use tracing::Instrument;

#[derive(Debug)]
pub(crate) struct QueryPipeline<'conn, 'schema> {
    graph: QueryGraph,
    interpreter: QueryInterpreter<'conn>,
    serializer: IrSerializer<'schema>,
}

impl<'conn, 'schema> QueryPipeline<'conn, 'schema> {
    pub(crate) fn new(
        graph: QueryGraph,
        interpreter: QueryInterpreter<'conn>,
        serializer: IrSerializer<'schema>,
    ) -> Self {
        Self {
            graph,
            interpreter,
            serializer,
        }
    }

    pub(crate) async fn execute(
        mut self,
        query_schema: &'schema QuerySchema,
        trace_id: Option<String>,
    ) -> crate::Result<ResponseData> {
        let serializer = self.serializer;
        let expr = Expressionista::translate(self.graph)?;

        let span = info_span!("prisma:engine:interpret");

        let result = self
            .interpreter
            .interpret(expr, Env::default(), 0, trace_id)
            .instrument(span)
            .await;

        trace!("{}", self.interpreter.log_output());
        serializer.serialize(result?, query_schema)
    }
}