diff --git a/crates/biome_graphql_factory/src/generated/node_factory.rs b/crates/biome_graphql_factory/src/generated/node_factory.rs index 12bdcfae6936..4b1f2c42088e 100644 --- a/crates/biome_graphql_factory/src/generated/node_factory.rs +++ b/crates/biome_graphql_factory/src/generated/node_factory.rs @@ -233,34 +233,40 @@ pub fn graphql_enum_type_extension( enum_token: SyntaxToken, name: GraphqlName, directives: GraphqlDirectiveList, -) -> GraphqlEnumTypeExtension { - GraphqlEnumTypeExtension::unwrap_cast(SyntaxNode::new_detached( - GraphqlSyntaxKind::GRAPHQL_ENUM_TYPE_EXTENSION, - [ - Some(SyntaxElement::Token(extend_token)), - Some(SyntaxElement::Token(enum_token)), - Some(SyntaxElement::Node(name.into_syntax())), - Some(SyntaxElement::Node(directives.into_syntax())), - ], - )) +) -> GraphqlEnumTypeExtensionBuilder { + GraphqlEnumTypeExtensionBuilder { + extend_token, + enum_token, + name, + directives, + enum_values: None, + } } -pub fn graphql_enum_type_extension_with_values( +pub struct GraphqlEnumTypeExtensionBuilder { extend_token: SyntaxToken, enum_token: SyntaxToken, name: GraphqlName, directives: GraphqlDirectiveList, - enum_values: GraphqlEnumValuesDefinition, -) -> GraphqlEnumTypeExtensionWithValues { - GraphqlEnumTypeExtensionWithValues::unwrap_cast(SyntaxNode::new_detached( - GraphqlSyntaxKind::GRAPHQL_ENUM_TYPE_EXTENSION_WITH_VALUES, - [ - Some(SyntaxElement::Token(extend_token)), - Some(SyntaxElement::Token(enum_token)), - Some(SyntaxElement::Node(name.into_syntax())), - Some(SyntaxElement::Node(directives.into_syntax())), - Some(SyntaxElement::Node(enum_values.into_syntax())), - ], - )) + enum_values: Option, +} +impl GraphqlEnumTypeExtensionBuilder { + pub fn with_enum_values(mut self, enum_values: GraphqlEnumValuesDefinition) -> Self { + self.enum_values = Some(enum_values); + self + } + pub fn build(self) -> GraphqlEnumTypeExtension { + GraphqlEnumTypeExtension::unwrap_cast(SyntaxNode::new_detached( + GraphqlSyntaxKind::GRAPHQL_ENUM_TYPE_EXTENSION, + [ + Some(SyntaxElement::Token(self.extend_token)), + Some(SyntaxElement::Token(self.enum_token)), + Some(SyntaxElement::Node(self.name.into_syntax())), + Some(SyntaxElement::Node(self.directives.into_syntax())), + self.enum_values + .map(|token| SyntaxElement::Node(token.into_syntax())), + ], + )) + } } pub fn graphql_enum_value(graphql_name: GraphqlName) -> GraphqlEnumValue { GraphqlEnumValue::unwrap_cast(SyntaxNode::new_detached( diff --git a/crates/biome_graphql_factory/src/generated/syntax_factory.rs b/crates/biome_graphql_factory/src/generated/syntax_factory.rs index ee1e479cc616..c992fb95cc52 100644 --- a/crates/biome_graphql_factory/src/generated/syntax_factory.rs +++ b/crates/biome_graphql_factory/src/generated/syntax_factory.rs @@ -405,46 +405,6 @@ impl SyntaxFactory for GraphqlSyntaxFactory { slots.into_node(GRAPHQL_ENUM_TYPE_DEFINITION, children) } GRAPHQL_ENUM_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![enum] { - 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_ENUM_TYPE_EXTENSION.to_bogus(), - children.into_iter().map(Some), - ); - } - slots.into_node(GRAPHQL_ENUM_TYPE_EXTENSION, children) - } - GRAPHQL_ENUM_TYPE_EXTENSION_WITH_VALUES => { let mut elements = (&children).into_iter(); let mut slots: RawNodeSlots<5usize> = RawNodeSlots::default(); let mut current_element = elements.next(); @@ -485,11 +445,11 @@ impl SyntaxFactory for GraphqlSyntaxFactory { slots.next_slot(); if current_element.is_some() { return RawSyntaxNode::new( - GRAPHQL_ENUM_TYPE_EXTENSION_WITH_VALUES.to_bogus(), + GRAPHQL_ENUM_TYPE_EXTENSION.to_bogus(), children.into_iter().map(Some), ); } - slots.into_node(GRAPHQL_ENUM_TYPE_EXTENSION_WITH_VALUES, children) + slots.into_node(GRAPHQL_ENUM_TYPE_EXTENSION, children) } GRAPHQL_ENUM_VALUE => { let mut elements = (&children).into_iter(); diff --git a/crates/biome_graphql_parser/src/parser/definitions/enum.rs b/crates/biome_graphql_parser/src/parser/definitions/enum.rs index 905aa515ea27..d67aee5b28c0 100644 --- a/crates/biome_graphql_parser/src/parser/definitions/enum.rs +++ b/crates/biome_graphql_parser/src/parser/definitions/enum.rs @@ -1,7 +1,7 @@ use crate::parser::{ directive::{is_at_directive, DirectiveList}, is_nth_at_name, is_nth_at_non_kw_name, parse_description, - parse_error::expected_name, + parse_error::{expected_enum_extension, expected_name}, parse_name, value::{is_at_string, parse_enum_value}, GraphqlParser, @@ -34,6 +34,28 @@ pub(crate) fn parse_enum_type_definition(p: &mut GraphqlParser) -> ParsedSyntax Present(m.complete(p, GRAPHQL_ENUM_TYPE_DEFINITION)) } +/// Must only be called if the next 2 token is `extend` and `enum`, otherwise it will panic. +#[inline] +pub(crate) fn parse_enum_type_extension(p: &mut GraphqlParser) -> ParsedSyntax { + let m = p.start(); + + p.bump(T![extend]); + p.expect(T![enum]); + + 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 enum_values_empty = parse_enum_values(p).is_absent(); + + if directive_empty && enum_values_empty { + p.error(expected_enum_extension(p, p.cur_range())); + } + + Present(m.complete(p, GRAPHQL_ENUM_TYPE_EXTENSION)) +} + #[inline] fn parse_enum_values(p: &mut GraphqlParser) -> ParsedSyntax { if !is_at_enum_values(p) { diff --git a/crates/biome_graphql_parser/src/parser/definitions/mod.rs b/crates/biome_graphql_parser/src/parser/definitions/mod.rs index 1ad98a2060a9..e7d078b180ae 100644 --- a/crates/biome_graphql_parser/src/parser/definitions/mod.rs +++ b/crates/biome_graphql_parser/src/parser/definitions/mod.rs @@ -27,7 +27,7 @@ use self::{ 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}, - r#enum::parse_enum_type_definition, + r#enum::{parse_enum_type_definition, parse_enum_type_extension}, scalar::{parse_scalar_type_definition, parse_scalar_type_extension}, schema::{parse_schema_definition, parse_schema_extension}, union::{parse_union_type_definition, parse_union_type_extension}, @@ -101,6 +101,7 @@ fn parse_extension(p: &mut GraphqlParser) -> ParsedSyntax { T![type] => parse_object_type_extension(p), T![interface] => parse_interface_type_extension(p), T![union] => parse_union_type_extension(p), + T![enum] => parse_enum_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 c17e0271660f..5d3050aa2836 100644 --- a/crates/biome_graphql_parser/src/parser/parse_error.rs +++ b/crates/biome_graphql_parser/src/parser/parse_error.rs @@ -109,14 +109,21 @@ pub(crate) fn expected_directive_location(p: &GraphqlParser, range: TextRange) - pub(crate) fn expected_object_extension(p: &GraphqlParser, range: TextRange) -> ParseDiagnostic { p.err_builder( - "Expected at least one directive, implements interface or fields definition", + "Expected at least one directive, implements interface or a set of fields definition", range, ) } pub(crate) fn expected_union_extension(p: &GraphqlParser, range: TextRange) -> ParseDiagnostic { p.err_builder( - "Expected at least one directive or union member types", + "Expected at least one directive or a set union member types", + range, + ) +} + +pub(crate) fn expected_enum_extension(p: &GraphqlParser, range: TextRange) -> ParseDiagnostic { + p.err_builder( + "Expected at least one directive or a set of enum values", range, ) } diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/enum_extension.graphql b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/enum_extension.graphql new file mode 100644 index 000000000000..369a7e97fab0 --- /dev/null +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/enum_extension.graphql @@ -0,0 +1,6 @@ +extend enum Direction + +extend enum Direction + NORTH +} + diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/enum_extension.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/enum_extension.graphql.snap new file mode 100644 index 000000000000..19ea8bb07eec --- /dev/null +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/enum_extension.graphql.snap @@ -0,0 +1,118 @@ +--- +source: crates/biome_graphql_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```graphql +extend enum Direction + +extend enum Direction + NORTH +} + + +``` + +## AST + +``` +GraphqlRoot { + bom_token: missing (optional), + definitions: GraphqlDefinitionList [ + GraphqlEnumTypeExtension { + extend_token: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")], + enum_token: ENUM_KW@7..12 "enum" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@12..21 "Direction" [] [], + }, + directives: GraphqlDirectiveList [], + enum_values: missing (optional), + }, + GraphqlEnumTypeExtension { + extend_token: EXTEND_KW@21..30 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + enum_token: ENUM_KW@30..35 "enum" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@35..44 "Direction" [] [], + }, + directives: GraphqlDirectiveList [], + enum_values: GraphqlEnumValuesDefinition { + l_curly_token: missing (required), + values: GraphqlEnumValueList [ + GraphqlEnumValueDefinition { + description: missing (optional), + value: GraphqlEnumValue { + graphql_name: GraphqlName { + value_token: GRAPHQL_NAME@44..52 "NORTH" [Newline("\n"), Whitespace(" ")] [], + }, + }, + directives: GraphqlDirectiveList [], + }, + ], + r_curly_token: R_CURLY@52..54 "}" [Newline("\n")] [], + }, + }, + ], + eof_token: EOF@54..56 "" [Newline("\n"), Newline("\n")] [], +} +``` + +## CST + +``` +0: GRAPHQL_ROOT@0..56 + 0: (empty) + 1: GRAPHQL_DEFINITION_LIST@0..54 + 0: GRAPHQL_ENUM_TYPE_EXTENSION@0..21 + 0: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")] + 1: ENUM_KW@7..12 "enum" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@12..21 + 0: GRAPHQL_NAME@12..21 "Direction" [] [] + 3: GRAPHQL_DIRECTIVE_LIST@21..21 + 4: (empty) + 1: GRAPHQL_ENUM_TYPE_EXTENSION@21..54 + 0: EXTEND_KW@21..30 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: ENUM_KW@30..35 "enum" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@35..44 + 0: GRAPHQL_NAME@35..44 "Direction" [] [] + 3: GRAPHQL_DIRECTIVE_LIST@44..44 + 4: GRAPHQL_ENUM_VALUES_DEFINITION@44..54 + 0: (empty) + 1: GRAPHQL_ENUM_VALUE_LIST@44..52 + 0: GRAPHQL_ENUM_VALUE_DEFINITION@44..52 + 0: (empty) + 1: GRAPHQL_ENUM_VALUE@44..52 + 0: GRAPHQL_NAME@44..52 + 0: GRAPHQL_NAME@44..52 "NORTH" [Newline("\n"), Whitespace(" ")] [] + 2: GRAPHQL_DIRECTIVE_LIST@52..52 + 2: R_CURLY@52..54 "}" [Newline("\n")] [] + 2: EOF@54..56 "" [Newline("\n"), Newline("\n")] [] + +``` + +## Diagnostics + +``` +enum_extension.graphql:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected at least one directive or a set of enum values + + 1 │ extend enum Direction + 2 │ + > 3 │ extend enum Direction + │ ^^^^^^ + 4 │ NORTH + 5 │ } + +enum_extension.graphql:4:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `{` but instead found `NORTH` + + 3 │ extend enum Direction + > 4 │ NORTH + │ ^^^^^ + 5 │ } + 6 │ + + i Remove NORTH + +``` diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/interface_extension.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/interface_extension.graphql.snap index 64d228725af6..3b596b69697f 100644 --- a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/interface_extension.graphql.snap +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/interface_extension.graphql.snap @@ -106,7 +106,7 @@ GraphqlRoot { ``` interface_extension.graphql:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Expected at least one directive, implements interface or fields definition + × Expected at least one directive, implements interface or a set of fields definition 1 │ extend interface Story 2 │ diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/object_extension.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/object_extension.graphql.snap index abbda0c5a55a..db75e3e9a2c1 100644 --- a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/object_extension.graphql.snap +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/object_extension.graphql.snap @@ -106,7 +106,7 @@ GraphqlRoot { ``` object_extension.graphql:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Expected at least one directive, implements interface or fields definition + × Expected at least one directive, implements interface or a set of fields definition 1 │ extend type Story 2 │ diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/union_extension.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/union_extension.graphql.snap index 0e933a0b3fab..e302aac35ce9 100644 --- a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/union_extension.graphql.snap +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/union_extension.graphql.snap @@ -94,7 +94,7 @@ GraphqlRoot { ``` union_extension.graphql:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - × Expected at least one directive or union member types + × Expected at least one directive or a set union member types 1 │ extend union SearchResult 2 │ diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/enum_extension.graphql b/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/enum_extension.graphql new file mode 100644 index 000000000000..ae0a2dfa544e --- /dev/null +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/enum_extension.graphql @@ -0,0 +1,9 @@ +extend enum Direction @deprecated + +extend enum Direction { + NORTH +} + +extend enum Direction @deprecated { + NORTH +} diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/enum_extension.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/enum_extension.graphql.snap new file mode 100644 index 000000000000..542d6b83df08 --- /dev/null +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/enum_extension.graphql.snap @@ -0,0 +1,158 @@ +--- +source: crates/biome_graphql_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```graphql +extend enum Direction @deprecated + +extend enum Direction { + NORTH +} + +extend enum Direction @deprecated { + NORTH +} + +``` + +## AST + +``` +GraphqlRoot { + bom_token: missing (optional), + definitions: GraphqlDefinitionList [ + GraphqlEnumTypeExtension { + extend_token: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")], + enum_token: ENUM_KW@7..12 "enum" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@12..22 "Direction" [] [Whitespace(" ")], + }, + directives: GraphqlDirectiveList [ + GraphqlDirective { + at_token: AT@22..23 "@" [] [], + name: GraphqlName { + value_token: GRAPHQL_NAME@23..33 "deprecated" [] [], + }, + arguments: missing (optional), + }, + ], + enum_values: missing (optional), + }, + GraphqlEnumTypeExtension { + extend_token: EXTEND_KW@33..42 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + enum_token: ENUM_KW@42..47 "enum" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@47..57 "Direction" [] [Whitespace(" ")], + }, + directives: GraphqlDirectiveList [], + enum_values: GraphqlEnumValuesDefinition { + l_curly_token: L_CURLY@57..58 "{" [] [], + values: GraphqlEnumValueList [ + GraphqlEnumValueDefinition { + description: missing (optional), + value: GraphqlEnumValue { + graphql_name: GraphqlName { + value_token: GRAPHQL_NAME@58..66 "NORTH" [Newline("\n"), Whitespace(" ")] [], + }, + }, + directives: GraphqlDirectiveList [], + }, + ], + r_curly_token: R_CURLY@66..68 "}" [Newline("\n")] [], + }, + }, + GraphqlEnumTypeExtension { + extend_token: EXTEND_KW@68..77 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + enum_token: ENUM_KW@77..82 "enum" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@82..92 "Direction" [] [Whitespace(" ")], + }, + directives: GraphqlDirectiveList [ + GraphqlDirective { + at_token: AT@92..93 "@" [] [], + name: GraphqlName { + value_token: GRAPHQL_NAME@93..104 "deprecated" [] [Whitespace(" ")], + }, + arguments: missing (optional), + }, + ], + enum_values: GraphqlEnumValuesDefinition { + l_curly_token: L_CURLY@104..105 "{" [] [], + values: GraphqlEnumValueList [ + GraphqlEnumValueDefinition { + description: missing (optional), + value: GraphqlEnumValue { + graphql_name: GraphqlName { + value_token: GRAPHQL_NAME@105..113 "NORTH" [Newline("\n"), Whitespace(" ")] [], + }, + }, + directives: GraphqlDirectiveList [], + }, + ], + r_curly_token: R_CURLY@113..115 "}" [Newline("\n")] [], + }, + }, + ], + eof_token: EOF@115..116 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRAPHQL_ROOT@0..116 + 0: (empty) + 1: GRAPHQL_DEFINITION_LIST@0..115 + 0: GRAPHQL_ENUM_TYPE_EXTENSION@0..33 + 0: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")] + 1: ENUM_KW@7..12 "enum" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@12..22 + 0: GRAPHQL_NAME@12..22 "Direction" [] [Whitespace(" ")] + 3: GRAPHQL_DIRECTIVE_LIST@22..33 + 0: GRAPHQL_DIRECTIVE@22..33 + 0: AT@22..23 "@" [] [] + 1: GRAPHQL_NAME@23..33 + 0: GRAPHQL_NAME@23..33 "deprecated" [] [] + 2: (empty) + 4: (empty) + 1: GRAPHQL_ENUM_TYPE_EXTENSION@33..68 + 0: EXTEND_KW@33..42 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: ENUM_KW@42..47 "enum" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@47..57 + 0: GRAPHQL_NAME@47..57 "Direction" [] [Whitespace(" ")] + 3: GRAPHQL_DIRECTIVE_LIST@57..57 + 4: GRAPHQL_ENUM_VALUES_DEFINITION@57..68 + 0: L_CURLY@57..58 "{" [] [] + 1: GRAPHQL_ENUM_VALUE_LIST@58..66 + 0: GRAPHQL_ENUM_VALUE_DEFINITION@58..66 + 0: (empty) + 1: GRAPHQL_ENUM_VALUE@58..66 + 0: GRAPHQL_NAME@58..66 + 0: GRAPHQL_NAME@58..66 "NORTH" [Newline("\n"), Whitespace(" ")] [] + 2: GRAPHQL_DIRECTIVE_LIST@66..66 + 2: R_CURLY@66..68 "}" [Newline("\n")] [] + 2: GRAPHQL_ENUM_TYPE_EXTENSION@68..115 + 0: EXTEND_KW@68..77 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: ENUM_KW@77..82 "enum" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@82..92 + 0: GRAPHQL_NAME@82..92 "Direction" [] [Whitespace(" ")] + 3: GRAPHQL_DIRECTIVE_LIST@92..104 + 0: GRAPHQL_DIRECTIVE@92..104 + 0: AT@92..93 "@" [] [] + 1: GRAPHQL_NAME@93..104 + 0: GRAPHQL_NAME@93..104 "deprecated" [] [Whitespace(" ")] + 2: (empty) + 4: GRAPHQL_ENUM_VALUES_DEFINITION@104..115 + 0: L_CURLY@104..105 "{" [] [] + 1: GRAPHQL_ENUM_VALUE_LIST@105..113 + 0: GRAPHQL_ENUM_VALUE_DEFINITION@105..113 + 0: (empty) + 1: GRAPHQL_ENUM_VALUE@105..113 + 0: GRAPHQL_NAME@105..113 + 0: GRAPHQL_NAME@105..113 "NORTH" [Newline("\n"), Whitespace(" ")] [] + 2: GRAPHQL_DIRECTIVE_LIST@113..113 + 2: R_CURLY@113..115 "}" [Newline("\n")] [] + 2: EOF@115..116 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_graphql_syntax/src/generated/macros.rs b/crates/biome_graphql_syntax/src/generated/macros.rs index e4286b0eec8c..dd93b3691e3e 100644 --- a/crates/biome_graphql_syntax/src/generated/macros.rs +++ b/crates/biome_graphql_syntax/src/generated/macros.rs @@ -67,11 +67,6 @@ macro_rules! map_syntax_node { let $pattern = unsafe { $crate::GraphqlEnumTypeExtension::new_unchecked(node) }; $body } - $crate::GraphqlSyntaxKind::GRAPHQL_ENUM_TYPE_EXTENSION_WITH_VALUES => { - let $pattern = - unsafe { $crate::GraphqlEnumTypeExtensionWithValues::new_unchecked(node) }; - $body - } $crate::GraphqlSyntaxKind::GRAPHQL_ENUM_VALUE => { let $pattern = unsafe { $crate::GraphqlEnumValue::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 df2c5260dcbc..482ecffe6ab4 100644 --- a/crates/biome_graphql_syntax/src/generated/nodes.rs +++ b/crates/biome_graphql_syntax/src/generated/nodes.rs @@ -551,57 +551,6 @@ impl GraphqlEnumTypeExtension { enum_token: self.enum_token(), name: self.name(), directives: self.directives(), - } - } - pub fn extend_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 0usize) - } - pub fn enum_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 GraphqlEnumTypeExtension { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - self.as_fields().serialize(serializer) - } -} -#[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GraphqlEnumTypeExtensionFields { - pub extend_token: SyntaxResult, - pub enum_token: SyntaxResult, - pub name: SyntaxResult, - pub directives: GraphqlDirectiveList, -} -#[derive(Clone, PartialEq, Eq, Hash)] -pub struct GraphqlEnumTypeExtensionWithValues { - pub(crate) syntax: SyntaxNode, -} -impl GraphqlEnumTypeExtensionWithValues { - #[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) -> GraphqlEnumTypeExtensionWithValuesFields { - GraphqlEnumTypeExtensionWithValuesFields { - extend_token: self.extend_token(), - enum_token: self.enum_token(), - name: self.name(), - directives: self.directives(), enum_values: self.enum_values(), } } @@ -617,12 +566,12 @@ impl GraphqlEnumTypeExtensionWithValues { pub fn directives(&self) -> GraphqlDirectiveList { support::list(&self.syntax, 3usize) } - pub fn enum_values(&self) -> SyntaxResult { - support::required_node(&self.syntax, 4usize) + pub fn enum_values(&self) -> Option { + support::node(&self.syntax, 4usize) } } #[cfg(feature = "serde")] -impl Serialize for GraphqlEnumTypeExtensionWithValues { +impl Serialize for GraphqlEnumTypeExtension { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -631,12 +580,12 @@ impl Serialize for GraphqlEnumTypeExtensionWithValues { } } #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct GraphqlEnumTypeExtensionWithValuesFields { +pub struct GraphqlEnumTypeExtensionFields { pub extend_token: SyntaxResult, pub enum_token: SyntaxResult, pub name: SyntaxResult, pub directives: GraphqlDirectiveList, - pub enum_values: SyntaxResult, + pub enum_values: Option, } #[derive(Clone, PartialEq, Eq, Hash)] pub struct GraphqlEnumValue { @@ -2906,12 +2855,12 @@ pub struct GraphqlVariableDefinitionsFields { #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyGraphqlDefinition { - AnyGraphqlEnumTypeExtension(AnyGraphqlEnumTypeExtension), AnyGraphqlInputObjectTypeExtension(AnyGraphqlInputObjectTypeExtension), AnyGraphqlOperationDefinition(AnyGraphqlOperationDefinition), GraphqlBogusDefinition(GraphqlBogusDefinition), GraphqlDirectiveDefinition(GraphqlDirectiveDefinition), GraphqlEnumTypeDefinition(GraphqlEnumTypeDefinition), + GraphqlEnumTypeExtension(GraphqlEnumTypeExtension), GraphqlFragmentDefinition(GraphqlFragmentDefinition), GraphqlInputObjectTypeDefinition(GraphqlInputObjectTypeDefinition), GraphqlInterfaceTypeDefinition(GraphqlInterfaceTypeDefinition), @@ -2926,12 +2875,6 @@ pub enum AnyGraphqlDefinition { GraphqlUnionTypeExtension(GraphqlUnionTypeExtension), } impl AnyGraphqlDefinition { - pub fn as_any_graphql_enum_type_extension(&self) -> Option<&AnyGraphqlEnumTypeExtension> { - match &self { - AnyGraphqlDefinition::AnyGraphqlEnumTypeExtension(item) => Some(item), - _ => None, - } - } pub fn as_any_graphql_input_object_type_extension( &self, ) -> Option<&AnyGraphqlInputObjectTypeExtension> { @@ -2964,6 +2907,12 @@ impl AnyGraphqlDefinition { _ => None, } } + pub fn as_graphql_enum_type_extension(&self) -> Option<&GraphqlEnumTypeExtension> { + match &self { + AnyGraphqlDefinition::GraphqlEnumTypeExtension(item) => Some(item), + _ => None, + } + } pub fn as_graphql_fragment_definition(&self) -> Option<&GraphqlFragmentDefinition> { match &self { AnyGraphqlDefinition::GraphqlFragmentDefinition(item) => Some(item), @@ -3041,35 +2990,6 @@ impl AnyGraphqlDefinition { } #[derive(Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize))] -pub enum AnyGraphqlEnumTypeExtension { - GraphqlBogusExtension(GraphqlBogusExtension), - GraphqlEnumTypeExtension(GraphqlEnumTypeExtension), - GraphqlEnumTypeExtensionWithValues(GraphqlEnumTypeExtensionWithValues), -} -impl AnyGraphqlEnumTypeExtension { - pub fn as_graphql_bogus_extension(&self) -> Option<&GraphqlBogusExtension> { - match &self { - AnyGraphqlEnumTypeExtension::GraphqlBogusExtension(item) => Some(item), - _ => None, - } - } - pub fn as_graphql_enum_type_extension(&self) -> Option<&GraphqlEnumTypeExtension> { - match &self { - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtension(item) => Some(item), - _ => None, - } - } - pub fn as_graphql_enum_type_extension_with_values( - &self, - ) -> Option<&GraphqlEnumTypeExtensionWithValues> { - match &self { - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtensionWithValues(item) => Some(item), - _ => None, - } - } -} -#[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize))] pub enum AnyGraphqlInputObjectTypeExtension { GraphqlBogusExtension(GraphqlBogusExtension), GraphqlInputObjectTypeExtension(GraphqlInputObjectTypeExtension), @@ -3800,6 +3720,10 @@ impl std::fmt::Debug for GraphqlEnumTypeExtension { .field("enum_token", &support::DebugSyntaxResult(self.enum_token())) .field("name", &support::DebugSyntaxResult(self.name())) .field("directives", &self.directives()) + .field( + "enum_values", + &support::DebugOptionalElement(self.enum_values()), + ) .finish() } } @@ -3813,55 +3737,6 @@ impl From for SyntaxElement { n.syntax.into() } } -impl AstNode for GraphqlEnumTypeExtensionWithValues { - type Language = Language; - const KIND_SET: SyntaxKindSet = SyntaxKindSet::from_raw(RawSyntaxKind( - GRAPHQL_ENUM_TYPE_EXTENSION_WITH_VALUES as u16, - )); - fn can_cast(kind: SyntaxKind) -> bool { - kind == GRAPHQL_ENUM_TYPE_EXTENSION_WITH_VALUES - } - 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 GraphqlEnumTypeExtensionWithValues { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("GraphqlEnumTypeExtensionWithValues") - .field( - "extend_token", - &support::DebugSyntaxResult(self.extend_token()), - ) - .field("enum_token", &support::DebugSyntaxResult(self.enum_token())) - .field("name", &support::DebugSyntaxResult(self.name())) - .field("directives", &self.directives()) - .field( - "enum_values", - &support::DebugSyntaxResult(self.enum_values()), - ) - .finish() - } -} -impl From for SyntaxNode { - fn from(n: GraphqlEnumTypeExtensionWithValues) -> SyntaxNode { - n.syntax - } -} -impl From for SyntaxElement { - fn from(n: GraphqlEnumTypeExtensionWithValues) -> SyntaxElement { - n.syntax.into() - } -} impl AstNode for GraphqlEnumValue { type Language = Language; const KIND_SET: SyntaxKindSet = @@ -6031,6 +5906,11 @@ impl From for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlEnumTypeDefinition(node) } } +impl From for AnyGraphqlDefinition { + fn from(node: GraphqlEnumTypeExtension) -> AnyGraphqlDefinition { + AnyGraphqlDefinition::GraphqlEnumTypeExtension(node) + } +} impl From for AnyGraphqlDefinition { fn from(node: GraphqlFragmentDefinition) -> AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlFragmentDefinition(node) @@ -6093,12 +5973,12 @@ impl From for AnyGraphqlDefinition { } impl AstNode for AnyGraphqlDefinition { type Language = Language; - const KIND_SET: SyntaxKindSet = AnyGraphqlEnumTypeExtension::KIND_SET - .union(AnyGraphqlInputObjectTypeExtension::KIND_SET) + const KIND_SET: SyntaxKindSet = AnyGraphqlInputObjectTypeExtension::KIND_SET .union(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(GraphqlInterfaceTypeDefinition::KIND_SET) @@ -6116,6 +5996,7 @@ impl AstNode for AnyGraphqlDefinition { GRAPHQL_BOGUS_DEFINITION | GRAPHQL_DIRECTIVE_DEFINITION | GRAPHQL_ENUM_TYPE_DEFINITION + | GRAPHQL_ENUM_TYPE_EXTENSION | GRAPHQL_FRAGMENT_DEFINITION | GRAPHQL_INPUT_OBJECT_TYPE_DEFINITION | GRAPHQL_INTERFACE_TYPE_DEFINITION @@ -6128,7 +6009,6 @@ impl AstNode for AnyGraphqlDefinition { | GRAPHQL_SCHEMA_EXTENSION | GRAPHQL_UNION_TYPE_DEFINITION | GRAPHQL_UNION_TYPE_EXTENSION => true, - k if AnyGraphqlEnumTypeExtension::can_cast(k) => true, k if AnyGraphqlInputObjectTypeExtension::can_cast(k) => true, k if AnyGraphqlOperationDefinition::can_cast(k) => true, _ => false, @@ -6149,6 +6029,9 @@ impl AstNode for AnyGraphqlDefinition { syntax, }) } + GRAPHQL_ENUM_TYPE_EXTENSION => { + AnyGraphqlDefinition::GraphqlEnumTypeExtension(GraphqlEnumTypeExtension { syntax }) + } GRAPHQL_FRAGMENT_DEFINITION => { AnyGraphqlDefinition::GraphqlFragmentDefinition(GraphqlFragmentDefinition { syntax, @@ -6206,13 +6089,6 @@ impl AstNode for AnyGraphqlDefinition { }) } _ => { - if let Some(any_graphql_enum_type_extension) = - AnyGraphqlEnumTypeExtension::cast(syntax.clone()) - { - return Some(AnyGraphqlDefinition::AnyGraphqlEnumTypeExtension( - any_graphql_enum_type_extension, - )); - } if let Some(any_graphql_input_object_type_extension) = AnyGraphqlInputObjectTypeExtension::cast(syntax.clone()) { @@ -6237,6 +6113,7 @@ impl AstNode for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlBogusDefinition(it) => &it.syntax, AnyGraphqlDefinition::GraphqlDirectiveDefinition(it) => &it.syntax, AnyGraphqlDefinition::GraphqlEnumTypeDefinition(it) => &it.syntax, + AnyGraphqlDefinition::GraphqlEnumTypeExtension(it) => &it.syntax, AnyGraphqlDefinition::GraphqlFragmentDefinition(it) => &it.syntax, AnyGraphqlDefinition::GraphqlInputObjectTypeDefinition(it) => &it.syntax, AnyGraphqlDefinition::GraphqlInterfaceTypeDefinition(it) => &it.syntax, @@ -6249,7 +6126,6 @@ impl AstNode for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlSchemaExtension(it) => &it.syntax, AnyGraphqlDefinition::GraphqlUnionTypeDefinition(it) => &it.syntax, AnyGraphqlDefinition::GraphqlUnionTypeExtension(it) => &it.syntax, - AnyGraphqlDefinition::AnyGraphqlEnumTypeExtension(it) => it.syntax(), AnyGraphqlDefinition::AnyGraphqlInputObjectTypeExtension(it) => it.syntax(), AnyGraphqlDefinition::AnyGraphqlOperationDefinition(it) => it.syntax(), } @@ -6259,6 +6135,7 @@ impl AstNode for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlBogusDefinition(it) => it.syntax, AnyGraphqlDefinition::GraphqlDirectiveDefinition(it) => it.syntax, AnyGraphqlDefinition::GraphqlEnumTypeDefinition(it) => it.syntax, + AnyGraphqlDefinition::GraphqlEnumTypeExtension(it) => it.syntax, AnyGraphqlDefinition::GraphqlFragmentDefinition(it) => it.syntax, AnyGraphqlDefinition::GraphqlInputObjectTypeDefinition(it) => it.syntax, AnyGraphqlDefinition::GraphqlInterfaceTypeDefinition(it) => it.syntax, @@ -6271,7 +6148,6 @@ impl AstNode for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlSchemaExtension(it) => it.syntax, AnyGraphqlDefinition::GraphqlUnionTypeDefinition(it) => it.syntax, AnyGraphqlDefinition::GraphqlUnionTypeExtension(it) => it.syntax, - AnyGraphqlDefinition::AnyGraphqlEnumTypeExtension(it) => it.into_syntax(), AnyGraphqlDefinition::AnyGraphqlInputObjectTypeExtension(it) => it.into_syntax(), AnyGraphqlDefinition::AnyGraphqlOperationDefinition(it) => it.into_syntax(), } @@ -6280,7 +6156,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::AnyGraphqlEnumTypeExtension(it) => std::fmt::Debug::fmt(it, f), AnyGraphqlDefinition::AnyGraphqlInputObjectTypeExtension(it) => { std::fmt::Debug::fmt(it, f) } @@ -6288,6 +6163,7 @@ impl std::fmt::Debug for AnyGraphqlDefinition { AnyGraphqlDefinition::GraphqlBogusDefinition(it) => std::fmt::Debug::fmt(it, f), AnyGraphqlDefinition::GraphqlDirectiveDefinition(it) => std::fmt::Debug::fmt(it, f), AnyGraphqlDefinition::GraphqlEnumTypeDefinition(it) => std::fmt::Debug::fmt(it, f), + AnyGraphqlDefinition::GraphqlEnumTypeExtension(it) => std::fmt::Debug::fmt(it, f), AnyGraphqlDefinition::GraphqlFragmentDefinition(it) => std::fmt::Debug::fmt(it, f), AnyGraphqlDefinition::GraphqlInputObjectTypeDefinition(it) => { std::fmt::Debug::fmt(it, f) @@ -6308,12 +6184,12 @@ impl std::fmt::Debug for AnyGraphqlDefinition { impl From for SyntaxNode { fn from(n: AnyGraphqlDefinition) -> SyntaxNode { match n { - AnyGraphqlDefinition::AnyGraphqlEnumTypeExtension(it) => it.into(), AnyGraphqlDefinition::AnyGraphqlInputObjectTypeExtension(it) => it.into(), AnyGraphqlDefinition::AnyGraphqlOperationDefinition(it) => it.into(), AnyGraphqlDefinition::GraphqlBogusDefinition(it) => it.into(), AnyGraphqlDefinition::GraphqlDirectiveDefinition(it) => it.into(), AnyGraphqlDefinition::GraphqlEnumTypeDefinition(it) => it.into(), + AnyGraphqlDefinition::GraphqlEnumTypeExtension(it) => it.into(), AnyGraphqlDefinition::GraphqlFragmentDefinition(it) => it.into(), AnyGraphqlDefinition::GraphqlInputObjectTypeDefinition(it) => it.into(), AnyGraphqlDefinition::GraphqlInterfaceTypeDefinition(it) => it.into(), @@ -6335,96 +6211,6 @@ impl From for SyntaxElement { node.into() } } -impl From for AnyGraphqlEnumTypeExtension { - fn from(node: GraphqlBogusExtension) -> AnyGraphqlEnumTypeExtension { - AnyGraphqlEnumTypeExtension::GraphqlBogusExtension(node) - } -} -impl From for AnyGraphqlEnumTypeExtension { - fn from(node: GraphqlEnumTypeExtension) -> AnyGraphqlEnumTypeExtension { - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtension(node) - } -} -impl From for AnyGraphqlEnumTypeExtension { - fn from(node: GraphqlEnumTypeExtensionWithValues) -> AnyGraphqlEnumTypeExtension { - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtensionWithValues(node) - } -} -impl AstNode for AnyGraphqlEnumTypeExtension { - type Language = Language; - const KIND_SET: SyntaxKindSet = GraphqlBogusExtension::KIND_SET - .union(GraphqlEnumTypeExtension::KIND_SET) - .union(GraphqlEnumTypeExtensionWithValues::KIND_SET); - fn can_cast(kind: SyntaxKind) -> bool { - matches!( - kind, - GRAPHQL_BOGUS_EXTENSION - | GRAPHQL_ENUM_TYPE_EXTENSION - | GRAPHQL_ENUM_TYPE_EXTENSION_WITH_VALUES - ) - } - fn cast(syntax: SyntaxNode) -> Option { - let res = match syntax.kind() { - GRAPHQL_BOGUS_EXTENSION => { - AnyGraphqlEnumTypeExtension::GraphqlBogusExtension(GraphqlBogusExtension { syntax }) - } - GRAPHQL_ENUM_TYPE_EXTENSION => { - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtension(GraphqlEnumTypeExtension { - syntax, - }) - } - GRAPHQL_ENUM_TYPE_EXTENSION_WITH_VALUES => { - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtensionWithValues( - GraphqlEnumTypeExtensionWithValues { syntax }, - ) - } - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxNode { - match self { - AnyGraphqlEnumTypeExtension::GraphqlBogusExtension(it) => &it.syntax, - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtension(it) => &it.syntax, - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtensionWithValues(it) => &it.syntax, - } - } - fn into_syntax(self) -> SyntaxNode { - match self { - AnyGraphqlEnumTypeExtension::GraphqlBogusExtension(it) => it.syntax, - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtension(it) => it.syntax, - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtensionWithValues(it) => it.syntax, - } - } -} -impl std::fmt::Debug for AnyGraphqlEnumTypeExtension { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - AnyGraphqlEnumTypeExtension::GraphqlBogusExtension(it) => std::fmt::Debug::fmt(it, f), - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtension(it) => { - std::fmt::Debug::fmt(it, f) - } - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtensionWithValues(it) => { - std::fmt::Debug::fmt(it, f) - } - } - } -} -impl From for SyntaxNode { - fn from(n: AnyGraphqlEnumTypeExtension) -> SyntaxNode { - match n { - AnyGraphqlEnumTypeExtension::GraphqlBogusExtension(it) => it.into(), - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtension(it) => it.into(), - AnyGraphqlEnumTypeExtension::GraphqlEnumTypeExtensionWithValues(it) => it.into(), - } - } -} -impl From for SyntaxElement { - fn from(n: AnyGraphqlEnumTypeExtension) -> SyntaxElement { - let node: SyntaxNode = n.into(); - node.into() - } -} impl From for AnyGraphqlInputObjectTypeExtension { fn from(node: GraphqlBogusExtension) -> AnyGraphqlInputObjectTypeExtension { AnyGraphqlInputObjectTypeExtension::GraphqlBogusExtension(node) @@ -7000,11 +6786,6 @@ impl std::fmt::Display for AnyGraphqlDefinition { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for AnyGraphqlEnumTypeExtension { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - 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) @@ -7095,11 +6876,6 @@ impl std::fmt::Display for GraphqlEnumTypeExtension { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for GraphqlEnumTypeExtensionWithValues { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for GraphqlEnumValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) diff --git a/crates/biome_graphql_syntax/src/generated/nodes_mut.rs b/crates/biome_graphql_syntax/src/generated/nodes_mut.rs index 2f91380cc918..630d41150fdd 100644 --- a/crates/biome_graphql_syntax/src/generated/nodes_mut.rs +++ b/crates/biome_graphql_syntax/src/generated/nodes_mut.rs @@ -248,37 +248,11 @@ impl GraphqlEnumTypeExtension { .splice_slots(3usize..=3usize, once(Some(element.into_syntax().into()))), ) } -} -impl GraphqlEnumTypeExtensionWithValues { - 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_enum_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_enum_values(self, element: GraphqlEnumValuesDefinition) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(4usize..=4usize, once(Some(element.into_syntax().into()))), - ) + pub fn with_enum_values(self, element: Option) -> Self { + Self::unwrap_cast(self.syntax.splice_slots( + 4usize..=4usize, + once(element.map(|element| element.into_syntax().into())), + )) } } impl GraphqlEnumValue { diff --git a/crates/biome_graphql_syntax/src/lib.rs b/crates/biome_graphql_syntax/src/lib.rs index 42bf381188db..631d13359e08 100644 --- a/crates/biome_graphql_syntax/src/lib.rs +++ b/crates/biome_graphql_syntax/src/lib.rs @@ -57,7 +57,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 AnyGraphqlEnumTypeExtension::can_cast(*kind) => GRAPHQL_BOGUS_EXTENSION, kind if AnyGraphqlInputObjectTypeExtension::can_cast(*kind) => GRAPHQL_BOGUS_EXTENSION, _ => GRAPHQL_BOGUS, } diff --git a/xtask/codegen/graphql.ungram b/xtask/codegen/graphql.ungram index 62a8c09e5d8c..a7332c29ef75 100644 --- a/xtask/codegen/graphql.ungram +++ b/xtask/codegen/graphql.ungram @@ -73,7 +73,7 @@ AnyGraphqlDefinition = | GraphqlObjectTypeExtension | GraphqlInterfaceTypeExtension | GraphqlUnionTypeExtension - | AnyGraphqlEnumTypeExtension + | GraphqlEnumTypeExtension | AnyGraphqlInputObjectTypeExtension // https://spec.graphql.org/October2021/#sec-Language.Operations.Query-shorthand @@ -495,25 +495,13 @@ GraphqlEnumValueDefinition = directives: GraphqlDirectiveList // https://spec.graphql.org/October2021/#sec-Enum-Extensions -AnyGraphqlEnumTypeExtension = - GraphqlEnumTypeExtensionWithValues - | GraphqlEnumTypeExtension - | GraphqlBogusExtension - // extend enum A @d { Y } -GraphqlEnumTypeExtensionWithValues = - 'extend' - 'enum' - name: GraphqlName - directives: GraphqlDirectiveList - enum_values: GraphqlEnumValuesDefinition - -// extend enum A @d GraphqlEnumTypeExtension = 'extend' 'enum' name: GraphqlName directives: GraphqlDirectiveList + enum_values: GraphqlEnumValuesDefinition? // "xyz" input A @d { x: y } // https://spec.graphql.org/October2021/#sec-Input-Object