From e7205f118a31a0c2e4223dff4a5bc1cda670297a Mon Sep 17 00:00:00 2001 From: vohoanglong0107 Date: Fri, 7 Jun 2024 13:59:26 +0000 Subject: [PATCH] feat(graphql_parser): parse input object type extension --- .../src/generated/node_factory.rs | 107 +++-- .../src/generated/syntax_factory.rs | 45 +-- .../src/parser/definitions/input_object.rs | 28 +- .../src/parser/definitions/mod.rs | 3 +- .../src/parser/parse_error.rs | 10 + .../input_object_extension.graphql | 6 + .../input_object_extension.graphql.snap | 151 +++++++ .../definitions/schema_extension.graphql.snap | 2 +- .../input_object_extension.graphql | 11 + .../input_object_extension.graphql.snap | 226 +++++++++++ .../src/generated/kind.rs | 3 - .../src/generated/macros.rs | 10 - .../src/generated/nodes.rs | 378 ++---------------- .../src/generated/nodes_mut.rs | 46 +-- crates/biome_graphql_syntax/src/lib.rs | 2 - xtask/codegen/graphql.ungram | 20 +- xtask/codegen/src/graphql_kind_src.rs | 3 - 17 files changed, 552 insertions(+), 499 deletions(-) create mode 100644 crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/input_object_extension.graphql create mode 100644 crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/input_object_extension.graphql.snap create mode 100644 crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/input_object_extension.graphql create mode 100644 crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/input_object_extension.graphql.snap diff --git a/crates/biome_graphql_factory/src/generated/node_factory.rs b/crates/biome_graphql_factory/src/generated/node_factory.rs index 4b1f2c42088e..cb66f6ed5695 100644 --- a/crates/biome_graphql_factory/src/generated/node_factory.rs +++ b/crates/biome_graphql_factory/src/generated/node_factory.rs @@ -595,34 +595,40 @@ pub fn graphql_input_object_type_extension( input_token: SyntaxToken, name: GraphqlName, directives: GraphqlDirectiveList, -) -> GraphqlInputObjectTypeExtension { - GraphqlInputObjectTypeExtension::unwrap_cast(SyntaxNode::new_detached( - GraphqlSyntaxKind::GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION, - [ - Some(SyntaxElement::Token(extend_token)), - Some(SyntaxElement::Token(input_token)), - Some(SyntaxElement::Node(name.into_syntax())), - Some(SyntaxElement::Node(directives.into_syntax())), - ], - )) +) -> GraphqlInputObjectTypeExtensionBuilder { + GraphqlInputObjectTypeExtensionBuilder { + extend_token, + input_token, + name, + directives, + input_fields: None, + } } -pub fn graphql_input_object_type_extension_with_fields( +pub struct GraphqlInputObjectTypeExtensionBuilder { extend_token: SyntaxToken, input_token: SyntaxToken, name: GraphqlName, directives: GraphqlDirectiveList, - input_fields: GraphqlInputFieldsDefinition, -) -> GraphqlInputObjectTypeExtensionWithFields { - GraphqlInputObjectTypeExtensionWithFields::unwrap_cast(SyntaxNode::new_detached( - GraphqlSyntaxKind::GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION_WITH_FIELDS, - [ - Some(SyntaxElement::Token(extend_token)), - Some(SyntaxElement::Token(input_token)), - Some(SyntaxElement::Node(name.into_syntax())), - Some(SyntaxElement::Node(directives.into_syntax())), - Some(SyntaxElement::Node(input_fields.into_syntax())), - ], - )) + input_fields: Option, +} +impl GraphqlInputObjectTypeExtensionBuilder { + pub fn with_input_fields(mut self, input_fields: GraphqlInputFieldsDefinition) -> Self { + self.input_fields = Some(input_fields); + self + } + pub fn build(self) -> GraphqlInputObjectTypeExtension { + GraphqlInputObjectTypeExtension::unwrap_cast(SyntaxNode::new_detached( + GraphqlSyntaxKind::GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION, + [ + Some(SyntaxElement::Token(self.extend_token)), + Some(SyntaxElement::Token(self.input_token)), + Some(SyntaxElement::Node(self.name.into_syntax())), + Some(SyntaxElement::Node(self.directives.into_syntax())), + self.input_fields + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } } pub fn graphql_input_value_definition( name: GraphqlName, @@ -1165,17 +1171,40 @@ pub fn graphql_schema_extension( extend_token: SyntaxToken, schema_token: SyntaxToken, directives: GraphqlDirectiveList, - root_operation_types: GraphqlRootOperationTypes, -) -> GraphqlSchemaExtension { - GraphqlSchemaExtension::unwrap_cast(SyntaxNode::new_detached( - GraphqlSyntaxKind::GRAPHQL_SCHEMA_EXTENSION, - [ - Some(SyntaxElement::Token(extend_token)), - Some(SyntaxElement::Token(schema_token)), - Some(SyntaxElement::Node(directives.into_syntax())), - Some(SyntaxElement::Node(root_operation_types.into_syntax())), - ], - )) +) -> GraphqlSchemaExtensionBuilder { + GraphqlSchemaExtensionBuilder { + extend_token, + schema_token, + directives, + root_operation_types: None, + } +} +pub struct GraphqlSchemaExtensionBuilder { + extend_token: SyntaxToken, + schema_token: SyntaxToken, + directives: GraphqlDirectiveList, + root_operation_types: Option, +} +impl GraphqlSchemaExtensionBuilder { + pub fn with_root_operation_types( + mut self, + root_operation_types: GraphqlRootOperationTypes, + ) -> Self { + self.root_operation_types = Some(root_operation_types); + self + } + pub fn build(self) -> GraphqlSchemaExtension { + GraphqlSchemaExtension::unwrap_cast(SyntaxNode::new_detached( + GraphqlSyntaxKind::GRAPHQL_SCHEMA_EXTENSION, + [ + Some(SyntaxElement::Token(self.extend_token)), + Some(SyntaxElement::Token(self.schema_token)), + Some(SyntaxElement::Node(self.directives.into_syntax())), + self.root_operation_types + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } } pub fn graphql_selection_set( l_curly_token: SyntaxToken, @@ -1620,16 +1649,6 @@ where slots, )) } -pub fn graphql_bogus_extension(slots: I) -> GraphqlBogusExtension -where - I: IntoIterator>, - I::IntoIter: ExactSizeIterator, -{ - GraphqlBogusExtension::unwrap_cast(SyntaxNode::new_detached( - GraphqlSyntaxKind::GRAPHQL_BOGUS_EXTENSION, - slots, - )) -} pub fn graphql_bogus_selection(slots: I) -> GraphqlBogusSelection where I: IntoIterator>, diff --git a/crates/biome_graphql_factory/src/generated/syntax_factory.rs b/crates/biome_graphql_factory/src/generated/syntax_factory.rs index c992fb95cc52..c697214720cf 100644 --- a/crates/biome_graphql_factory/src/generated/syntax_factory.rs +++ b/crates/biome_graphql_factory/src/generated/syntax_factory.rs @@ -16,7 +16,6 @@ impl SyntaxFactory for GraphqlSyntaxFactory { match kind { GRAPHQL_BOGUS | GRAPHQL_BOGUS_DEFINITION - | GRAPHQL_BOGUS_EXTENSION | GRAPHQL_BOGUS_SELECTION | GRAPHQL_BOGUS_TYPE | GRAPHQL_BOGUS_VALUE => RawSyntaxNode::new(kind, children.into_iter().map(Some)), @@ -923,46 +922,6 @@ impl SyntaxFactory for GraphqlSyntaxFactory { slots.into_node(GRAPHQL_INPUT_OBJECT_TYPE_DEFINITION, children) } GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION => { - let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); - let mut current_element = elements.next(); - if let Some(element) = ¤t_element { - if element.kind() == T![extend] { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if element.kind() == T![input] { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GraphqlName::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if let Some(element) = ¤t_element { - if GraphqlDirectiveList::can_cast(element.kind()) { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); - if current_element.is_some() { - return RawSyntaxNode::new( - GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION.to_bogus(), - children.into_iter().map(Some), - ); - } - slots.into_node(GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION, children) - } - GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION_WITH_FIELDS => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<5usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -1003,11 +962,11 @@ impl SyntaxFactory for GraphqlSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION_WITH_FIELDS.to_bogus(), + GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION_WITH_FIELDS, children) + slots.into_node(GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION, children) } GRAPHQL_INPUT_VALUE_DEFINITION => { let mut elements = (&children).into_iter(); diff --git a/crates/biome_graphql_parser/src/parser/definitions/input_object.rs b/crates/biome_graphql_parser/src/parser/definitions/input_object.rs index d4ac9a1fc8b5..1987415e776f 100644 --- a/crates/biome_graphql_parser/src/parser/definitions/input_object.rs +++ b/crates/biome_graphql_parser/src/parser/definitions/input_object.rs @@ -1,6 +1,8 @@ use crate::parser::{ - directive::DirectiveList, parse_description, parse_error::expected_name, parse_name, - GraphqlParser, + directive::DirectiveList, + parse_description, + parse_error::{expected_input_object_extension, expected_name}, + parse_name, GraphqlParser, }; use biome_graphql_syntax::{ GraphqlSyntaxKind::{self, *}, @@ -32,6 +34,28 @@ pub(crate) fn parse_input_object_type_definition(p: &mut GraphqlParser) -> Parse Present(m.complete(p, GRAPHQL_INPUT_OBJECT_TYPE_DEFINITION)) } +/// Must only be called if the next 2 token is `extend` and `input`, otherwise it will panic. +#[inline] +pub(crate) fn parse_input_object_type_extension(p: &mut GraphqlParser) -> ParsedSyntax { + let m = p.start(); + + p.bump(T![extend]); + p.expect(T![input]); + + parse_name(p).or_add_diagnostic(p, expected_name); + + let directive_list = DirectiveList.parse_list(p); + let directive_empty = directive_list.range(p).is_empty(); + + let input_fields_empty = parse_input_fields_definition(p).is_absent(); + + if directive_empty && input_fields_empty { + p.error(expected_input_object_extension(p, p.cur_range())); + } + + Present(m.complete(p, GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION)) +} + #[inline] fn parse_input_fields_definition(p: &mut GraphqlParser) -> ParsedSyntax { if !is_at_input_fields_definition(p) { diff --git a/crates/biome_graphql_parser/src/parser/definitions/mod.rs b/crates/biome_graphql_parser/src/parser/definitions/mod.rs index e7d078b180ae..f7a4317c017a 100644 --- a/crates/biome_graphql_parser/src/parser/definitions/mod.rs +++ b/crates/biome_graphql_parser/src/parser/definitions/mod.rs @@ -23,7 +23,7 @@ use biome_parser::{ use self::{ directive::parse_directive_definition, fragment::parse_fragment_definition, - input_object::parse_input_object_type_definition, + input_object::{parse_input_object_type_definition, parse_input_object_type_extension}, interface::{parse_interface_type_definition, parse_interface_type_extension}, object::{parse_object_type_definition, parse_object_type_extension}, operation::{parse_operation_definition, parse_selection_set}, @@ -102,6 +102,7 @@ fn parse_extension(p: &mut GraphqlParser) -> ParsedSyntax { T![interface] => parse_interface_type_extension(p), T![union] => parse_union_type_extension(p), T![enum] => parse_enum_type_extension(p), + T![input] => parse_input_object_type_extension(p), _ => Absent, } } diff --git a/crates/biome_graphql_parser/src/parser/parse_error.rs b/crates/biome_graphql_parser/src/parser/parse_error.rs index 5d3050aa2836..9b1f51bc5af8 100644 --- a/crates/biome_graphql_parser/src/parser/parse_error.rs +++ b/crates/biome_graphql_parser/src/parser/parse_error.rs @@ -127,3 +127,13 @@ pub(crate) fn expected_enum_extension(p: &GraphqlParser, range: TextRange) -> Pa range, ) } + +pub(crate) fn expected_input_object_extension( + p: &GraphqlParser, + range: TextRange, +) -> ParseDiagnostic { + p.err_builder( + "Expected at least one directive or a set of fields definition", + range, + ) +} diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/input_object_extension.graphql b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/input_object_extension.graphql new file mode 100644 index 000000000000..2fb853766f1a --- /dev/null +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/input_object_extension.graphql @@ -0,0 +1,6 @@ +extend input Point2D + +extend input Point2D + x: Float + y: Float +} diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/input_object_extension.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/input_object_extension.graphql.snap new file mode 100644 index 000000000000..e01e0b0fcf23 --- /dev/null +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/input_object_extension.graphql.snap @@ -0,0 +1,151 @@ +--- +source: crates/biome_graphql_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```graphql +extend input Point2D + +extend input Point2D + x: Float + y: Float +} + +``` + +## AST + +``` +GraphqlRoot { + bom_token: missing (optional), + definitions: GraphqlDefinitionList [ + GraphqlInputObjectTypeExtension { + extend_token: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")], + input_token: INPUT_KW@7..13 "input" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@13..20 "Point2D" [] [], + }, + directives: GraphqlDirectiveList [], + input_fields: missing (optional), + }, + GraphqlInputObjectTypeExtension { + extend_token: EXTEND_KW@20..29 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + input_token: INPUT_KW@29..35 "input" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@35..42 "Point2D" [] [], + }, + directives: GraphqlDirectiveList [], + input_fields: GraphqlInputFieldsDefinition { + l_curly_token: missing (required), + fields: GraphqlInputFieldList [ + GraphqlInputValueDefinition { + description: missing (optional), + name: GraphqlName { + value_token: GRAPHQL_NAME@42..46 "x" [Newline("\n"), Whitespace(" ")] [], + }, + colon_token: COLON@46..48 ":" [] [Whitespace(" ")], + ty: GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@48..53 "Float" [] [], + }, + }, + default: missing (optional), + directives: GraphqlDirectiveList [], + }, + GraphqlInputValueDefinition { + description: missing (optional), + name: GraphqlName { + value_token: GRAPHQL_NAME@53..57 "y" [Newline("\n"), Whitespace(" ")] [], + }, + colon_token: COLON@57..59 ":" [] [Whitespace(" ")], + ty: GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@59..64 "Float" [] [], + }, + }, + default: missing (optional), + directives: GraphqlDirectiveList [], + }, + ], + r_curly_token: R_CURLY@64..66 "}" [Newline("\n")] [], + }, + }, + ], + eof_token: EOF@66..67 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRAPHQL_ROOT@0..67 + 0: (empty) + 1: GRAPHQL_DEFINITION_LIST@0..66 + 0: GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION@0..20 + 0: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")] + 1: INPUT_KW@7..13 "input" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@13..20 + 0: GRAPHQL_NAME@13..20 "Point2D" [] [] + 3: GRAPHQL_DIRECTIVE_LIST@20..20 + 4: (empty) + 1: GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION@20..66 + 0: EXTEND_KW@20..29 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: INPUT_KW@29..35 "input" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@35..42 + 0: GRAPHQL_NAME@35..42 "Point2D" [] [] + 3: GRAPHQL_DIRECTIVE_LIST@42..42 + 4: GRAPHQL_INPUT_FIELDS_DEFINITION@42..66 + 0: (empty) + 1: GRAPHQL_INPUT_FIELD_LIST@42..64 + 0: GRAPHQL_INPUT_VALUE_DEFINITION@42..53 + 0: (empty) + 1: GRAPHQL_NAME@42..46 + 0: GRAPHQL_NAME@42..46 "x" [Newline("\n"), Whitespace(" ")] [] + 2: COLON@46..48 ":" [] [Whitespace(" ")] + 3: GRAPHQL_NAMED_TYPE@48..53 + 0: GRAPHQL_NAME@48..53 + 0: GRAPHQL_NAME@48..53 "Float" [] [] + 4: (empty) + 5: GRAPHQL_DIRECTIVE_LIST@53..53 + 1: GRAPHQL_INPUT_VALUE_DEFINITION@53..64 + 0: (empty) + 1: GRAPHQL_NAME@53..57 + 0: GRAPHQL_NAME@53..57 "y" [Newline("\n"), Whitespace(" ")] [] + 2: COLON@57..59 ":" [] [Whitespace(" ")] + 3: GRAPHQL_NAMED_TYPE@59..64 + 0: GRAPHQL_NAME@59..64 + 0: GRAPHQL_NAME@59..64 "Float" [] [] + 4: (empty) + 5: GRAPHQL_DIRECTIVE_LIST@64..64 + 2: R_CURLY@64..66 "}" [Newline("\n")] [] + 2: EOF@66..67 "" [Newline("\n")] [] + +``` + +## Diagnostics + +``` +input_object_extension.graphql:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected at least one directive or a set of fields definition + + 1 │ extend input Point2D + 2 │ + > 3 │ extend input Point2D + │ ^^^^^^ + 4 │ x: Float + 5 │ y: Float + +input_object_extension.graphql:4:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `{` but instead found `x` + + 3 │ extend input Point2D + > 4 │ x: Float + │ ^ + 5 │ y: Float + 6 │ } + + i Remove x + +``` diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/schema_extension.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/schema_extension.graphql.snap index d996f5078638..833c9a9af17e 100644 --- a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/schema_extension.graphql.snap +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/schema_extension.graphql.snap @@ -25,7 +25,7 @@ GraphqlRoot { extend_token: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")], schema_token: SCHEMA_KW@7..13 "schema" [] [], directives: GraphqlDirectiveList [], - root_operation_types: missing (required), + root_operation_types: missing (optional), }, GraphqlSchemaExtension { extend_token: EXTEND_KW@13..22 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/input_object_extension.graphql b/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/input_object_extension.graphql new file mode 100644 index 000000000000..0ba7a2fc0c22 --- /dev/null +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/input_object_extension.graphql @@ -0,0 +1,11 @@ +extend input Point2D { + x: Float + y: Float +} + +extend input Point2D @deprecated + +extend input Point2D @deprecated { + x: Float + y: Float +} diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/input_object_extension.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/input_object_extension.graphql.snap new file mode 100644 index 000000000000..f6c805d074f8 --- /dev/null +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/input_object_extension.graphql.snap @@ -0,0 +1,226 @@ +--- +source: crates/biome_graphql_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```graphql +extend input Point2D { + x: Float + y: Float +} + +extend input Point2D @deprecated + +extend input Point2D @deprecated { + x: Float + y: Float +} + +``` + +## AST + +``` +GraphqlRoot { + bom_token: missing (optional), + definitions: GraphqlDefinitionList [ + GraphqlInputObjectTypeExtension { + extend_token: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")], + input_token: INPUT_KW@7..13 "input" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@13..21 "Point2D" [] [Whitespace(" ")], + }, + directives: GraphqlDirectiveList [], + input_fields: GraphqlInputFieldsDefinition { + l_curly_token: L_CURLY@21..22 "{" [] [], + fields: GraphqlInputFieldList [ + GraphqlInputValueDefinition { + description: missing (optional), + name: GraphqlName { + value_token: GRAPHQL_NAME@22..26 "x" [Newline("\n"), Whitespace(" ")] [], + }, + colon_token: COLON@26..28 ":" [] [Whitespace(" ")], + ty: GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@28..33 "Float" [] [], + }, + }, + default: missing (optional), + directives: GraphqlDirectiveList [], + }, + GraphqlInputValueDefinition { + description: missing (optional), + name: GraphqlName { + value_token: GRAPHQL_NAME@33..37 "y" [Newline("\n"), Whitespace(" ")] [], + }, + colon_token: COLON@37..39 ":" [] [Whitespace(" ")], + ty: GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@39..44 "Float" [] [], + }, + }, + default: missing (optional), + directives: GraphqlDirectiveList [], + }, + ], + r_curly_token: R_CURLY@44..46 "}" [Newline("\n")] [], + }, + }, + GraphqlInputObjectTypeExtension { + extend_token: EXTEND_KW@46..55 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + input_token: INPUT_KW@55..61 "input" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@61..69 "Point2D" [] [Whitespace(" ")], + }, + directives: GraphqlDirectiveList [ + GraphqlDirective { + at_token: AT@69..70 "@" [] [], + name: GraphqlName { + value_token: GRAPHQL_NAME@70..80 "deprecated" [] [], + }, + arguments: missing (optional), + }, + ], + input_fields: missing (optional), + }, + GraphqlInputObjectTypeExtension { + extend_token: EXTEND_KW@80..89 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + input_token: INPUT_KW@89..95 "input" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@95..103 "Point2D" [] [Whitespace(" ")], + }, + directives: GraphqlDirectiveList [ + GraphqlDirective { + at_token: AT@103..104 "@" [] [], + name: GraphqlName { + value_token: GRAPHQL_NAME@104..115 "deprecated" [] [Whitespace(" ")], + }, + arguments: missing (optional), + }, + ], + input_fields: GraphqlInputFieldsDefinition { + l_curly_token: L_CURLY@115..116 "{" [] [], + fields: GraphqlInputFieldList [ + GraphqlInputValueDefinition { + description: missing (optional), + name: GraphqlName { + value_token: GRAPHQL_NAME@116..120 "x" [Newline("\n"), Whitespace(" ")] [], + }, + colon_token: COLON@120..122 ":" [] [Whitespace(" ")], + ty: GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@122..127 "Float" [] [], + }, + }, + default: missing (optional), + directives: GraphqlDirectiveList [], + }, + GraphqlInputValueDefinition { + description: missing (optional), + name: GraphqlName { + value_token: GRAPHQL_NAME@127..131 "y" [Newline("\n"), Whitespace(" ")] [], + }, + colon_token: COLON@131..133 ":" [] [Whitespace(" ")], + ty: GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@133..138 "Float" [] [], + }, + }, + default: missing (optional), + directives: GraphqlDirectiveList [], + }, + ], + r_curly_token: R_CURLY@138..140 "}" [Newline("\n")] [], + }, + }, + ], + eof_token: EOF@140..141 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRAPHQL_ROOT@0..141 + 0: (empty) + 1: GRAPHQL_DEFINITION_LIST@0..140 + 0: GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION@0..46 + 0: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")] + 1: INPUT_KW@7..13 "input" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@13..21 + 0: GRAPHQL_NAME@13..21 "Point2D" [] [Whitespace(" ")] + 3: GRAPHQL_DIRECTIVE_LIST@21..21 + 4: GRAPHQL_INPUT_FIELDS_DEFINITION@21..46 + 0: L_CURLY@21..22 "{" [] [] + 1: GRAPHQL_INPUT_FIELD_LIST@22..44 + 0: GRAPHQL_INPUT_VALUE_DEFINITION@22..33 + 0: (empty) + 1: GRAPHQL_NAME@22..26 + 0: GRAPHQL_NAME@22..26 "x" [Newline("\n"), Whitespace(" ")] [] + 2: COLON@26..28 ":" [] [Whitespace(" ")] + 3: GRAPHQL_NAMED_TYPE@28..33 + 0: GRAPHQL_NAME@28..33 + 0: GRAPHQL_NAME@28..33 "Float" [] [] + 4: (empty) + 5: GRAPHQL_DIRECTIVE_LIST@33..33 + 1: GRAPHQL_INPUT_VALUE_DEFINITION@33..44 + 0: (empty) + 1: GRAPHQL_NAME@33..37 + 0: GRAPHQL_NAME@33..37 "y" [Newline("\n"), Whitespace(" ")] [] + 2: COLON@37..39 ":" [] [Whitespace(" ")] + 3: GRAPHQL_NAMED_TYPE@39..44 + 0: GRAPHQL_NAME@39..44 + 0: GRAPHQL_NAME@39..44 "Float" [] [] + 4: (empty) + 5: GRAPHQL_DIRECTIVE_LIST@44..44 + 2: R_CURLY@44..46 "}" [Newline("\n")] [] + 1: GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION@46..80 + 0: EXTEND_KW@46..55 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: INPUT_KW@55..61 "input" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@61..69 + 0: GRAPHQL_NAME@61..69 "Point2D" [] [Whitespace(" ")] + 3: GRAPHQL_DIRECTIVE_LIST@69..80 + 0: GRAPHQL_DIRECTIVE@69..80 + 0: AT@69..70 "@" [] [] + 1: GRAPHQL_NAME@70..80 + 0: GRAPHQL_NAME@70..80 "deprecated" [] [] + 2: (empty) + 4: (empty) + 2: GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION@80..140 + 0: EXTEND_KW@80..89 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: INPUT_KW@89..95 "input" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@95..103 + 0: GRAPHQL_NAME@95..103 "Point2D" [] [Whitespace(" ")] + 3: GRAPHQL_DIRECTIVE_LIST@103..115 + 0: GRAPHQL_DIRECTIVE@103..115 + 0: AT@103..104 "@" [] [] + 1: GRAPHQL_NAME@104..115 + 0: GRAPHQL_NAME@104..115 "deprecated" [] [Whitespace(" ")] + 2: (empty) + 4: GRAPHQL_INPUT_FIELDS_DEFINITION@115..140 + 0: L_CURLY@115..116 "{" [] [] + 1: GRAPHQL_INPUT_FIELD_LIST@116..138 + 0: GRAPHQL_INPUT_VALUE_DEFINITION@116..127 + 0: (empty) + 1: GRAPHQL_NAME@116..120 + 0: GRAPHQL_NAME@116..120 "x" [Newline("\n"), Whitespace(" ")] [] + 2: COLON@120..122 ":" [] [Whitespace(" ")] + 3: GRAPHQL_NAMED_TYPE@122..127 + 0: GRAPHQL_NAME@122..127 + 0: GRAPHQL_NAME@122..127 "Float" [] [] + 4: (empty) + 5: GRAPHQL_DIRECTIVE_LIST@127..127 + 1: GRAPHQL_INPUT_VALUE_DEFINITION@127..138 + 0: (empty) + 1: GRAPHQL_NAME@127..131 + 0: GRAPHQL_NAME@127..131 "y" [Newline("\n"), Whitespace(" ")] [] + 2: COLON@131..133 ":" [] [Whitespace(" ")] + 3: GRAPHQL_NAMED_TYPE@133..138 + 0: GRAPHQL_NAME@133..138 + 0: GRAPHQL_NAME@133..138 "Float" [] [] + 4: (empty) + 5: GRAPHQL_DIRECTIVE_LIST@138..138 + 2: R_CURLY@138..140 "}" [Newline("\n")] [] + 2: EOF@140..141 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_graphql_syntax/src/generated/kind.rs b/crates/biome_graphql_syntax/src/generated/kind.rs index 6dcf00728880..b0baddafd6fa 100644 --- a/crates/biome_graphql_syntax/src/generated/kind.rs +++ b/crates/biome_graphql_syntax/src/generated/kind.rs @@ -136,11 +136,9 @@ pub enum GraphqlSyntaxKind { GRAPHQL_ENUM_VALUES_DEFINITION, GRAPHQL_ENUM_VALUE_LIST, GRAPHQL_ENUM_VALUE_DEFINITION, - GRAPHQL_ENUM_TYPE_EXTENSION_WITH_VALUES, GRAPHQL_ENUM_TYPE_EXTENSION, GRAPHQL_INPUT_FIELDS_DEFINITION, GRAPHQL_INPUT_FIELD_LIST, - GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION_WITH_FIELDS, GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION, GRAPHQL_DIRECTIVE_LOCATION_LIST, GRAPHQL_DIRECTIVE_LOCATION, @@ -154,7 +152,6 @@ pub enum GraphqlSyntaxKind { GRAPHQL_BOGUS_SELECTION, GRAPHQL_BOGUS_VALUE, GRAPHQL_BOGUS_TYPE, - GRAPHQL_BOGUS_EXTENSION, #[doc(hidden)] __LAST, } diff --git a/crates/biome_graphql_syntax/src/generated/macros.rs b/crates/biome_graphql_syntax/src/generated/macros.rs index dd93b3691e3e..ab1a6b67bb8b 100644 --- a/crates/biome_graphql_syntax/src/generated/macros.rs +++ b/crates/biome_graphql_syntax/src/generated/macros.rs @@ -130,12 +130,6 @@ macro_rules! map_syntax_node { unsafe { $crate::GraphqlInputObjectTypeExtension::new_unchecked(node) }; $body } - $crate::GraphqlSyntaxKind::GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION_WITH_FIELDS => { - let $pattern = unsafe { - $crate::GraphqlInputObjectTypeExtensionWithFields::new_unchecked(node) - }; - $body - } $crate::GraphqlSyntaxKind::GRAPHQL_INPUT_VALUE_DEFINITION => { let $pattern = unsafe { $crate::GraphqlInputValueDefinition::new_unchecked(node) }; @@ -286,10 +280,6 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GraphqlBogusDefinition::new_unchecked(node) }; $body } - $crate::GraphqlSyntaxKind::GRAPHQL_BOGUS_EXTENSION => { - let $pattern = unsafe { $crate::GraphqlBogusExtension::new_unchecked(node) }; - $body - } $crate::GraphqlSyntaxKind::GRAPHQL_BOGUS_SELECTION => { let $pattern = unsafe { $crate::GraphqlBogusSelection::new_unchecked(node) }; $body diff --git a/crates/biome_graphql_syntax/src/generated/nodes.rs b/crates/biome_graphql_syntax/src/generated/nodes.rs index 482ecffe6ab4..c75a34c5337e 100644 --- a/crates/biome_graphql_syntax/src/generated/nodes.rs +++ b/crates/biome_graphql_syntax/src/generated/nodes.rs @@ -1235,57 +1235,6 @@ impl GraphqlInputObjectTypeExtension { input_token: self.input_token(), name: self.name(), directives: self.directives(), - } - } - pub fn extend_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 0usize) - } - pub fn input_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 1usize) - } - pub fn name(&self) -> SyntaxResult { - support::required_node(&self.syntax, 2usize) - } - pub fn directives(&self) -> GraphqlDirectiveList { - support::list(&self.syntax, 3usize) - } -} -#[cfg(feature = "serde")] -impl Serialize for GraphqlInputObjectTypeExtension { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - self.as_fields().serialize(serializer) - } -} -#[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GraphqlInputObjectTypeExtensionFields { - pub extend_token: SyntaxResult, - pub input_token: SyntaxResult, - pub name: SyntaxResult, - pub directives: GraphqlDirectiveList, -} -#[derive(Clone, PartialEq, Eq, Hash)] -pub struct GraphqlInputObjectTypeExtensionWithFields { - pub(crate) syntax: SyntaxNode, -} -impl GraphqlInputObjectTypeExtensionWithFields { - #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] - #[doc = r""] - #[doc = r" # Safety"] - #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] - #[doc = r" or a match on [SyntaxNode::kind]"] - #[inline] - pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { - Self { syntax } - } - pub fn as_fields(&self) -> GraphqlInputObjectTypeExtensionWithFieldsFields { - GraphqlInputObjectTypeExtensionWithFieldsFields { - extend_token: self.extend_token(), - input_token: self.input_token(), - name: self.name(), - directives: self.directives(), input_fields: self.input_fields(), } } @@ -1301,12 +1250,12 @@ impl GraphqlInputObjectTypeExtensionWithFields { pub fn directives(&self) -> GraphqlDirectiveList { support::list(&self.syntax, 3usize) } - pub fn input_fields(&self) -> SyntaxResult { - support::required_node(&self.syntax, 4usize) + pub fn input_fields(&self) -> Option { + support::node(&self.syntax, 4usize) } } #[cfg(feature = "serde")] -impl Serialize for GraphqlInputObjectTypeExtensionWithFields { +impl Serialize for GraphqlInputObjectTypeExtension { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -1315,12 +1264,12 @@ impl Serialize for GraphqlInputObjectTypeExtensionWithFields { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GraphqlInputObjectTypeExtensionWithFieldsFields { +pub struct GraphqlInputObjectTypeExtensionFields { pub extend_token: SyntaxResult, pub input_token: SyntaxResult, pub name: SyntaxResult, pub directives: GraphqlDirectiveList, - pub input_fields: SyntaxResult, + pub input_fields: Option, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GraphqlInputValueDefinition { @@ -2408,8 +2357,8 @@ impl GraphqlSchemaExtension { pub fn directives(&self) -> GraphqlDirectiveList { support::list(&self.syntax, 2usize) } - pub fn root_operation_types(&self) -> SyntaxResult { - support::required_node(&self.syntax, 3usize) + pub fn root_operation_types(&self) -> Option { + support::node(&self.syntax, 3usize) } } #[cfg(feature = "serde")] @@ -2426,7 +2375,7 @@ pub struct GraphqlSchemaExtensionFields { pub extend_token: SyntaxResult, pub schema_token: SyntaxResult, pub directives: GraphqlDirectiveList, - pub root_operation_types: SyntaxResult, + pub root_operation_types: Option, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GraphqlSelectionSet { @@ -2855,7 +2804,6 @@ pub struct GraphqlVariableDefinitionsFields { #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyGraphqlDefinition { - AnyGraphqlInputObjectTypeExtension(AnyGraphqlInputObjectTypeExtension), AnyGraphqlOperationDefinition(AnyGraphqlOperationDefinition), GraphqlBogusDefinition(GraphqlBogusDefinition), GraphqlDirectiveDefinition(GraphqlDirectiveDefinition), @@ -2863,6 +2811,7 @@ pub enum AnyGraphqlDefinition { GraphqlEnumTypeExtension(GraphqlEnumTypeExtension), GraphqlFragmentDefinition(GraphqlFragmentDefinition), GraphqlInputObjectTypeDefinition(GraphqlInputObjectTypeDefinition), + GraphqlInputObjectTypeExtension(GraphqlInputObjectTypeExtension), GraphqlInterfaceTypeDefinition(GraphqlInterfaceTypeDefinition), GraphqlInterfaceTypeExtension(GraphqlInterfaceTypeExtension), GraphqlObjectTypeDefinition(GraphqlObjectTypeDefinition), @@ -2875,14 +2824,6 @@ pub enum AnyGraphqlDefinition { GraphqlUnionTypeExtension(GraphqlUnionTypeExtension), } impl AnyGraphqlDefinition { - pub fn as_any_graphql_input_object_type_extension( - &self, - ) -> Option<&AnyGraphqlInputObjectTypeExtension> { - match &self { - AnyGraphqlDefinition::AnyGraphqlInputObjectTypeExtension(item) => Some(item), - _ => None, - } - } pub fn as_any_graphql_operation_definition(&self) -> Option<&AnyGraphqlOperationDefinition> { match &self { AnyGraphqlDefinition::AnyGraphqlOperationDefinition(item) => Some(item), @@ -2927,6 +2868,14 @@ impl AnyGraphqlDefinition { _ => None, } } + pub fn as_graphql_input_object_type_extension( + &self, + ) -> Option<&GraphqlInputObjectTypeExtension> { + match &self { + AnyGraphqlDefinition::GraphqlInputObjectTypeExtension(item) => Some(item), + _ => None, + } + } pub fn as_graphql_interface_type_definition(&self) -> Option<&GraphqlInterfaceTypeDefinition> { match &self { AnyGraphqlDefinition::GraphqlInterfaceTypeDefinition(item) => Some(item), @@ -2990,39 +2939,6 @@ impl AnyGraphqlDefinition { } #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] -pub enum AnyGraphqlInputObjectTypeExtension { - GraphqlBogusExtension(GraphqlBogusExtension), - GraphqlInputObjectTypeExtension(GraphqlInputObjectTypeExtension), - GraphqlInputObjectTypeExtensionWithFields(GraphqlInputObjectTypeExtensionWithFields), -} -impl AnyGraphqlInputObjectTypeExtension { - pub fn as_graphql_bogus_extension(&self) -> Option<&GraphqlBogusExtension> { - match &self { - AnyGraphqlInputObjectTypeExtension::GraphqlBogusExtension(item) => Some(item), - _ => None, - } - } - pub fn as_graphql_input_object_type_extension( - &self, - ) -> Option<&GraphqlInputObjectTypeExtension> { - match &self { - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtension(item) => Some(item), - _ => None, - } - } - pub fn as_graphql_input_object_type_extension_with_fields( - &self, - ) -> Option<&GraphqlInputObjectTypeExtensionWithFields> { - match &self { - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtensionWithFields(item) => { - Some(item) - } - _ => None, - } - } -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyGraphqlOperationDefinition { GraphqlOperationDefinition(GraphqlOperationDefinition), GraphqlSelectionSet(GraphqlSelectionSet), @@ -4375,6 +4291,10 @@ impl std::fmt::Debug for GraphqlInputObjectTypeExtension { ) .field("name", &support::DebugSyntaxResult(self.name())) .field("directives", &self.directives()) + .field( + "input_fields", + &support::DebugOptionalElement(self.input_fields()), + ) .finish() } } @@ -4388,58 +4308,6 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GraphqlInputObjectTypeExtensionWithFields { - type Language = Language; - const KIND_SET: SyntaxKindSet = SyntaxKindSet::from_raw(RawSyntaxKind( - GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION_WITH_FIELDS as u16, - )); - fn can_cast(kind: SyntaxKind) -> bool { - kind == GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION_WITH_FIELDS - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } - fn into_syntax(self) -> SyntaxNode { - self.syntax - } -} -impl std::fmt::Debug for GraphqlInputObjectTypeExtensionWithFields { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GraphqlInputObjectTypeExtensionWithFields") - .field( - "extend_token", - &support::DebugSyntaxResult(self.extend_token()), - ) - .field( - "input_token", - &support::DebugSyntaxResult(self.input_token()), - ) - .field("name", &support::DebugSyntaxResult(self.name())) - .field("directives", &self.directives()) - .field( - "input_fields", - &support::DebugSyntaxResult(self.input_fields()), - ) - .finish() - } -} -impl From for SyntaxNode { - fn from(n: GraphqlInputObjectTypeExtensionWithFields) -> SyntaxNode { - n.syntax - } -} -impl From for SyntaxElement { - fn from(n: GraphqlInputObjectTypeExtensionWithFields) -> SyntaxElement { - n.syntax.into() - } -} impl AstNode for GraphqlInputValueDefinition { type Language = Language; const KIND_SET: SyntaxKindSet = @@ -5472,7 +5340,7 @@ impl std::fmt::Debug for GraphqlSchemaExtension { .field("directives", &self.directives()) .field( "root_operation_types", - &support::DebugSyntaxResult(self.root_operation_types()), + &support::DebugOptionalElement(self.root_operation_types()), ) .finish() } @@ -5921,6 +5789,11 @@ impl From for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlInputObjectTypeDefinition(node) } } +impl From for AnyGraphqlDefinition { + fn from(node: GraphqlInputObjectTypeExtension) -> AnyGraphqlDefinition { + AnyGraphqlDefinition::GraphqlInputObjectTypeExtension(node) + } +} impl From for AnyGraphqlDefinition { fn from(node: GraphqlInterfaceTypeDefinition) -> AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlInterfaceTypeDefinition(node) @@ -5973,14 +5846,14 @@ impl From for AnyGraphqlDefinition { } impl AstNode for AnyGraphqlDefinition { type Language = Language; - const KIND_SET: SyntaxKindSet = AnyGraphqlInputObjectTypeExtension::KIND_SET - .union(AnyGraphqlOperationDefinition::KIND_SET) + const KIND_SET: SyntaxKindSet = AnyGraphqlOperationDefinition::KIND_SET .union(GraphqlBogusDefinition::KIND_SET) .union(GraphqlDirectiveDefinition::KIND_SET) .union(GraphqlEnumTypeDefinition::KIND_SET) .union(GraphqlEnumTypeExtension::KIND_SET) .union(GraphqlFragmentDefinition::KIND_SET) .union(GraphqlInputObjectTypeDefinition::KIND_SET) + .union(GraphqlInputObjectTypeExtension::KIND_SET) .union(GraphqlInterfaceTypeDefinition::KIND_SET) .union(GraphqlInterfaceTypeExtension::KIND_SET) .union(GraphqlObjectTypeDefinition::KIND_SET) @@ -5999,6 +5872,7 @@ impl AstNode for AnyGraphqlDefinition { | GRAPHQL_ENUM_TYPE_EXTENSION | GRAPHQL_FRAGMENT_DEFINITION | GRAPHQL_INPUT_OBJECT_TYPE_DEFINITION + | GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION | GRAPHQL_INTERFACE_TYPE_DEFINITION | GRAPHQL_INTERFACE_TYPE_EXTENSION | GRAPHQL_OBJECT_TYPE_DEFINITION @@ -6009,7 +5883,6 @@ impl AstNode for AnyGraphqlDefinition { | GRAPHQL_SCHEMA_EXTENSION | GRAPHQL_UNION_TYPE_DEFINITION | GRAPHQL_UNION_TYPE_EXTENSION => true, - k if AnyGraphqlInputObjectTypeExtension::can_cast(k) => true, k if AnyGraphqlOperationDefinition::can_cast(k) => true, _ => false, } @@ -6042,6 +5915,11 @@ impl AstNode for AnyGraphqlDefinition { GraphqlInputObjectTypeDefinition { syntax }, ) } + GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION => { + AnyGraphqlDefinition::GraphqlInputObjectTypeExtension( + GraphqlInputObjectTypeExtension { syntax }, + ) + } GRAPHQL_INTERFACE_TYPE_DEFINITION => { AnyGraphqlDefinition::GraphqlInterfaceTypeDefinition( GraphqlInterfaceTypeDefinition { syntax }, @@ -6089,13 +5967,6 @@ impl AstNode for AnyGraphqlDefinition { }) } _ => { - if let Some(any_graphql_input_object_type_extension) = - AnyGraphqlInputObjectTypeExtension::cast(syntax.clone()) - { - return Some(AnyGraphqlDefinition::AnyGraphqlInputObjectTypeExtension( - any_graphql_input_object_type_extension, - )); - } if let Some(any_graphql_operation_definition) = AnyGraphqlOperationDefinition::cast(syntax) { @@ -6116,6 +5987,7 @@ impl AstNode for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlEnumTypeExtension(it) => &it.syntax, AnyGraphqlDefinition::GraphqlFragmentDefinition(it) => &it.syntax, AnyGraphqlDefinition::GraphqlInputObjectTypeDefinition(it) => &it.syntax, + AnyGraphqlDefinition::GraphqlInputObjectTypeExtension(it) => &it.syntax, AnyGraphqlDefinition::GraphqlInterfaceTypeDefinition(it) => &it.syntax, AnyGraphqlDefinition::GraphqlInterfaceTypeExtension(it) => &it.syntax, AnyGraphqlDefinition::GraphqlObjectTypeDefinition(it) => &it.syntax, @@ -6126,7 +5998,6 @@ impl AstNode for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlSchemaExtension(it) => &it.syntax, AnyGraphqlDefinition::GraphqlUnionTypeDefinition(it) => &it.syntax, AnyGraphqlDefinition::GraphqlUnionTypeExtension(it) => &it.syntax, - AnyGraphqlDefinition::AnyGraphqlInputObjectTypeExtension(it) => it.syntax(), AnyGraphqlDefinition::AnyGraphqlOperationDefinition(it) => it.syntax(), } } @@ -6138,6 +6009,7 @@ impl AstNode for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlEnumTypeExtension(it) => it.syntax, AnyGraphqlDefinition::GraphqlFragmentDefinition(it) => it.syntax, AnyGraphqlDefinition::GraphqlInputObjectTypeDefinition(it) => it.syntax, + AnyGraphqlDefinition::GraphqlInputObjectTypeExtension(it) => it.syntax, AnyGraphqlDefinition::GraphqlInterfaceTypeDefinition(it) => it.syntax, AnyGraphqlDefinition::GraphqlInterfaceTypeExtension(it) => it.syntax, AnyGraphqlDefinition::GraphqlObjectTypeDefinition(it) => it.syntax, @@ -6148,7 +6020,6 @@ impl AstNode for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlSchemaExtension(it) => it.syntax, AnyGraphqlDefinition::GraphqlUnionTypeDefinition(it) => it.syntax, AnyGraphqlDefinition::GraphqlUnionTypeExtension(it) => it.syntax, - AnyGraphqlDefinition::AnyGraphqlInputObjectTypeExtension(it) => it.into_syntax(), AnyGraphqlDefinition::AnyGraphqlOperationDefinition(it) => it.into_syntax(), } } @@ -6156,9 +6027,6 @@ impl AstNode for AnyGraphqlDefinition { impl std::fmt::Debug for AnyGraphqlDefinition { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - AnyGraphqlDefinition::AnyGraphqlInputObjectTypeExtension(it) => { - std::fmt::Debug::fmt(it, f) - } AnyGraphqlDefinition::AnyGraphqlOperationDefinition(it) => std::fmt::Debug::fmt(it, f), AnyGraphqlDefinition::GraphqlBogusDefinition(it) => std::fmt::Debug::fmt(it, f), AnyGraphqlDefinition::GraphqlDirectiveDefinition(it) => std::fmt::Debug::fmt(it, f), @@ -6168,6 +6036,9 @@ impl std::fmt::Debug for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlInputObjectTypeDefinition(it) => { std::fmt::Debug::fmt(it, f) } + AnyGraphqlDefinition::GraphqlInputObjectTypeExtension(it) => { + std::fmt::Debug::fmt(it, f) + } AnyGraphqlDefinition::GraphqlInterfaceTypeDefinition(it) => std::fmt::Debug::fmt(it, f), AnyGraphqlDefinition::GraphqlInterfaceTypeExtension(it) => std::fmt::Debug::fmt(it, f), AnyGraphqlDefinition::GraphqlObjectTypeDefinition(it) => std::fmt::Debug::fmt(it, f), @@ -6184,7 +6055,6 @@ impl std::fmt::Debug for AnyGraphqlDefinition { impl From for SyntaxNode { fn from(n: AnyGraphqlDefinition) -> SyntaxNode { match n { - AnyGraphqlDefinition::AnyGraphqlInputObjectTypeExtension(it) => it.into(), AnyGraphqlDefinition::AnyGraphqlOperationDefinition(it) => it.into(), AnyGraphqlDefinition::GraphqlBogusDefinition(it) => it.into(), AnyGraphqlDefinition::GraphqlDirectiveDefinition(it) => it.into(), @@ -6192,6 +6062,7 @@ impl From for SyntaxNode { AnyGraphqlDefinition::GraphqlEnumTypeExtension(it) => it.into(), AnyGraphqlDefinition::GraphqlFragmentDefinition(it) => it.into(), AnyGraphqlDefinition::GraphqlInputObjectTypeDefinition(it) => it.into(), + AnyGraphqlDefinition::GraphqlInputObjectTypeExtension(it) => it.into(), AnyGraphqlDefinition::GraphqlInterfaceTypeDefinition(it) => it.into(), AnyGraphqlDefinition::GraphqlInterfaceTypeExtension(it) => it.into(), AnyGraphqlDefinition::GraphqlObjectTypeDefinition(it) => it.into(), @@ -6211,106 +6082,6 @@ impl From for SyntaxElement { node.into() } } -impl From for AnyGraphqlInputObjectTypeExtension { - fn from(node: GraphqlBogusExtension) -> AnyGraphqlInputObjectTypeExtension { - AnyGraphqlInputObjectTypeExtension::GraphqlBogusExtension(node) - } -} -impl From for AnyGraphqlInputObjectTypeExtension { - fn from(node: GraphqlInputObjectTypeExtension) -> AnyGraphqlInputObjectTypeExtension { - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtension(node) - } -} -impl From for AnyGraphqlInputObjectTypeExtension { - fn from(node: GraphqlInputObjectTypeExtensionWithFields) -> AnyGraphqlInputObjectTypeExtension { - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtensionWithFields(node) - } -} -impl AstNode for AnyGraphqlInputObjectTypeExtension { - type Language = Language; - const KIND_SET: SyntaxKindSet = GraphqlBogusExtension::KIND_SET - .union(GraphqlInputObjectTypeExtension::KIND_SET) - .union(GraphqlInputObjectTypeExtensionWithFields::KIND_SET); - fn can_cast(kind: SyntaxKind) -> bool { - matches!( - kind, - GRAPHQL_BOGUS_EXTENSION - | GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION - | GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION_WITH_FIELDS - ) - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - GRAPHQL_BOGUS_EXTENSION => { - AnyGraphqlInputObjectTypeExtension::GraphqlBogusExtension(GraphqlBogusExtension { - syntax, - }) - } - GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION => { - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtension( - GraphqlInputObjectTypeExtension { syntax }, - ) - } - GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION_WITH_FIELDS => { - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtensionWithFields( - GraphqlInputObjectTypeExtensionWithFields { syntax }, - ) - } - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - AnyGraphqlInputObjectTypeExtension::GraphqlBogusExtension(it) => &it.syntax, - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtension(it) => &it.syntax, - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtensionWithFields(it) => { - &it.syntax - } - } - } - fn into_syntax(self) -> SyntaxNode { - match self { - AnyGraphqlInputObjectTypeExtension::GraphqlBogusExtension(it) => it.syntax, - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtension(it) => it.syntax, - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtensionWithFields(it) => { - it.syntax - } - } - } -} -impl std::fmt::Debug for AnyGraphqlInputObjectTypeExtension { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - AnyGraphqlInputObjectTypeExtension::GraphqlBogusExtension(it) => { - std::fmt::Debug::fmt(it, f) - } - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtension(it) => { - std::fmt::Debug::fmt(it, f) - } - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtensionWithFields(it) => { - std::fmt::Debug::fmt(it, f) - } - } - } -} -impl From for SyntaxNode { - fn from(n: AnyGraphqlInputObjectTypeExtension) -> SyntaxNode { - match n { - AnyGraphqlInputObjectTypeExtension::GraphqlBogusExtension(it) => it.into(), - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtension(it) => it.into(), - AnyGraphqlInputObjectTypeExtension::GraphqlInputObjectTypeExtensionWithFields(it) => { - it.into() - } - } - } -} -impl From for SyntaxElement { - fn from(n: AnyGraphqlInputObjectTypeExtension) -> SyntaxElement { - let node: SyntaxNode = n.into(); - node.into() - } -} impl From for AnyGraphqlOperationDefinition { fn from(node: GraphqlOperationDefinition) -> AnyGraphqlOperationDefinition { AnyGraphqlOperationDefinition::GraphqlOperationDefinition(node) @@ -6786,11 +6557,6 @@ impl std::fmt::Display for AnyGraphqlDefinition { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for AnyGraphqlInputObjectTypeExtension { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for AnyGraphqlOperationDefinition { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -6946,11 +6712,6 @@ impl std::fmt::Display for GraphqlInputObjectTypeExtension { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GraphqlInputObjectTypeExtensionWithFields { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for GraphqlInputValueDefinition { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -7227,63 +6988,6 @@ impl From for SyntaxElement { } #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GraphqlBogusExtension { - syntax: SyntaxNode, -} -impl GraphqlBogusExtension { - #[doc = r" Create an AstNode from a SyntaxNode without checking its kind"] - #[doc = r""] - #[doc = r" # Safety"] - #[doc = r" This function must be guarded with a call to [AstNode::can_cast]"] - #[doc = r" or a match on [SyntaxNode::kind]"] - #[inline] - pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { - Self { syntax } - } - pub fn items(&self) -> SyntaxElementChildren { - support::elements(&self.syntax) - } -} -impl AstNode for GraphqlBogusExtension { - type Language = Language; - const KIND_SET: SyntaxKindSet = - SyntaxKindSet::from_raw(RawSyntaxKind(GRAPHQL_BOGUS_EXTENSION as u16)); - fn can_cast(kind: SyntaxKind) -> bool { - kind == GRAPHQL_BOGUS_EXTENSION - } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { - &self.syntax - } - fn into_syntax(self) -> SyntaxNode { - self.syntax - } -} -impl std::fmt::Debug for GraphqlBogusExtension { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GraphqlBogusExtension") - .field("items", &DebugSyntaxElementChildren(self.items())) - .finish() - } -} -impl From for SyntaxNode { - fn from(n: GraphqlBogusExtension) -> SyntaxNode { - n.syntax - } -} -impl From for SyntaxElement { - fn from(n: GraphqlBogusExtension) -> SyntaxElement { - n.syntax.into() - } -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] pub struct GraphqlBogusSelection { syntax: SyntaxNode, } diff --git a/crates/biome_graphql_syntax/src/generated/nodes_mut.rs b/crates/biome_graphql_syntax/src/generated/nodes_mut.rs index 630d41150fdd..32813e8c3118 100644 --- a/crates/biome_graphql_syntax/src/generated/nodes_mut.rs +++ b/crates/biome_graphql_syntax/src/generated/nodes_mut.rs @@ -576,37 +576,11 @@ impl GraphqlInputObjectTypeExtension { .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), ) } -} -impl GraphqlInputObjectTypeExtensionWithFields { - pub fn with_extend_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(0usize..=0usize, once(Some(element.into()))), - ) - } - pub fn with_input_token(self, element: SyntaxToken) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(1usize..=1usize, once(Some(element.into()))), - ) - } - pub fn with_name(self, element: GraphqlName) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_directives(self, element: GraphqlDirectiveList) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), - ) - } - pub fn with_input_fields(self, element: GraphqlInputFieldsDefinition) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(4usize..=4usize, once(Some(element.into_syntax().into()))), - ) + pub fn with_input_fields(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 4usize..=4usize, + once(element.map(|element| element.into_syntax().into())), + )) } } impl GraphqlInputValueDefinition { @@ -1122,11 +1096,11 @@ impl GraphqlSchemaExtension { .splice_slots(2usize..=2usize, once(Some(element.into_syntax().into()))), ) } - pub fn with_root_operation_types(self, element: GraphqlRootOperationTypes) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), - ) + pub fn with_root_operation_types(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 3usize..=3usize, + once(element.map(|element| element.into_syntax().into())), + )) } } impl GraphqlSelectionSet { diff --git a/crates/biome_graphql_syntax/src/lib.rs b/crates/biome_graphql_syntax/src/lib.rs index 631d13359e08..5f70663173a6 100644 --- a/crates/biome_graphql_syntax/src/lib.rs +++ b/crates/biome_graphql_syntax/src/lib.rs @@ -47,7 +47,6 @@ impl biome_rowan::SyntaxKind for GraphqlSyntaxKind { | GRAPHQL_BOGUS_SELECTION | GRAPHQL_BOGUS_VALUE | GRAPHQL_BOGUS_TYPE - | GRAPHQL_BOGUS_EXTENSION ) } @@ -57,7 +56,6 @@ impl biome_rowan::SyntaxKind for GraphqlSyntaxKind { kind if AnyGraphqlSelection::can_cast(*kind) => GRAPHQL_BOGUS_SELECTION, kind if AnyGraphqlValue::can_cast(*kind) => GRAPHQL_BOGUS_VALUE, kind if AnyGraphqlType::can_cast(*kind) => GRAPHQL_BOGUS_TYPE, - kind if AnyGraphqlInputObjectTypeExtension::can_cast(*kind) => GRAPHQL_BOGUS_EXTENSION, _ => GRAPHQL_BOGUS, } } diff --git a/xtask/codegen/graphql.ungram b/xtask/codegen/graphql.ungram index a7332c29ef75..e036f4818cc9 100644 --- a/xtask/codegen/graphql.ungram +++ b/xtask/codegen/graphql.ungram @@ -42,8 +42,6 @@ GraphqlBogusDefinition = SyntaxElement* GraphqlBogusSelection = SyntaxElement* GraphqlBogusValue = SyntaxElement* GraphqlBogusType = SyntaxElement* -// Extension that don't add anything -GraphqlBogusExtension = SyntaxElement* GraphqlName = value: 'graphql_name' @@ -74,7 +72,7 @@ AnyGraphqlDefinition = | GraphqlInterfaceTypeExtension | GraphqlUnionTypeExtension | GraphqlEnumTypeExtension - | AnyGraphqlInputObjectTypeExtension + | GraphqlInputObjectTypeExtension // https://spec.graphql.org/October2021/#sec-Language.Operations.Query-shorthand AnyGraphqlOperationDefinition = GraphqlOperationDefinition | GraphqlSelectionSet @@ -310,7 +308,7 @@ GraphqlSchemaExtension = 'extend' 'schema' directives: GraphqlDirectiveList - root_operation_types: GraphqlRootOperationTypes + root_operation_types: GraphqlRootOperationTypes? GraphqlRootOperationTypes = '{' @@ -521,25 +519,13 @@ GraphqlInputFieldsDefinition = GraphqlInputFieldList = GraphqlInputValueDefinition* // https://spec.graphql.org/October2021/#sec-Input-Object-Extensions -AnyGraphqlInputObjectTypeExtension = - GraphqlInputObjectTypeExtensionWithFields - | GraphqlInputObjectTypeExtension - | GraphqlBogusExtension - // extend input A @d { x: y } -GraphqlInputObjectTypeExtensionWithFields = - 'extend' - 'input' - name: GraphqlName - directives: GraphqlDirectiveList - input_fields: GraphqlInputFieldsDefinition - -// extend input A @d GraphqlInputObjectTypeExtension = 'extend' 'input' name: GraphqlName directives: GraphqlDirectiveList + input_fields: GraphqlInputFieldsDefinition? // directive @a(b: c) repeatable on // | QUERY diff --git a/xtask/codegen/src/graphql_kind_src.rs b/xtask/codegen/src/graphql_kind_src.rs index 9c7e8f802a42..e8632af1959c 100644 --- a/xtask/codegen/src/graphql_kind_src.rs +++ b/xtask/codegen/src/graphql_kind_src.rs @@ -133,11 +133,9 @@ pub const GRAPHQL_KINDS_SRC: KindsSrc = KindsSrc { "GRAPHQL_ENUM_VALUES_DEFINITION", "GRAPHQL_ENUM_VALUE_LIST", "GRAPHQL_ENUM_VALUE_DEFINITION", - "GRAPHQL_ENUM_TYPE_EXTENSION_WITH_VALUES", "GRAPHQL_ENUM_TYPE_EXTENSION", "GRAPHQL_INPUT_FIELDS_DEFINITION", "GRAPHQL_INPUT_FIELD_LIST", - "GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION_WITH_FIELDS", "GRAPHQL_INPUT_OBJECT_TYPE_EXTENSION", "GRAPHQL_DIRECTIVE_LOCATION_LIST", "GRAPHQL_DIRECTIVE_LOCATION", @@ -153,6 +151,5 @@ pub const GRAPHQL_KINDS_SRC: KindsSrc = KindsSrc { "GRAPHQL_BOGUS_SELECTION", "GRAPHQL_BOGUS_VALUE", "GRAPHQL_BOGUS_TYPE", - "GRAPHQL_BOGUS_EXTENSION", ], };