thegraph_graphql_http/
compat.rs1#[cfg(feature = "graphql-parser")]
4pub mod compat_graphql_parser {
5 use graphql_parser::query::Text;
6
7 use crate::graphql::{Document, IntoDocument};
8
9 impl<'a, T: Text<'a>> IntoDocument for graphql_parser::query::Document<'a, T> {
15 fn into_document(self) -> Document {
16 Document::new(self.to_string())
17 }
18 }
19}
20
21#[cfg(feature = "graphql-client")]
22pub mod compat_graphql_client {
23 use graphql_client::QueryBody;
24
25 use crate::{
26 graphql::IntoDocument,
27 http::request::{IntoRequestParameters, RequestParameters},
28 };
29
30 impl<V> IntoRequestParameters for QueryBody<V>
33 where
34 V: serde::ser::Serialize,
35 {
36 fn into_request_parameters(self) -> RequestParameters {
37 let query = self.query.into_document();
38
39 let operation_name = if !self.operation_name.is_empty() {
41 Some(self.operation_name.to_owned())
42 } else {
43 None
44 };
45
46 let variables = match serde_json::to_value(self.variables) {
49 Ok(serde_json::Value::Object(vars)) => Some(vars),
50 _ => None,
51 };
52
53 RequestParameters {
54 query,
55 operation_name,
56 variables: variables.unwrap_or_default(),
57 extensions: Default::default(),
58 }
59 }
60 }
61}
62
63#[cfg(feature = "async-graphql")]
64pub mod compat_async_graphql {
65 use async_graphql::Request;
66
67 use crate::{
68 graphql::IntoDocument,
69 http::request::{IntoRequestParameters, RequestParameters},
70 };
71
72 impl IntoRequestParameters for Request {
75 fn into_request_parameters(self) -> RequestParameters {
76 let query = self.query.into_document();
77
78 let variables = match serde_json::to_value(self.variables) {
82 Ok(serde_json::Value::Object(vars)) => vars,
83 _ => Default::default(),
84 };
85
86 let extensions = match serde_json::to_value(self.extensions) {
87 Ok(serde_json::Value::Object(vars)) => vars,
88 _ => Default::default(),
89 };
90
91 RequestParameters {
92 query,
93 operation_name: self.operation_name,
94 variables,
95 extensions,
96 }
97 }
98 }
99}