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
use crate::{dynamic::FieldValue, Request};

/// GraphQL request for dynamic schema.
pub struct DynamicRequest {
    pub(crate) inner: Request,
    pub(crate) root_value: FieldValue<'static>,
}

/// A trait for [`DynamicRequest`]
pub trait DynamicRequestExt {
    /// Specify the root value for the request
    fn root_value(self, value: FieldValue<'static>) -> DynamicRequest;
}

impl<T: Into<Request>> DynamicRequestExt for T {
    fn root_value(self, value: FieldValue<'static>) -> DynamicRequest {
        DynamicRequest {
            inner: self.into(),
            root_value: value,
        }
    }
}

impl<T: Into<Request>> From<T> for DynamicRequest {
    fn from(req: T) -> Self {
        Self {
            inner: req.into(),
            root_value: FieldValue::NULL,
        }
    }
}