apollo_gateway_rs/planner/
request.rs1use std::collections::HashMap;
2use serde::{Deserialize, Serialize};
3use value::{ConstValue, Variables};
4
5#[derive(Debug)]
6pub struct Request {
7 pub headers: HashMap<String, String>,
8 pub data: RequestData
9}
10
11#[derive(Debug, Serialize, Deserialize)]
12pub struct RequestData {
13 pub query: String,
14 #[serde(rename(deserialize = "operationName"))]
15 pub operation: Option<String>,
16 #[serde(skip_serializing_if = "variables_is_empty", default)]
17 pub variables: Variables,
18}
19
20impl RequestData {
21 pub fn new(query: impl Into<String>) -> Self {
22 Self {
23 query: query.into(),
24 operation: None,
25 variables: Default::default(),
26 }
27 }
28
29 pub fn operation(self, operation: impl Into<String>) -> Self {
30 Self {
31 operation: Some(operation.into()),
32 ..self
33 }
34 }
35
36 pub fn variables(self, variables: Variables) -> Self {
37 Self { variables, ..self }
38 }
39
40 pub fn extend_variables(mut self, variables: Variables) -> Self {
41 if let ConstValue::Object(obj) = variables.into_value() {
42 self.variables.extend(obj);
43 }
44 self
45 }
46}
47
48#[inline]
49fn variables_is_empty(variables: &Variables) -> bool {
50 variables.is_empty()
51}