diff --git a/Cargo.lock b/Cargo.lock index 5af5cff6f1c..aaac6194e6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3712,7 +3712,7 @@ dependencies = [ "futures 0.1.31", "futures 0.3.31", "graph_derive", - "graphql-parser", + "graphql-tools", "half", "hex", "hex-literal", @@ -4009,7 +4009,6 @@ dependencies = [ "git-testament", "graph", "graphman-store", - "graphql-parser", "hex", "itertools 0.14.0", "lazy_static", @@ -4117,27 +4116,20 @@ dependencies = [ "strum", ] -[[package]] -name = "graphql-parser" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a818c0d883d7c0801df27be910917750932be279c7bc82dc541b8769425f409" -dependencies = [ - "combine", - "thiserror 1.0.61", -] - [[package]] name = "graphql-tools" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68fb22726aceab7a8933cdcff4201e1cdbcc7c7394df5bc1ebdcf27b44376433" +checksum = "9a378ccbe227983c1f4aeaafd088d0de9c5e3d5b6cd8e7aa9b0c682582a6c067" dependencies = [ - "graphql-parser", + "combine", + "itoa", "lazy_static", + "ryu", "serde", "serde_json", "serde_with", + "thiserror 2.0.18", ] [[package]] @@ -4918,9 +4910,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" [[package]] name = "ittapi" @@ -7025,9 +7017,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.18" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" [[package]] name = "same-file" diff --git a/Cargo.toml b/Cargo.toml index ddeaedb6732..e5ac8f61325 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,6 +66,7 @@ graph-store-postgres = { path = "./store/postgres" } graphman-server = { path = "./server/graphman" } graphman = { path = "./core/graphman" } graphman-store = { path = "./core/graphman_store" } +graphql-tools = "0.5.0" itertools = "0.14.0" lazy_static = "1.5.0" prost = "0.13" diff --git a/graph/Cargo.toml b/graph/Cargo.toml index 648fa8efcb8..fd8034040f6 100644 --- a/graph/Cargo.toml +++ b/graph/Cargo.toml @@ -37,7 +37,7 @@ http-body-util = "0.1" hyper-util = { version = "0.1", features = ["full"] } futures01 = { package = "futures", version = "0.1.31" } lru_time_cache = "0.11" -graphql-parser = "0.4.1" +graphql-tools = { workspace = true } lazy_static = "1.5.0" num-bigint = { version = "=0.2.6", features = ["serde"] } num-integer = { version = "=0.1.46" } diff --git a/graph/examples/validate.rs b/graph/examples/validate.rs index a5a2159cff4..b94c00b999d 100644 --- a/graph/examples/validate.rs +++ b/graph/examples/validate.rs @@ -36,7 +36,6 @@ use graph::data::subgraph::SPEC_VERSION_1_1_0; use graph::prelude::s; use graph::prelude::DeploymentHash; use graph::schema::InputSchema; -use graphql_parser::parse_schema; use serde::Deserialize; use std::alloc::GlobalAlloc; use std::alloc::Layout; @@ -147,7 +146,7 @@ struct Opts { #[clap(long)] api: bool, #[clap( - short, long, default_value = "validate", + short, long, default_value = "validate", value_parser = clap::builder::PossibleValuesParser::new(&["validate", "size"]) )] mode: RunMode, @@ -157,7 +156,7 @@ struct Opts { } fn parse(raw: &str, name: &str, api: bool) -> Result { - let schema = parse_schema(raw) + let schema = s::parse_schema(raw) .map(|v| v.into_static()) .map_err(|e| anyhow!("Failed to parse schema sgd{name}: {e}"))?; let id = subgraph_id(&schema); @@ -233,7 +232,7 @@ impl Sizer { let elapsed = start.elapsed(); let txt_size = raw.len(); let (gql_size, _) = self.size(|| { - parse_schema(raw) + s::parse_schema(raw) .map(|v| v.into_static()) .map_err(Into::into) })?; diff --git a/graph/src/data/graphql/ext.rs b/graph/src/data/graphql/ext.rs index 8cdc312f72b..e9f3828e169 100644 --- a/graph/src/data/graphql/ext.rs +++ b/graph/src/data/graphql/ext.rs @@ -394,8 +394,6 @@ impl FieldExt for Field { #[cfg(test)] mod directive_finder_tests { - use graphql_parser::parse_schema; - use super::*; const SCHEMA: &str = " @@ -407,7 +405,7 @@ mod directive_finder_tests { /// Makes sure that the DirectiveFinder::find_directive implementation for ObjectiveType and Field works #[test] fn find_directive_impls() { - let ast = parse_schema::(SCHEMA).unwrap(); + let ast = s::parse_schema::(SCHEMA).unwrap(); let object_types = ast.get_object_type_definitions(); assert_eq!(object_types.len(), 1); let object_type = object_types[0]; @@ -430,7 +428,7 @@ mod directive_finder_tests { /// Makes sure that the DirectiveFinder::is_derived implementation for ObjectiveType and Field works #[test] fn is_derived_impls() { - let ast = parse_schema::(SCHEMA).unwrap(); + let ast = s::parse_schema::(SCHEMA).unwrap(); let object_types = ast.get_object_type_definitions(); assert_eq!(object_types.len(), 1); let object_type = object_types[0]; diff --git a/graph/src/data/graphql/shape_hash.rs b/graph/src/data/graphql/shape_hash.rs index 00ab6476c9f..017093c641c 100644 --- a/graph/src/data/graphql/shape_hash.rs +++ b/graph/src/data/graphql/shape_hash.rs @@ -38,7 +38,7 @@ impl ShapeHash for q::Document { impl ShapeHash for q::OperationDefinition { fn shape_hash(&self, hasher: &mut ShapeHasher) { - use graphql_parser::query::OperationDefinition::*; + use graphql_tools::parser::query::OperationDefinition::*; // We want `[query|subscription|mutation] things { BODY }` to hash // to the same thing as just `things { BODY }` match self { @@ -69,7 +69,7 @@ impl ShapeHash for q::SelectionSet { impl ShapeHash for q::Selection { fn shape_hash(&self, hasher: &mut ShapeHasher) { - use graphql_parser::query::Selection::*; + use graphql_tools::parser::query::Selection::*; match self { Field(field) => field.shape_hash(hasher), FragmentSpread(spread) => spread.shape_hash(hasher), @@ -92,7 +92,7 @@ impl ShapeHash for q::Field { impl ShapeHash for s::Value { fn shape_hash(&self, hasher: &mut ShapeHasher) { - use graphql_parser::schema::Value::*; + use graphql_tools::parser::schema::Value::*; match self { Variable(_) | Int(_) | Float(_) | String(_) | Boolean(_) | Null | Enum(_) => { @@ -151,7 +151,6 @@ impl ShapeHash for q::TypeCondition { #[cfg(test)] mod tests { use super::*; - use graphql_parser::parse_query; #[test] fn identical_and_different() { @@ -159,16 +158,16 @@ mod tests { const Q2: &str = "{ things(where: { stuff_gt: 42 }) { id } }"; const Q3: &str = "{ things(where: { stuff_lte: 42 }) { id } }"; const Q4: &str = "{ things(where: { stuff_gt: 42 }) { id name } }"; - let q1 = parse_query(Q1) + let q1 = q::parse_query(Q1) .expect("q1 is syntactically valid") .into_static(); - let q2 = parse_query(Q2) + let q2 = q::parse_query(Q2) .expect("q2 is syntactically valid") .into_static(); - let q3 = parse_query(Q3) + let q3 = q::parse_query(Q3) .expect("q3 is syntactically valid") .into_static(); - let q4 = parse_query(Q4) + let q4 = q::parse_query(Q4) .expect("q4 is syntactically valid") .into_static(); diff --git a/graph/src/data/query/error.rs b/graph/src/data/query/error.rs index 1a85f34af8c..ac01da52df7 100644 --- a/graph/src/data/query/error.rs +++ b/graph/src/data/query/error.rs @@ -1,4 +1,3 @@ -use graphql_parser::Pos; use hex::FromHexError; use serde::ser::*; use std::collections::HashMap; @@ -26,20 +25,20 @@ pub enum QueryExecutionError { OperationNameRequired, OperationNotFound(String), NotSupported(String), - NonNullError(Pos, String), - ListValueError(Pos, String), + NonNullError(q::Pos, String), + ListValueError(q::Pos, String), NamedTypeError(String), AbstractTypeError(String), - InvalidArgumentError(Pos, String, q::Value), - MissingArgumentError(Pos, String), - ValidationError(Option, String), - InvalidVariableTypeError(Pos, String), - MissingVariableError(Pos, String), + InvalidArgumentError(q::Pos, String, q::Value), + MissingArgumentError(q::Pos, String), + ValidationError(Option, String), + InvalidVariableTypeError(q::Pos, String), + MissingVariableError(q::Pos, String), ResolveEntitiesError(String), OrderByNotSupportedError(String, String), OrderByNotSupportedForType(String), FilterNotSupportedError(String, String), - UnknownField(Pos, String, String), + UnknownField(q::Pos, String, String), EmptyQuery, InvalidOrFilterStructure(Vec, String), SubgraphDeploymentIdError(String), @@ -55,10 +54,10 @@ pub enum QueryExecutionError { StoreError(CloneableAnyhowError), Timeout, EmptySelectionSet(String), - AmbiguousDerivedFromResult(Pos, String, String, String), + AmbiguousDerivedFromResult(q::Pos, String, String, String), Unimplemented(String), - EnumCoercionError(Pos, String, q::Value, String, Vec), - ScalarCoercionError(Pos, String, q::Value, String), + EnumCoercionError(q::Pos, String, q::Value, String, Vec), + ScalarCoercionError(q::Pos, String, q::Value, String), TooComplex(u64, u64), // (complexity, max_complexity) TooDeep(u8), // max_depth CyclicalFragment(String), diff --git a/graph/src/data/query/query.rs b/graph/src/data/query/query.rs index 0520be3be78..cb35f6ccca0 100644 --- a/graph/src/data/query/query.rs +++ b/graph/src/data/query/query.rs @@ -147,7 +147,7 @@ impl Query { { ( document - .format(graphql_parser::Style::default().indent(0)) + .format(graphql_tools::parser::Style::default().indent(0)) .replace('\n', " "), serde_json::to_string(&variables).unwrap_or_default(), ) diff --git a/graph/src/data/store/mod.rs b/graph/src/data/store/mod.rs index f113c5248c8..cdd9be06a37 100644 --- a/graph/src/data/store/mod.rs +++ b/graph/src/data/store/mod.rs @@ -329,7 +329,7 @@ impl NullValue for Value { impl Value { pub fn from_query_value(value: &r::Value, ty: &s::Type) -> Result { - use graphql_parser::schema::Type::{ListType, NamedType, NonNullType}; + use graphql_tools::parser::schema::Type::{ListType, NamedType, NonNullType}; Ok(match (value, ty) { // When dealing with non-null types, use the inner type to convert the value diff --git a/graph/src/lib.rs b/graph/src/lib.rs index 030ca945709..99dcc35984a 100644 --- a/graph/src/lib.rs +++ b/graph/src/lib.rs @@ -176,31 +176,34 @@ pub mod prelude { macro_rules! static_graphql { ($m:ident, $m2:ident, {$($n:ident,)*}) => { - pub mod $m { - use graphql_parser::$m2 as $m; - pub use graphql_parser::Pos; + use graphql_tools::parser::$m2 as $m; + pub use graphql_tools::parser::Pos; pub use $m::*; $( pub type $n = $m::$n<'static, String>; )* - } }; } // Static graphql mods. These are to be phased out, with a preference // toward making graphql generic over text. This helps to ease the // transition by providing the old graphql-parse 0.2.x API - static_graphql!(q, query, { - Document, Value, OperationDefinition, InlineFragment, TypeCondition, - FragmentSpread, Field, Selection, SelectionSet, FragmentDefinition, - Directive, VariableDefinition, Type, Query, - }); - static_graphql!(s, schema, { - Field, Directive, InterfaceType, ObjectType, Value, TypeDefinition, - EnumType, Type, Definition, Document, ScalarType, InputValue, DirectiveDefinition, - UnionType, InputObjectType, EnumValue, - }); - + pub mod q { + static_graphql!(q, query, { + Document, Value, OperationDefinition, InlineFragment, TypeCondition, + FragmentSpread, Field, Selection, SelectionSet, FragmentDefinition, + Directive, VariableDefinition, Type, Query, + }); + pub use q::parse_query; + } + pub mod s { + static_graphql!(s, schema, { + Field, Directive, InterfaceType, ObjectType, Value, TypeDefinition, + EnumType, Type, Definition, Document, ScalarType, InputValue, DirectiveDefinition, + UnionType, InputObjectType, EnumValue, + }); + pub use s::parse_schema; + } pub mod r { pub use crate::data::value::{Object, Value}; } diff --git a/graph/src/schema/api.rs b/graph/src/schema/api.rs index 86b13a9f3f2..6195e3295a2 100644 --- a/graph/src/schema/api.rs +++ b/graph/src/schema/api.rs @@ -3,7 +3,6 @@ use std::str::FromStr; use std::sync::Arc; use anyhow::Context; -use graphql_parser::Pos; use lazy_static::lazy_static; use thiserror::Error; @@ -284,7 +283,7 @@ fn add_introspection_schema(schema: &mut s::Document) { // } let type_args = vec![s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: None, name: "name".to_string(), value_type: s::Type::NonNullType(Box::new(s::Type::NamedType("String".to_string()))), @@ -294,7 +293,7 @@ fn add_introspection_schema(schema: &mut s::Document) { vec![ s::Field { - position: Pos::default(), + position: q::Pos::default(), description: None, name: "__schema".to_string(), arguments: vec![], @@ -304,7 +303,7 @@ fn add_introspection_schema(schema: &mut s::Document) { directives: vec![], }, s::Field { - position: Pos::default(), + position: q::Pos::default(), description: None, name: "__type".to_string(), arguments: type_args, @@ -509,7 +508,7 @@ fn add_order_by_type( match api.get_named_type(&type_name) { None => { let typedef = s::TypeDefinition::Enum(s::EnumType { - position: Pos::default(), + position: q::Pos::default(), description: None, name: type_name, directives: vec![], @@ -531,7 +530,7 @@ fn field_enum_values( let mut enum_values = vec![]; for field in fields { enum_values.push(s::EnumValue { - position: Pos::default(), + position: q::Pos::default(), description: None, name: field.name.to_string(), directives: vec![], @@ -552,7 +551,7 @@ fn enum_value_from_child_entity_field( None } else { Some(s::EnumValue { - position: Pos::default(), + position: q::Pos::default(), description: None, name: format!("{}__{}", parent_field_name, field.name), directives: vec![], @@ -607,7 +606,7 @@ fn filter_type_defn(name: String, mut fields: Vec) -> s::Definiti if !ENV_VARS.graphql.disable_bool_filters { fields.push(s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: None, name: "and".to_string(), value_type: s::Type::ListType(Box::new(s::Type::NamedType(name.clone()))), @@ -616,7 +615,7 @@ fn filter_type_defn(name: String, mut fields: Vec) -> s::Definiti }); fields.push(s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: None, name: "or".to_string(), value_type: s::Type::ListType(Box::new(s::Type::NamedType(name.clone()))), @@ -626,7 +625,7 @@ fn filter_type_defn(name: String, mut fields: Vec) -> s::Definiti } let typedef = s::TypeDefinition::InputObject(s::InputObjectType { - position: Pos::default(), + position: q::Pos::default(), description: None, name, directives: vec![], @@ -1032,7 +1031,7 @@ fn field_list_filter_input_values( /// Generates a `*_filter` input value for the given field name, suffix and value type. fn input_value(name: &str, suffix: &'static str, value_type: s::Type) -> s::InputValue { s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: None, name: if suffix.is_empty() { name.to_owned() @@ -1075,7 +1074,7 @@ fn add_query_type(api: &mut s::Document, input_schema: &InputSchema) -> Result<( fields.push(meta_field()); let typedef = s::TypeDefinition::Object(s::ObjectType { - position: Pos::default(), + position: q::Pos::default(), description: None, name: type_name, implements_interfaces: vec![], @@ -1099,7 +1098,7 @@ fn query_field_for_fulltext(fulltext: &s::Directive) -> Option { let mut arguments = vec![ // text: String s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: None, name: String::from("text"), value_type: s::Type::NonNullType(Box::new(s::Type::NamedType(String::from("String")))), @@ -1108,7 +1107,7 @@ fn query_field_for_fulltext(fulltext: &s::Directive) -> Option { }, // first: Int s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: None, name: String::from("first"), value_type: s::Type::NamedType(String::from("Int")), @@ -1117,7 +1116,7 @@ fn query_field_for_fulltext(fulltext: &s::Directive) -> Option { }, // skip: Int s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: None, name: String::from("skip"), value_type: s::Type::NamedType(String::from("Int")), @@ -1136,7 +1135,7 @@ fn query_field_for_fulltext(fulltext: &s::Directive) -> Option { arguments.push(subgraph_error_argument()); Some(s::Field { - position: Pos::default(), + position: q::Pos::default(), description: None, name, arguments, @@ -1149,7 +1148,7 @@ fn query_field_for_fulltext(fulltext: &s::Directive) -> Option { fn block_argument() -> s::InputValue { s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: Some( "The block at which the query should be executed. \ Can either be a `{ hash: Bytes }` value containing a block hash, \ @@ -1169,7 +1168,7 @@ fn block_argument() -> s::InputValue { fn block_changed_filter_argument() -> s::InputValue { s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: Some("Filter for the block changed event.".to_owned()), name: "_change_block".to_string(), value_type: s::Type::NamedType(CHANGE_BLOCK_FILTER_NAME.to_owned()), @@ -1180,7 +1179,7 @@ fn block_changed_filter_argument() -> s::InputValue { fn subgraph_error_argument() -> s::InputValue { s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: Some( "Set to `allow` to receive data even if the subgraph has skipped over errors while syncing." .to_owned(), @@ -1199,7 +1198,7 @@ fn query_fields_for_type(type_name: &str, ops: FilterOps) -> Vec { let mut by_id_arguments = vec![ s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: None, name: "id".to_string(), value_type: s::Type::NonNullType(Box::new(s::Type::NamedType("ID".to_string()))), @@ -1216,7 +1215,7 @@ fn query_fields_for_type(type_name: &str, ops: FilterOps) -> Vec { let (singular, plural) = camel_cased_names(type_name); vec![ s::Field { - position: Pos::default(), + position: q::Pos::default(), description: None, name: singular, arguments: by_id_arguments, @@ -1224,7 +1223,7 @@ fn query_fields_for_type(type_name: &str, ops: FilterOps) -> Vec { directives: vec![], }, s::Field { - position: Pos::default(), + position: q::Pos::default(), description: None, name: plural, arguments: collection_arguments, @@ -1243,7 +1242,7 @@ fn query_fields_for_agg_type(type_name: &str) -> Vec { let (_, plural) = camel_cased_names(type_name); vec![s::Field { - position: Pos::default(), + position: q::Pos::default(), description: Some(format!("Collection of aggregated `{}` values", type_name)), name: plural, arguments: collection_arguments, @@ -1257,13 +1256,13 @@ fn query_fields_for_agg_type(type_name: &str) -> Vec { fn meta_field() -> s::Field { lazy_static! { static ref META_FIELD: s::Field = s::Field { - position: Pos::default(), + position: q::Pos::default(), description: Some("Access to subgraph metadata".to_string()), name: META_FIELD_NAME.to_string(), arguments: vec![ // block: BlockHeight s::InputValue { - position: Pos::default(), + position: q::Pos::default(), description: None, name: String::from("block"), value_type: s::Type::NamedType(BLOCK_HEIGHT.to_string()), @@ -1288,7 +1287,6 @@ mod tests { prelude::{s, DeploymentHash}, schema::{InputSchema, SCHEMA_TYPE_NAME}, }; - use graphql_parser::schema::*; use lazy_static::lazy_static; use super::ApiSchema; @@ -1316,7 +1314,7 @@ mod tests { .expect("Query type is missing in derived API schema"); match query_type { - TypeDefinition::Object(t) => ast::get_field(t, name), + s::TypeDefinition::Object(t) => ast::get_field(t, name), _ => None, } .unwrap_or_else(|| panic!("Schema should contain a field named `{}`", name)) @@ -1357,7 +1355,7 @@ mod tests { .get_named_type("OrderDirection") .expect("OrderDirection type is missing in derived API schema"); let enum_type = match order_direction { - TypeDefinition::Enum(t) => Some(t), + s::TypeDefinition::Enum(t) => Some(t), _ => None, } .expect("OrderDirection type is not an enum"); @@ -1387,7 +1385,7 @@ mod tests { .expect("User_orderBy type is missing in derived API schema"); let enum_type = match user_order_by { - TypeDefinition::Enum(t) => Some(t), + s::TypeDefinition::Enum(t) => Some(t), _ => None, } .expect("User_orderBy type is not an enum"); @@ -1486,7 +1484,7 @@ mod tests { .expect("User_orderBy type is missing in derived API schema"); let enum_type = match user_order_by { - TypeDefinition::Enum(t) => Some(t), + s::TypeDefinition::Enum(t) => Some(t), _ => None, } .expect("User_orderBy type is not an enum"); @@ -1528,7 +1526,7 @@ mod tests { .expect("Meal_orderBy type is missing in derived API schema"); let enum_type = match meal_order_by { - TypeDefinition::Enum(t) => Some(t), + s::TypeDefinition::Enum(t) => Some(t), _ => None, } .expect("Meal_orderBy type is not an enum"); @@ -1546,7 +1544,7 @@ mod tests { .expect("Recipe_orderBy type is missing in derived API schema"); let enum_type = match recipe_order_by { - TypeDefinition::Enum(t) => Some(t), + s::TypeDefinition::Enum(t) => Some(t), _ => None, } .expect("Recipe_orderBy type is not an enum"); @@ -1607,7 +1605,7 @@ mod tests { .expect("User_filter type is missing in derived API schema"); let user_filter_type = match user_filter { - TypeDefinition::InputObject(t) => Some(t), + s::TypeDefinition::InputObject(t) => Some(t), _ => None, } .expect("User_filter type is not an input object"); @@ -1712,7 +1710,7 @@ mod tests { .expect("Pet_filter type is missing in derived API schema"); let pet_filter_type = match pet_filter { - TypeDefinition::InputObject(t) => Some(t), + s::TypeDefinition::InputObject(t) => Some(t), _ => None, } .expect("Pet_filter type is not an input object"); @@ -1782,7 +1780,7 @@ mod tests { .expect("_change_block field is missing in User_filter"); match &change_block_filter.value_type { - Type::NamedType(name) => assert_eq!(name.as_str(), "BlockChangedFilter"), + s::Type::NamedType(name) => assert_eq!(name.as_str(), "BlockChangedFilter"), _ => panic!("_change_block field is not a named type"), } @@ -1827,7 +1825,7 @@ mod tests { .expect("User_filter type is missing in derived API schema"); let user_filter_type = match user_filter { - TypeDefinition::InputObject(t) => Some(t), + s::TypeDefinition::InputObject(t) => Some(t), _ => None, } .expect("User_filter type is not an input object"); @@ -1905,7 +1903,7 @@ mod tests { .expect("_change_block field is missing in User_filter"); match &change_block_filter.value_type { - Type::NamedType(name) => assert_eq!(name.as_str(), "BlockChangedFilter"), + s::Type::NamedType(name) => assert_eq!(name.as_str(), "BlockChangedFilter"), _ => panic!("_change_block field is not a named type"), } @@ -1925,14 +1923,14 @@ mod tests { .expect("Query type is missing in derived API schema"); let user_singular_field = match query_type { - TypeDefinition::Object(t) => ast::get_field(t, "user"), + s::TypeDefinition::Object(t) => ast::get_field(t, "user"), _ => None, } .expect("\"user\" field is missing on Query type"); assert_eq!( user_singular_field.field_type, - Type::NamedType("User".to_string()) + s::Type::NamedType("User".to_string()) ); assert_eq!( @@ -1949,15 +1947,15 @@ mod tests { ); let user_plural_field = match query_type { - TypeDefinition::Object(t) => ast::get_field(t, "users"), + s::TypeDefinition::Object(t) => ast::get_field(t, "users"), _ => None, } .expect("\"users\" field is missing on Query type"); assert_eq!( user_plural_field.field_type, - Type::NonNullType(Box::new(Type::ListType(Box::new(Type::NonNullType( - Box::new(Type::NamedType("User".to_string())) + s::Type::NonNullType(Box::new(s::Type::ListType(Box::new(s::Type::NonNullType( + Box::new(s::Type::NamedType("User".to_string())) ))))) ); @@ -1982,26 +1980,26 @@ mod tests { ); let user_profile_singular_field = match query_type { - TypeDefinition::Object(t) => ast::get_field(t, "userProfile"), + s::TypeDefinition::Object(t) => ast::get_field(t, "userProfile"), _ => None, } .expect("\"userProfile\" field is missing on Query type"); assert_eq!( user_profile_singular_field.field_type, - Type::NamedType("UserProfile".to_string()) + s::Type::NamedType("UserProfile".to_string()) ); let user_profile_plural_field = match query_type { - TypeDefinition::Object(t) => ast::get_field(t, "userProfiles"), + s::TypeDefinition::Object(t) => ast::get_field(t, "userProfiles"), _ => None, } .expect("\"userProfiles\" field is missing on Query type"); assert_eq!( user_profile_plural_field.field_type, - Type::NonNullType(Box::new(Type::ListType(Box::new(Type::NonNullType( - Box::new(Type::NamedType("UserProfile".to_string())) + s::Type::NonNullType(Box::new(s::Type::ListType(Box::new(s::Type::NonNullType( + Box::new(s::Type::NamedType("UserProfile".to_string())) ))))) ); } @@ -2020,14 +2018,14 @@ mod tests { .expect("Query type is missing in derived API schema"); let singular_field = match query_type { - TypeDefinition::Object(ref t) => ast::get_field(t, "node"), + s::TypeDefinition::Object(ref t) => ast::get_field(t, "node"), _ => None, } .expect("\"node\" field is missing on Query type"); assert_eq!( singular_field.field_type, - Type::NamedType("Node".to_string()) + s::Type::NamedType("Node".to_string()) ); assert_eq!( @@ -2044,15 +2042,15 @@ mod tests { ); let plural_field = match query_type { - TypeDefinition::Object(ref t) => ast::get_field(t, "nodes"), + s::TypeDefinition::Object(ref t) => ast::get_field(t, "nodes"), _ => None, } .expect("\"nodes\" field is missing on Query type"); assert_eq!( plural_field.field_type, - Type::NonNullType(Box::new(Type::ListType(Box::new(Type::NonNullType( - Box::new(Type::NamedType("Node".to_string())) + s::Type::NonNullType(Box::new(s::Type::ListType(Box::new(s::Type::NonNullType( + Box::new(s::Type::NamedType("Node".to_string())) ))))) ); @@ -2111,7 +2109,7 @@ type Gravatar @entity { .expect("Query type is missing in derived API schema"); let _metadata_field = match query_type { - TypeDefinition::Object(t) => ast::get_field(t, &String::from("metadata")), + s::TypeDefinition::Object(t) => ast::get_field(t, &String::from("metadata")), _ => None, } .expect("\"metadata\" field is missing on Query type"); @@ -2282,7 +2280,7 @@ type Gravatar @entity { .expect("Query type is missing in derived API schema"); match query_type { - TypeDefinition::Object(t) => ast::get_field(t, name), + s::TypeDefinition::Object(t) => ast::get_field(t, name), _ => None, } .unwrap_or_else(|| panic!("Schema should contain a field named `{}`", name)) diff --git a/graph/src/schema/ast.rs b/graph/src/schema/ast.rs index 2152ed25723..60395cb88e0 100644 --- a/graph/src/schema/ast.rs +++ b/graph/src/schema/ast.rs @@ -1,4 +1,3 @@ -use graphql_parser::Pos; use lazy_static::lazy_static; use std::ops::Deref; use std::str::FromStr; @@ -161,7 +160,7 @@ pub fn get_object_type_mut<'a>( schema: &'a mut s::Document, name: &str, ) -> Option<&'a mut s::ObjectType> { - use graphql_parser::schema::TypeDefinition::*; + use graphql_tools::parser::schema::TypeDefinition::*; get_named_type_definition_mut(schema, name).and_then(|type_def| match type_def { Object(object_type) => Some(object_type), @@ -174,7 +173,7 @@ pub fn get_interface_type_mut<'a>( schema: &'a mut s::Document, name: &str, ) -> Option<&'a mut s::InterfaceType> { - use graphql_parser::schema::TypeDefinition::*; + use graphql_tools::parser::schema::TypeDefinition::*; get_named_type_definition_mut(schema, name).and_then(|type_def| match type_def { Interface(interface_type) => Some(interface_type), @@ -189,7 +188,7 @@ pub fn get_field<'a>( ) -> Option<&'a s::Field> { lazy_static! { pub static ref TYPENAME_FIELD: s::Field = s::Field { - position: Pos::default(), + position: s::Pos::default(), description: None, name: "__typename".to_owned(), field_type: s::Type::NonNullType(Box::new(s::Type::NamedType("String".to_owned()))), @@ -261,7 +260,7 @@ pub fn get_argument_definitions<'a>( ) -> Option<&'a Vec> { lazy_static! { pub static ref NAME_ARGUMENT: Vec = vec![s::InputValue { - position: Pos::default(), + position: s::Pos::default(), description: None, name: "name".to_owned(), value_type: s::Type::NonNullType(Box::new(s::Type::NamedType("String".to_owned()))), diff --git a/graph/src/schema/input/mod.rs b/graph/src/schema/input/mod.rs index bd6aa2d3017..4f7eb70e0bf 100644 --- a/graph/src/schema/input/mod.rs +++ b/graph/src/schema/input/mod.rs @@ -2827,7 +2827,7 @@ type Account implements Address @entity { id: ID!, txn: Transaction! @derivedFro fn validate(field: &str, errmsg: &str) { let raw = format!("type A @entity {{ id: ID!\n {} }}\n{}", field, OTHER_TYPES); - let document = graphql_parser::parse_schema(&raw) + let document = s::parse_schema(&raw) .expect("Failed to parse raw schema") .into_static(); let schema = BaseSchema::new(DeploymentHash::new("id").unwrap(), document).unwrap(); @@ -2884,8 +2884,7 @@ type Account implements Address @entity { id: ID!, txn: Transaction! @derivedFro const ROOT_SCHEMA: &str = " type _Schema_ { id: ID! }"; - let document = - graphql_parser::parse_schema(ROOT_SCHEMA).expect("Failed to parse root schema"); + let document = s::parse_schema(ROOT_SCHEMA).expect("Failed to parse root schema"); let schema = BaseSchema::new(DeploymentHash::new("id").unwrap(), document).unwrap(); let schema = Schema::new(LATEST_VERSION, &schema); assert_eq!( @@ -2901,8 +2900,7 @@ type _Schema_ { id: ID! }"; const ROOT_SCHEMA: &str = " type _Schema_ @illegal"; - let document = - graphql_parser::parse_schema(ROOT_SCHEMA).expect("Failed to parse root schema"); + let document = s::parse_schema(ROOT_SCHEMA).expect("Failed to parse root schema"); let schema = BaseSchema::new(DeploymentHash::new("id").unwrap(), document).unwrap(); let schema = Schema::new(LATEST_VERSION, &schema); assert_eq!( @@ -2926,8 +2924,7 @@ type A @entity { color: Color }"#; - let document = - graphql_parser::parse_schema(ROOT_SCHEMA).expect("Failed to parse root schema"); + let document = s::parse_schema(ROOT_SCHEMA).expect("Failed to parse root schema"); let schema = BaseSchema::new(DeploymentHash::new("id").unwrap(), document).unwrap(); let schema = Schema::new(LATEST_VERSION, &schema); assert_eq!(schema.validate_fields().len(), 0); @@ -3035,7 +3032,7 @@ type Gravatar @entity { imageUrl: String! }"#; - let document = graphql_parser::parse_schema(SCHEMA).expect("Failed to parse schema"); + let document = s::parse_schema(SCHEMA).expect("Failed to parse schema"); let schema = BaseSchema::new(DeploymentHash::new("id1").unwrap(), document).unwrap(); let schema = Schema::new(LATEST_VERSION, &schema); assert_eq!(schema.validate_fulltext_directives(), vec![]); diff --git a/graph/src/schema/mod.rs b/graph/src/schema/mod.rs index f4e098a4b3e..f8725302b52 100644 --- a/graph/src/schema/mod.rs +++ b/graph/src/schema/mod.rs @@ -3,7 +3,6 @@ use crate::data::subgraph::DeploymentHash; use crate::prelude::{anyhow, s}; use anyhow::Error; -use graphql_parser::{self, Pos}; use semver::Version; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -280,7 +279,7 @@ impl Schema { } pub fn parse(raw: &str, id: DeploymentHash) -> Result { - let document = graphql_parser::parse_schema(raw)?.into_static(); + let document = s::parse_schema(raw)?.into_static(); Schema::new(id, document).map_err(Into::into) } @@ -302,7 +301,7 @@ impl Schema { let subgraph_id_directive = s::Directive { name: "subgraphId".to_string(), - position: Pos::default(), + position: s::Pos::default(), arguments: vec![subgraph_id_argument], }; diff --git a/graphql/Cargo.toml b/graphql/Cargo.toml index 898bfc15f9b..2dcac956d67 100644 --- a/graphql/Cargo.toml +++ b/graphql/Cargo.toml @@ -7,7 +7,7 @@ edition.workspace = true async-trait = { workspace = true } crossbeam = "0.8" graph = { path = "../graph" } -graphql-tools = "0.4.0" +graphql-tools = { workspace = true } lazy_static = "1.5.0" stable-hash = { git = "https://github.com/graphprotocol/stable-hash", branch = "main"} stable-hash_legacy = { git = "https://github.com/graphprotocol/stable-hash", branch = "old", package = "stable-hash" } diff --git a/store/postgres/Cargo.toml b/store/postgres/Cargo.toml index ba132a514c6..36be96bb7d7 100644 --- a/store/postgres/Cargo.toml +++ b/store/postgres/Cargo.toml @@ -41,7 +41,6 @@ serde_yaml.workspace = true [dev-dependencies] clap.workspace = true -graphql-parser = "0.4.1" [lints] workspace = true