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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#![warn(missing_docs)]
#[doc(hidden)]
#[macro_use]
pub extern crate serde;
#[macro_use]
extern crate serde_derive;
#[cfg(any(test, feature = "expose-test-schema"))]
extern crate serde_json;
extern crate fnv;
extern crate indexmap;
#[cfg(any(test, feature = "chrono"))]
extern crate chrono;
#[cfg(any(test, feature = "url"))]
extern crate url;
#[cfg(any(test, feature = "uuid"))]
extern crate uuid;
#[allow(unused_imports)]
#[macro_use]
extern crate juniper_codegen;
#[doc(hidden)]
pub use juniper_codegen::*;
#[macro_use]
mod value;
#[macro_use]
mod macros;
mod ast;
mod executor;
pub mod parser;
pub(crate) mod schema;
mod types;
mod util;
mod validation;
pub mod http;
pub mod integrations;
pub use http::graphiql;
#[cfg(all(test, not(feature = "expose-test-schema")))]
mod tests;
#[cfg(feature = "expose-test-schema")]
pub mod tests;
#[cfg(test)]
mod executor_tests;
pub use util::to_camel_case;
use executor::execute_validated_query;
use parser::{parse_document_source, ParseError, Spanning};
use validation::{validate_input_values, visit_all_rules, ValidatorContext};
pub use ast::{FromInputValue, InputValue, Selection, ToInputValue, Type};
pub use executor::{
Applies, LookAheadArgument, LookAheadMethods, LookAheadSelection, LookAheadValue,
};
pub use executor::{
Context, ExecutionError, ExecutionResult, Executor, FieldError, FieldResult, FromContext,
IntoFieldError, IntoResolvable, Registry, Variables,
};
pub use schema::meta;
pub use schema::model::RootNode;
pub use types::base::{Arguments, GraphQLType, TypeKind};
pub use types::scalars::{EmptyMutation, ID};
pub use validation::RuleError;
pub use value::{
DefaultScalarValue, Object, ParseScalarResult, ParseScalarValue, ScalarRefValue, ScalarValue,
Value,
};
#[derive(Debug, PartialEq)]
#[allow(missing_docs)]
pub enum GraphQLError<'a> {
ParseError(Spanning<ParseError<'a>>),
ValidationError(Vec<RuleError>),
NoOperationProvided,
MultipleOperationsProvided,
UnknownOperationName,
}
pub fn execute<'a, S, CtxT, QueryT, MutationT>(
document_source: &'a str,
operation_name: Option<&str>,
root_node: &'a RootNode<QueryT, MutationT, S>,
variables: &Variables<S>,
context: &CtxT,
) -> Result<(Value<S>, Vec<ExecutionError<S>>), GraphQLError<'a>>
where
S: ScalarValue,
for<'b> &'b S: ScalarRefValue<'b>,
QueryT: GraphQLType<S, Context = CtxT>,
MutationT: GraphQLType<S, Context = CtxT>,
{
let document = parse_document_source(document_source, &root_node.schema)?;
{
let errors = validate_input_values(variables, &document, &root_node.schema);
if !errors.is_empty() {
return Err(GraphQLError::ValidationError(errors));
}
}
{
let mut ctx = ValidatorContext::new(&root_node.schema, &document);
visit_all_rules(&mut ctx, &document);
let errors = ctx.into_errors();
if !errors.is_empty() {
return Err(GraphQLError::ValidationError(errors));
}
}
execute_validated_query(document, operation_name, root_node, variables, context)
}
impl<'a> From<Spanning<ParseError<'a>>> for GraphQLError<'a> {
fn from(f: Spanning<ParseError<'a>>) -> GraphQLError<'a> {
GraphQLError::ParseError(f)
}
}