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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//! Standardized GraphQL network payload and transport models compliant with the GraphQL over HTTP specification.
//!
//! Provides strongly typed representations for:
//! * Outbound POST JSON request envelopes ([`GraphQLPayload`]).
//! * Universal execution responses ([`GraphQLResponse<T>`]).
//! * Standardized server-side execution diagnostics ([`GraphQLError`]).
//! * Source document error coordinates ([`GraphQLLocation`]).
//!
//! ### Specification Compliance
//!
//! These models strictly adhere to the official [GraphQL over HTTP specification](https://github.com/graphql/graphql-over-http),
//! ensuring seamless interoperability with any standard GraphQL server (Apollo, GraphQL Ruby, Hasura, etc.).
//!
//! ### Quick Example
//!
//! ```rust
//! use moongraphql_builder::payload::{GraphQLPayload, GraphQLResponse};
//! use serde::Deserialize;
//!
//! #[derive(Debug, Deserialize, PartialEq)]
//! struct UserData {
//! id: u32,
//! name: String,
//! }
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // 1. Construct outbound payload
//! let payload = GraphQLPayload {
//! operation_name: Some("GetUser".to_string()),
//! query: "query GetUser { user(id: 1) { id name } }".to_string(),
//! variables: None,
//! };
//!
//! // 2. Deserialize response envelope
//! let raw_json = r#"{"data": {"id": 1, "name": "Dina"}}"#;
//! let response: GraphQLResponse<UserData> = serde_json::from_str(raw_json)?;
//!
//! assert_eq!(response.data, Some(UserData { id: 1, name: "Dina".to_string() }));
//! println!("Parsed GraphQL data successfully!");
//! # Ok(())
//! # }
//! ```
use ;
/// Line and column position of a syntax or validation error within the GraphQL document source.
///
/// Coordinates follow the 1-indexed convention established by the GraphQL specification.
/// Standardized server-side GraphQL execution error descriptor.
///
/// Follows the official GraphQL specification, detailing human-readable diagnostics,
/// source locations in the document AST, and JSON path coordinates to the offending field.
///
/// # Example
///
/// ```rust
/// use moongraphql_builder::payload::GraphQLError;
///
/// let raw_error = r#"{
/// "message": "Field 'age' is not defined by type 'User'",
/// "locations": [{"line": 1, "column": 15}]
/// }"#;
///
/// let error: GraphQLError = serde_json::from_str(raw_error).unwrap();
/// println!("GraphQL Error: {} at line {:?}", error.message, error.locations);
/// ```
/// Universal response envelope returned by standard GraphQL endpoints.
///
/// Represents both successful responses, partial executions (where both `data` and `errors` are populated),
/// and complete execution failures.
///
/// # Type Parameters
///
/// * `T` — Deserializable data structure mapping to the requested schema fields.
///
/// # Example: Partial Success Handling
///
/// ```rust
/// use moongraphql_builder::payload::GraphQLResponse;
/// use serde::Deserialize;
///
/// #[derive(Debug, Deserialize)]
/// struct Profile {
/// nickname: String,
/// }
///
/// let response_json = r#"{
/// "data": {"nickname": "DinaMoon"},
/// "errors": [{"message": "Warning: rate limit budget at 90%"}]
/// }"#;
///
/// let response: GraphQLResponse<Profile> = serde_json::from_str(response_json).unwrap();
/// if let Some(data) = response.data {
/// println!("Successfully retrieved data: {}", data.nickname);
/// }
/// if let Some(errors) = response.errors {
/// println!("Encountered execution warnings: {} error(s)", errors.len());
/// }
/// ```
/// Standard JSON body payload dispatched to a GraphQL endpoint via HTTP POST.
///
/// Enforces clean serialization by skipping `operationName` and `variables` when [`None`],
/// minimizing wire payload overhead.
///
/// # Example
///
/// ```rust
/// use moongraphql_builder::payload::GraphQLPayload;
///
/// let payload = GraphQLPayload {
/// operation_name: None,
/// query: "query { animes(limit: 5) { id name } }".to_string(),
/// variables: Some(serde_json::json!({ "limit": 5 })),
/// };
///
/// let json_string = serde_json::to_string(&payload).unwrap();
/// assert!(json_string.contains("\"query\":"));
/// ```