Skip to content

Commit 3cea2bb

Browse files
committed
graph, store: Prefer using the q and s module over graphql_tools::parser
1 parent 40e8fd1 commit 3cea2bb

File tree

11 files changed

+96
-108
lines changed

11 files changed

+96
-108
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graph/examples/validate.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use graph::data::subgraph::SPEC_VERSION_1_1_0;
3636
use graph::prelude::s;
3737
use graph::prelude::DeploymentHash;
3838
use graph::schema::InputSchema;
39-
use graphql_tools::parser::parse_schema;
4039
use serde::Deserialize;
4140
use std::alloc::GlobalAlloc;
4241
use std::alloc::Layout;
@@ -157,7 +156,7 @@ struct Opts {
157156
}
158157

159158
fn parse(raw: &str, name: &str, api: bool) -> Result<DeploymentHash> {
160-
let schema = parse_schema(raw)
159+
let schema = s::parse_schema(raw)
161160
.map(|v| v.into_static())
162161
.map_err(|e| anyhow!("Failed to parse schema sgd{name}: {e}"))?;
163162
let id = subgraph_id(&schema);
@@ -233,7 +232,7 @@ impl Sizer {
233232
let elapsed = start.elapsed();
234233
let txt_size = raw.len();
235234
let (gql_size, _) = self.size(|| {
236-
parse_schema(raw)
235+
s::parse_schema(raw)
237236
.map(|v| v.into_static())
238237
.map_err(Into::into)
239238
})?;

graph/src/data/graphql/ext.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,6 @@ impl FieldExt for Field {
394394

395395
#[cfg(test)]
396396
mod directive_finder_tests {
397-
use graphql_tools::parser::parse_schema;
398-
399397
use super::*;
400398

401399
const SCHEMA: &str = "
@@ -407,7 +405,7 @@ mod directive_finder_tests {
407405
/// Makes sure that the DirectiveFinder::find_directive implementation for ObjectiveType and Field works
408406
#[test]
409407
fn find_directive_impls() {
410-
let ast = parse_schema::<String>(SCHEMA).unwrap();
408+
let ast = s::parse_schema::<String>(SCHEMA).unwrap();
411409
let object_types = ast.get_object_type_definitions();
412410
assert_eq!(object_types.len(), 1);
413411
let object_type = object_types[0];
@@ -430,7 +428,7 @@ mod directive_finder_tests {
430428
/// Makes sure that the DirectiveFinder::is_derived implementation for ObjectiveType and Field works
431429
#[test]
432430
fn is_derived_impls() {
433-
let ast = parse_schema::<String>(SCHEMA).unwrap();
431+
let ast = s::parse_schema::<String>(SCHEMA).unwrap();
434432
let object_types = ast.get_object_type_definitions();
435433
assert_eq!(object_types.len(), 1);
436434
let object_type = object_types[0];

graph/src/data/graphql/shape_hash.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,24 +151,23 @@ impl ShapeHash for q::TypeCondition {
151151
#[cfg(test)]
152152
mod tests {
153153
use super::*;
154-
use graphql_tools::parser::parse_query;
155154

156155
#[test]
157156
fn identical_and_different() {
158157
const Q1: &str = "query things($stuff: Int) { things(where: { stuff_gt: $stuff }) { id } }";
159158
const Q2: &str = "{ things(where: { stuff_gt: 42 }) { id } }";
160159
const Q3: &str = "{ things(where: { stuff_lte: 42 }) { id } }";
161160
const Q4: &str = "{ things(where: { stuff_gt: 42 }) { id name } }";
162-
let q1 = parse_query(Q1)
161+
let q1 = q::parse_query(Q1)
163162
.expect("q1 is syntactically valid")
164163
.into_static();
165-
let q2 = parse_query(Q2)
164+
let q2 = q::parse_query(Q2)
166165
.expect("q2 is syntactically valid")
167166
.into_static();
168-
let q3 = parse_query(Q3)
167+
let q3 = q::parse_query(Q3)
169168
.expect("q3 is syntactically valid")
170169
.into_static();
171-
let q4 = parse_query(Q4)
170+
let q4 = q::parse_query(Q4)
172171
.expect("q4 is syntactically valid")
173172
.into_static();
174173

graph/src/data/query/error.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use graphql_tools::parser::Pos;
21
use hex::FromHexError;
32
use serde::ser::*;
43
use std::collections::HashMap;
@@ -26,20 +25,20 @@ pub enum QueryExecutionError {
2625
OperationNameRequired,
2726
OperationNotFound(String),
2827
NotSupported(String),
29-
NonNullError(Pos, String),
30-
ListValueError(Pos, String),
28+
NonNullError(q::Pos, String),
29+
ListValueError(q::Pos, String),
3130
NamedTypeError(String),
3231
AbstractTypeError(String),
33-
InvalidArgumentError(Pos, String, q::Value),
34-
MissingArgumentError(Pos, String),
35-
ValidationError(Option<Pos>, String),
36-
InvalidVariableTypeError(Pos, String),
37-
MissingVariableError(Pos, String),
32+
InvalidArgumentError(q::Pos, String, q::Value),
33+
MissingArgumentError(q::Pos, String),
34+
ValidationError(Option<q::Pos>, String),
35+
InvalidVariableTypeError(q::Pos, String),
36+
MissingVariableError(q::Pos, String),
3837
ResolveEntitiesError(String),
3938
OrderByNotSupportedError(String, String),
4039
OrderByNotSupportedForType(String),
4140
FilterNotSupportedError(String, String),
42-
UnknownField(Pos, String, String),
41+
UnknownField(q::Pos, String, String),
4342
EmptyQuery,
4443
InvalidOrFilterStructure(Vec<String>, String),
4544
SubgraphDeploymentIdError(String),
@@ -55,10 +54,10 @@ pub enum QueryExecutionError {
5554
StoreError(CloneableAnyhowError),
5655
Timeout,
5756
EmptySelectionSet(String),
58-
AmbiguousDerivedFromResult(Pos, String, String, String),
57+
AmbiguousDerivedFromResult(q::Pos, String, String, String),
5958
Unimplemented(String),
60-
EnumCoercionError(Pos, String, q::Value, String, Vec<String>),
61-
ScalarCoercionError(Pos, String, q::Value, String),
59+
EnumCoercionError(q::Pos, String, q::Value, String, Vec<String>),
60+
ScalarCoercionError(q::Pos, String, q::Value, String),
6261
TooComplex(u64, u64), // (complexity, max_complexity)
6362
TooDeep(u8), // max_depth
6463
CyclicalFragment(String),

graph/src/lib.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,31 +176,34 @@ pub mod prelude {
176176

177177
macro_rules! static_graphql {
178178
($m:ident, $m2:ident, {$($n:ident,)*}) => {
179-
pub mod $m {
180179
use graphql_tools::parser::$m2 as $m;
181180
pub use graphql_tools::parser::Pos;
182181
pub use $m::*;
183182
$(
184183
pub type $n = $m::$n<'static, String>;
185184
)*
186-
}
187185
};
188186
}
189187

190188
// Static graphql mods. These are to be phased out, with a preference
191189
// toward making graphql generic over text. This helps to ease the
192190
// transition by providing the old graphql-parse 0.2.x API
193-
static_graphql!(q, query, {
194-
Document, Value, OperationDefinition, InlineFragment, TypeCondition,
195-
FragmentSpread, Field, Selection, SelectionSet, FragmentDefinition,
196-
Directive, VariableDefinition, Type, Query,
197-
});
198-
static_graphql!(s, schema, {
199-
Field, Directive, InterfaceType, ObjectType, Value, TypeDefinition,
200-
EnumType, Type, Definition, Document, ScalarType, InputValue, DirectiveDefinition,
201-
UnionType, InputObjectType, EnumValue,
202-
});
203-
191+
pub mod q {
192+
static_graphql!(q, query, {
193+
Document, Value, OperationDefinition, InlineFragment, TypeCondition,
194+
FragmentSpread, Field, Selection, SelectionSet, FragmentDefinition,
195+
Directive, VariableDefinition, Type, Query,
196+
});
197+
pub use q::parse_query;
198+
}
199+
pub mod s {
200+
static_graphql!(s, schema, {
201+
Field, Directive, InterfaceType, ObjectType, Value, TypeDefinition,
202+
EnumType, Type, Definition, Document, ScalarType, InputValue, DirectiveDefinition,
203+
UnionType, InputObjectType, EnumValue,
204+
});
205+
pub use s::parse_schema;
206+
}
204207
pub mod r {
205208
pub use crate::data::value::{Object, Value};
206209
}

0 commit comments

Comments
 (0)