From 2244c0b11730fba2ab7efd137dfdb315e153c73c Mon Sep 17 00:00:00 2001 From: Denis Bezrukov <6227442+denbezrukov@users.noreply.github.com> Date: Thu, 27 Jun 2024 23:00:54 +0300 Subject: [PATCH] feat(graphql_formatter): implement graphql formatter (#3296) --- .../src/check_reformat.rs | 9 +- .../src/prettier/prepare_tests.js | 4 +- .../biome_graphql_analyze/tests/spec_tests.rs | 4 +- .../biome_graphql_formatter/src/comments.rs | 25 +- .../src/graphql/auxiliary/alias.rs | 8 +- .../src/graphql/auxiliary/argument.rs | 16 +- .../src/graphql/auxiliary/arguments.rs | 20 +- .../src/graphql/auxiliary/description.rs | 11 +- .../src/graphql/auxiliary/directive.rs | 13 +- .../graphql/auxiliary/directive_location.rs | 9 +- .../src/graphql/auxiliary/field.rs | 29 +- .../src/graphql/auxiliary/fragment_spread.rs | 16 +- .../auxiliary/implements_interfaces.rs | 20 +- .../src/graphql/auxiliary/inline_fragment.rs | 20 +- .../src/graphql/auxiliary/list_type.rs | 20 +- .../src/graphql/auxiliary/name.rs | 9 +- .../src/graphql/auxiliary/named_type.rs | 9 +- .../src/graphql/auxiliary/non_null_type.rs | 8 +- .../src/graphql/auxiliary/object_field.rs | 16 +- .../src/graphql/auxiliary/operation_type.rs | 9 +- .../graphql/auxiliary/root_operation_types.rs | 20 +- .../src/graphql/auxiliary/selection_set.rs | 20 +- .../src/graphql/auxiliary/type_condition.rs | 8 +- .../graphql/auxiliary/union_member_types.rs | 57 ++- .../src/graphql/auxiliary/variable.rs | 9 +- .../graphql/auxiliary/variable_definitions.rs | 20 +- .../definitions/arguments_definition.rs | 20 +- .../definitions/directive_definition.rs | 42 +- .../definitions/enum_type_definition.rs | 29 +- .../definitions/enum_value_definition.rs | 17 +- .../definitions/enum_values_definition.rs | 20 +- .../graphql/definitions/field_definition.rs | 30 +- .../graphql/definitions/fields_definition.rs | 20 +- .../definitions/fragment_definition.rs | 27 +- .../definitions/input_fields_definition.rs | 20 +- .../input_object_type_definition.rs | 29 +- .../definitions/input_value_definition.rs | 28 +- .../definitions/interface_type_definition.rs | 32 +- .../definitions/object_type_definition.rs | 30 +- .../definitions/operation_definition.rs | 33 +- .../root_operation_type_definition.rs | 23 +- .../definitions/scalar_type_definition.rs | 26 +- .../graphql/definitions/schema_definition.rs | 26 +- .../definitions/union_type_definition.rs | 32 +- .../definitions/variable_definition.rs | 25 +- .../graphql/extensions/enum_type_extension.rs | 27 +- .../extensions/input_object_type_extension.rs | 29 +- .../extensions/interface_type_extension.rs | 37 +- .../extensions/object_type_extension.rs | 29 +- .../extensions/scalar_type_extension.rs | 24 +- .../graphql/extensions/schema_extension.rs | 28 +- .../extensions/union_type_extension.rs | 26 +- .../graphql/lists/argument_definition_list.rs | 22 +- .../src/graphql/lists/argument_list.rs | 22 +- .../src/graphql/lists/definition_list.rs | 12 +- .../src/graphql/lists/directive_list.rs | 30 +- .../graphql/lists/directive_location_list.rs | 19 +- .../src/graphql/lists/enum_value_list.rs | 11 +- .../graphql/lists/field_definition_list.rs | 11 +- .../lists/implements_interface_list.rs | 20 +- .../src/graphql/lists/input_field_list.rs | 11 +- .../graphql/lists/list_value_element_list.rs | 9 +- .../graphql/lists/object_value_member_list.rs | 9 +- .../root_operation_type_definition_list.rs | 11 +- .../src/graphql/lists/selection_list.rs | 11 +- .../graphql/lists/union_member_type_list.rs | 43 +- .../graphql/lists/variable_definition_list.rs | 8 +- .../src/graphql/value/boolean_value.rs | 8 +- .../src/graphql/value/default_value.rs | 9 +- .../src/graphql/value/enum_value.rs | 8 +- .../src/graphql/value/float_value.rs | 11 +- .../src/graphql/value/int_value.rs | 11 +- .../src/graphql/value/list_value.rs | 20 +- .../src/graphql/value/null_value.rs | 9 +- .../src/graphql/value/object_value.rs | 20 +- .../src/graphql/value/string_value.rs | 10 +- crates/biome_graphql_formatter/src/lib.rs | 1 - crates/biome_graphql_formatter/src/prelude.rs | 2 - .../biome_graphql_formatter/src/separated.rs | 59 --- .../tests/quick_test.rs | 31 +- .../definitions/directive_definition.graphql | 35 ++ .../directive_definition.graphql.snap | 72 ++++ .../specs/graphql/definitions/enum.graphql | 35 ++ .../graphql/definitions/enum.graphql.snap | 86 ++++ .../definitions/enum_extension.graphql | 26 ++ .../definitions/enum_extension.graphql.snap | 62 +++ .../graphql/definitions/fragment.graphql | 31 ++ .../graphql/definitions/fragment.graphql.snap | 77 ++++ .../graphql/definitions/input_object.graphql | 57 +++ .../definitions/input_object.graphql.snap | 109 +++++ .../input_object_extension.graphql | 29 ++ .../input_object_extension.graphql.snap | 69 +++ .../graphql/definitions/interface.graphql | 91 ++++ .../definitions/interface.graphql.snap | 162 +++++++ .../definitions/interface_extension.graphql | 45 ++ .../interface_extension.graphql.snap | 89 ++++ .../specs/graphql/definitions/object.graphql | 97 +++++ .../graphql/definitions/object.graphql.snap | 174 ++++++++ .../definitions/object_extension.graphql | 37 ++ .../definitions/object_extension.graphql.snap | 350 +++++++++++++++ .../specs/graphql/definitions/scalar.graphql | 10 + .../graphql/definitions/scalar.graphql.snap | 42 ++ .../definitions/scalar_extension.graphql | 7 + .../definitions/scalar_extension.graphql.snap | 35 ++ .../specs/graphql/definitions/schema.graphql | 32 ++ .../graphql/definitions/schema.graphql.snap | 83 ++++ .../definitions/schema_extension.graphql | 27 ++ .../definitions/schema_extension.graphql.snap | 72 ++++ .../specs/graphql/definitions/union.graphql | 20 + .../graphql/definitions/union.graphql.snap | 56 +++ .../definitions/union_extension.graphql | 3 + .../definitions/union_extension.graphql.snap | 33 ++ .../tests/specs/graphql/directive.graphql | 57 ++- .../specs/graphql/directive.graphql.snap | 73 +++- .../tests/specs/graphql/operation.graphql | 159 +++++++ .../specs/graphql/operation.graphql.snap | 239 +++++++++++ .../tests/specs/graphql/selection_set.graphql | 249 +++++++++++ .../specs/graphql/selection_set.graphql.snap | 405 ++++++++++++++++++ .../tests/specs/graphql/simple.graphql | 59 +++ .../tests/specs/graphql/simple.graphql.snap | 136 ++++++ .../tests/specs/graphql/type.graphql | 12 + .../tests/specs/graphql/type.graphql.snap | 49 +++ .../tests/specs/graphql/value.graphql | 14 + .../tests/specs/graphql/value.graphql.snap | 55 +++ .../prettier/graphql/arguments/hello.graphql | 4 + .../arguments/hello.graphql.prettier-snap | 10 + .../bracket-spacing/bracket_spacing.graphql | 6 + .../bracket_spacing.graphql.prettier-snap | 4 + .../graphql/comments/argument_comment.graphql | 7 + .../argument_comment.graphql.prettier-snap | 6 + .../prettier/graphql/comments/fields.graphql | 5 + .../comments/fields.graphql.prettier-snap | 3 + .../graphql/comments/interfaces.graphql | 7 + .../comments/interfaces.graphql.prettier-snap | 7 + .../graphql/comments/interfaces.graphql.snap | 49 +++ .../prettier/graphql/comments/tokens.graphql | 7 + .../comments/tokens.graphql.prettier-snap | 13 + .../graphql/definitions/fields.graphql | 32 ++ .../definitions/fields.graphql.prettier-snap | 31 ++ .../graphql/definitions/fields.graphql.snap | 94 ++++ .../graphql/deprecation/directives.graphql | 71 +++ .../directives.graphql.prettier-snap | 70 +++ .../directive-decl/directive_decl.graphql | 18 + .../directive_decl.graphql.prettier-snap | 14 + .../graphql/directives/directives.graphql | 20 + .../directives.graphql.prettier-snap | 26 ++ .../specs/prettier/graphql/enum/enum.graphql | 5 + .../graphql/enum/enum.graphql.prettier-snap | 5 + .../prettier/graphql/fields/fields.graphql | 4 + .../fields/fields.graphql.prettier-snap | 14 + .../fragment_variables.graphql | 7 + .../fragment_variables.graphql.prettier-snap | 10 + .../fragment_variables.graphql.snap | 160 +++++++ .../graphql/fragments/fragments.graphql | 15 + .../fragments/fragments.graphql.prettier-snap | 15 + .../prettier/graphql/hello/hello.graphql | 5 + .../graphql/hello/hello.graphql.prettier-snap | 5 + .../graphql/interface/interface.graphql | 43 ++ .../interface/interface.graphql.prettier-snap | 37 ++ .../graphql/interface/object_type_def.graphql | 22 + .../object_type_def.graphql.prettier-snap | 21 + .../object_type_def_mixed_syntax.graphql | 22 + ...ype_def_mixed_syntax.graphql.prettier-snap | 21 + .../object_type_def_old_syntax.graphql | 22 + ..._type_def_old_syntax.graphql.prettier-snap | 21 + .../interface/separator-detection.graphql | 30 ++ .../separator-detection.graphql.prettier-snap | 34 ++ .../separator-detection.graphql.snap | 140 ++++++ .../graphql/kitchen-sink/kitchen_sink.graphql | 57 +++ .../kitchen_sink.graphql.prettier-snap | 64 +++ .../kitchen-sink/kitchen_sink.graphql.snap | 152 +++++++ .../kitchen-sink/schema_kitchen_sink.graphql | 124 ++++++ .../schema_kitchen_sink.graphql.prettier-snap | 118 +++++ .../prettier/graphql/lists/lists.graphql | 4 + .../graphql/lists/lists.graphql.prettier-snap | 10 + .../graphql/newline/directive_decl.graphql | 10 + .../directive_decl.graphql.prettier-snap | 8 + .../graphql/newline/directives.graphql | 17 + .../newline/directives.graphql.prettier-snap | 19 + .../prettier/graphql/newline/enum.graphql | 11 + .../newline/enum.graphql.prettier-snap | 11 + .../prettier/graphql/newline/fields.graphql | 35 ++ .../newline/fields.graphql.prettier-snap | 28 ++ .../prettier/graphql/newline/input.graphql | 8 + .../newline/input.graphql.prettier-snap | 7 + .../graphql/newline/interface.graphql | 9 + .../newline/interface.graphql.prettier-snap | 8 + .../graphql/newline/object_type_def.graphql | 22 + .../object_type_def.graphql.prettier-snap | 21 + .../prettier/graphql/newline/schema.graphql | 10 + .../newline/schema.graphql.prettier-snap | 9 + .../graphql/object-type-def/arguments.graphql | 3 + .../arguments.graphql.prettier-snap | 3 + .../object-type-def/directives.graphql | 3 + .../directives.graphql.prettier-snap | 3 + .../graphql/object-type-def/extend.graphql | 3 + .../extend.graphql.prettier-snap | 3 + .../object-type-def/implements.graphql | 3 + .../implements.graphql.prettier-snap | 3 + .../graphql/object-type-def/input.graphql | 4 + .../input.graphql.prettier-snap | 4 + .../object-type-def/object_type_def.graphql | 4 + .../object_type_def.graphql.prettier-snap | 4 + .../prettier/graphql/objects/objects.graphql | 9 + .../objects/objects.graphql.prettier-snap | 11 + .../prettier-ignore-comment.graphql | 7 + ...ttier-ignore-comment.graphql.prettier-snap | 7 + .../prettier-ignore-comment.graphql.snap | 45 ++ .../prettier/graphql/range/issue2296.graphql | 1 + .../range/issue2296.graphql.prettier-snap | 5 + .../prettier/graphql/scalar/scalar.graphql | 1 + .../scalar/scalar.graphql.prettier-snap | 1 + .../prettier/graphql/schema/schema.graphql | 13 + .../schema/schema.graphql.prettier-snap | 16 + .../graphql/schema/schema.graphql.snap | 57 +++ .../graphql/string/description.graphql | 74 ++++ .../string/description.graphql.prettier-snap | 88 ++++ .../graphql/string/description.graphql.snap | 289 +++++++++++++ .../prettier/graphql/string/string.graphql | 60 +++ .../string/string.graphql.prettier-snap | 91 ++++ .../graphql/string/string.graphql.snap | 254 +++++++++++ .../graphql/trailing-comma/trailing.graphql | 20 + .../trailing.graphql.prettier-snap | 27 ++ .../trailing-comma/trailing.graphql.snap | 197 +++++++++ .../type-extendsion-syntax.graphql | 8 + ...pe-extendsion-syntax.graphql.prettier-snap | 8 + .../graphql/union-types/union_types.graphql | 15 + .../union_types.graphql.prettier-snap | 51 +++ ...union_types.graphql.prettier-snap-original | 51 +++ .../variable_definitions.graphql | 25 ++ ...variable_definitions.graphql.prettier-snap | 34 ++ .../src/parser/definitions/interface.rs | 5 +- .../src/parser/definitions/union.rs | 5 +- .../err/definitions/interface.graphql.snap | 282 ++++++------ .../err/definitions/object.graphql.snap | 282 ++++++------ .../err/definitions/union.graphql.snap | 183 ++++---- .../ok/definitions/union.graphql.snap | 20 +- .../biome_graphql_syntax/src/file_source.rs | 6 +- crates/biome_parser/src/parse_lists.rs | 8 - 239 files changed, 8731 insertions(+), 715 deletions(-) delete mode 100644 crates/biome_graphql_formatter/src/separated.rs create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/directive_definition.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/directive_definition.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum_extension.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum_extension.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/fragment.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/fragment.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object_extension.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object_extension.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface_extension.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface_extension.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/object.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/object.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/object_extension.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/object_extension.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar_extension.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar_extension.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema_extension.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema_extension.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/union.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/union.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/union_extension.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/definitions/union_extension.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/operation.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/operation.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/selection_set.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/selection_set.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/simple.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/simple.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/type.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/type.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/value.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/graphql/value.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/arguments/hello.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/arguments/hello.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/bracket-spacing/bracket_spacing.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/bracket-spacing/bracket_spacing.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/argument_comment.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/argument_comment.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/fields.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/fields.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/tokens.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/tokens.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/deprecation/directives.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/deprecation/directives.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/directive-decl/directive_decl.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/directive-decl/directive_decl.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/directives/directives.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/directives/directives.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/enum/enum.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/enum/enum.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/fields/fields.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/fields/fields.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragments/fragments.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragments/fragments.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/hello/hello.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/hello/hello.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/interface.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/interface.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_mixed_syntax.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_mixed_syntax.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_old_syntax.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_old_syntax.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/schema_kitchen_sink.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/schema_kitchen_sink.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/lists/lists.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/lists/lists.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directive_decl.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directive_decl.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directives.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directives.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/enum.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/enum.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/fields.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/fields.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/input.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/input.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/interface.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/interface.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/object_type_def.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/object_type_def.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/schema.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/schema.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/arguments.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/arguments.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/directives.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/directives.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/extend.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/extend.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/implements.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/implements.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/input.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/input.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/object_type_def.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/object_type_def.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/objects/objects.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/objects/objects.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/range/issue2296.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/range/issue2296.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/scalar/scalar.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/scalar/scalar.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql.snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/type-extension-definition/type-extendsion-syntax.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/type-extension-definition/type-extendsion-syntax.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql.prettier-snap create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql.prettier-snap-original create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/variable-definitions/variable_definitions.graphql create mode 100644 crates/biome_graphql_formatter/tests/specs/prettier/graphql/variable-definitions/variable_definitions.graphql.prettier-snap diff --git a/crates/biome_formatter_test/src/check_reformat.rs b/crates/biome_formatter_test/src/check_reformat.rs index de944979e441..8ea27859695f 100644 --- a/crates/biome_formatter_test/src/check_reformat.rs +++ b/crates/biome_formatter_test/src/check_reformat.rs @@ -68,10 +68,15 @@ where ) } - let formatted = self + let formatted = match self .language .format_node(self.options.clone(), &re_parse.syntax()) - .unwrap(); + { + Ok(formatted) => formatted, + Err(err) => { + panic!("failed to format: {}", err); + } + }; let printed = formatted.print().unwrap(); diff --git a/crates/biome_formatter_test/src/prettier/prepare_tests.js b/crates/biome_formatter_test/src/prettier/prepare_tests.js index b5bc235bef98..0cad77769581 100644 --- a/crates/biome_formatter_test/src/prettier/prepare_tests.js +++ b/crates/biome_formatter_test/src/prettier/prepare_tests.js @@ -42,7 +42,7 @@ async function traverseDir(dir, input_config) { const file = entry.name; // Ignore spec files - if (file.startsWith('jsfmt.spec')) { + if (file.startsWith('format.test')) { continue; } @@ -55,7 +55,7 @@ async function traverseDir(dir, input_config) { const snapshotPath = path.resolve( dir, '__snapshots__', - 'jsfmt.spec.js.snap' + 'format.test.js.snap' ); const snapFile = path.basename(file) + '.prettier-snap'; const snapOriginalFile = path.basename(file) + '.prettier-snap-original'; diff --git a/crates/biome_graphql_analyze/tests/spec_tests.rs b/crates/biome_graphql_analyze/tests/spec_tests.rs index 9bcde490734e..8d92bf08c037 100644 --- a/crates/biome_graphql_analyze/tests/spec_tests.rs +++ b/crates/biome_graphql_analyze/tests/spec_tests.rs @@ -50,7 +50,7 @@ fn run_test(input: &'static str, _: &str, _: &str, _: &str) { analyze_and_snap( &mut snapshot, &script, - GraphqlFileSource {}, + GraphqlFileSource::default(), filter, file_name, input_file, @@ -210,7 +210,7 @@ pub(crate) fn _run_suppression_test(input: &'static str, _: &str, _: &str, _: &s analyze_and_snap( &mut snapshot, &input_code, - GraphqlFileSource {}, + GraphqlFileSource::default(), filter, file_name, input_file, diff --git a/crates/biome_graphql_formatter/src/comments.rs b/crates/biome_graphql_formatter/src/comments.rs index 6d028d3b2e2e..8ec441d46da4 100644 --- a/crates/biome_graphql_formatter/src/comments.rs +++ b/crates/biome_graphql_formatter/src/comments.rs @@ -1,5 +1,4 @@ use crate::prelude::*; -use biome_diagnostics::category; use biome_formatter::comments::{ is_doc_comment, CommentKind, CommentStyle, Comments, SourceComment, }; @@ -7,7 +6,6 @@ use biome_formatter::formatter::Formatter; use biome_formatter::{write, FormatResult, FormatRule}; use biome_graphql_syntax::{GraphqlLanguage, TextLen}; use biome_rowan::SyntaxTriviaPieceComments; -use biome_suppression::parse_suppression_comment; pub type GraphqlComments = Comments; @@ -64,22 +62,15 @@ pub struct GraphqlCommentStyle; impl CommentStyle for GraphqlCommentStyle { type Language = GraphqlLanguage; - fn is_suppression(text: &str) -> bool { - parse_suppression_comment(text) - .filter_map(Result::ok) - .flat_map(|suppression| suppression.categories) - .any(|(key, _)| key == category!("format")) + fn is_suppression(_text: &str) -> bool { + // parse_suppression_comment(text) + // .filter_map(Result::ok) + // .flat_map(|suppression| suppression.categories) + // .any(|(key, _)| key == category!("format")) + false } - fn get_comment_kind(comment: &SyntaxTriviaPieceComments) -> CommentKind { - if comment.text().starts_with("/*") { - if comment.has_newline() { - CommentKind::Block - } else { - CommentKind::InlineBlock - } - } else { - CommentKind::Line - } + fn get_comment_kind(_comment: &SyntaxTriviaPieceComments) -> CommentKind { + CommentKind::Line } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/alias.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/alias.rs index 333b3f5863f1..56262c3904e1 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/alias.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/alias.rs @@ -1,10 +1,12 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlAlias; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlAlias, GraphqlAliasFields}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlAlias; impl FormatNodeRule for FormatGraphqlAlias { fn fmt_fields(&self, node: &GraphqlAlias, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlAliasFields { value, colon_token } = node.as_fields(); + + write!(f, [value.format(), colon_token.format(), space()]) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/argument.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/argument.rs index 0e74941296db..96bc31689e6a 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/argument.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/argument.rs @@ -1,10 +1,20 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlArgument; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlArgument, GraphqlArgumentFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlArgument; impl FormatNodeRule for FormatGraphqlArgument { fn fmt_fields(&self, node: &GraphqlArgument, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlArgumentFields { + name, + colon_token, + value, + } = node.as_fields(); + + write!( + f, + [name.format(), colon_token.format(), space(), value.format(),] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/arguments.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/arguments.rs index 4b39a9acf35d..054a5c5c06ac 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/arguments.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/arguments.rs @@ -1,10 +1,24 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlArguments; -use biome_rowan::AstNode; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlArguments, GraphqlArgumentsFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlArguments; impl FormatNodeRule for FormatGraphqlArguments { fn fmt_fields(&self, node: &GraphqlArguments, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlArgumentsFields { + l_paren_token, + arguments, + r_paren_token, + } = node.as_fields(); + + write!( + f, + [group(&format_args!( + l_paren_token.format(), + soft_block_indent(&arguments.format()), + r_paren_token.format(), + ))] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/description.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/description.rs index 3dde4772f8b0..8ce04cd712b4 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/description.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/description.rs @@ -1,10 +1,15 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlDescription; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlDescription, GraphqlDescriptionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlDescription; impl FormatNodeRule for FormatGraphqlDescription { fn fmt_fields(&self, node: &GraphqlDescription, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlDescriptionFields { + graphql_string_value, + } = node.as_fields(); + + write!(f, [graphql_string_value.format()]) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/directive.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/directive.rs index e17d30b21a12..41029f0c4e75 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/directive.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/directive.rs @@ -1,10 +1,17 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlDirective; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlDirective, GraphqlDirectiveFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlDirective; impl FormatNodeRule for FormatGraphqlDirective { fn fmt_fields(&self, node: &GraphqlDirective, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlDirectiveFields { + at_token, + name, + arguments, + } = node.as_fields(); + + write![f, [at_token.format(), name.format(), arguments.format()]] } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/directive_location.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/directive_location.rs index 7f329a347e5a..160d3d5b86e1 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/directive_location.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/directive_location.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlDirectiveLocation; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlDirectiveLocation, GraphqlDirectiveLocationFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlDirectiveLocation; impl FormatNodeRule for FormatGraphqlDirectiveLocation { @@ -9,6 +10,8 @@ impl FormatNodeRule for FormatGraphqlDirectiveLocation node: &GraphqlDirectiveLocation, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlDirectiveLocationFields { value_token } = node.as_fields(); + + write!(f, [value_token.format()]) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/field.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/field.rs index 7f27ec130ec2..55924ef3c4ff 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/field.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/field.rs @@ -1,10 +1,33 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlField; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlField, GraphqlFieldFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlField; impl FormatNodeRule for FormatGraphqlField { fn fmt_fields(&self, node: &GraphqlField, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlFieldFields { + alias, + name, + arguments, + directives, + selection_set, + } = node.as_fields(); + + write!( + f, + [ + alias.format(), + name.format(), + arguments.format(), + directives.format(), + ] + )?; + + if let Some(selection_set) = selection_set { + write!(f, [space(), selection_set.format()])?; + } + + Ok(()) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/fragment_spread.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/fragment_spread.rs index b2d4ebb10543..40f5256f6d4c 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/fragment_spread.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/fragment_spread.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlFragmentSpread; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlFragmentSpread, GraphqlFragmentSpreadFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlFragmentSpread; impl FormatNodeRule for FormatGraphqlFragmentSpread { @@ -9,6 +10,15 @@ impl FormatNodeRule for FormatGraphqlFragmentSpread { node: &GraphqlFragmentSpread, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlFragmentSpreadFields { + dotdotdot_token, + name, + directives, + } = node.as_fields(); + + write![ + f, + [dotdotdot_token.format(), name.format(), directives.format()] + ] } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/implements_interfaces.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/implements_interfaces.rs index b588778f7d39..534abca6573b 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/implements_interfaces.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/implements_interfaces.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlImplementsInterfaces; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlImplementsInterfaces, GraphqlImplementsInterfacesFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlImplementsInterfaces; impl FormatNodeRule for FormatGraphqlImplementsInterfaces { @@ -9,6 +10,19 @@ impl FormatNodeRule for FormatGraphqlImplementsInte node: &GraphqlImplementsInterfaces, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlImplementsInterfacesFields { + implements_token, + amp_token, + interfaces, + } = node.as_fields(); + + if let Some(amp_token) = amp_token { + write!(f, [format_removed(&_token)])?; + } + + write!( + f, + [implements_token.format(), space(), interfaces.format(),] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/inline_fragment.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/inline_fragment.rs index 256ebc924cc3..67c2df61706e 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/inline_fragment.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/inline_fragment.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlInlineFragment; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlInlineFragment, GraphqlInlineFragmentFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlInlineFragment; impl FormatNodeRule for FormatGraphqlInlineFragment { @@ -9,6 +10,19 @@ impl FormatNodeRule for FormatGraphqlInlineFragment { node: &GraphqlInlineFragment, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlInlineFragmentFields { + dotdotdot_token, + type_condition, + directives, + selection_set, + } = node.as_fields(); + + write!(f, [dotdotdot_token.format()])?; + + if let Some(type_condition) = type_condition { + write!(f, [space(), type_condition.format()])?; + } + + write!(f, [directives.format(), space(), selection_set.format(),]) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/list_type.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/list_type.rs index 24e0d444ab01..95e45d31c05f 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/list_type.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/list_type.rs @@ -1,10 +1,24 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlListType; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlListType, GraphqlListTypeFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlListType; impl FormatNodeRule for FormatGraphqlListType { fn fmt_fields(&self, node: &GraphqlListType, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlListTypeFields { + l_brack_token, + element, + r_brack_token, + } = node.as_fields(); + + write!( + f, + [ + l_brack_token.format(), + element.format(), + r_brack_token.format() + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/name.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/name.rs index 807ebb9b6391..f217dbcca876 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/name.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/name.rs @@ -1,10 +1,13 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlName; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlName, GraphqlNameFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlName; impl FormatNodeRule for FormatGraphqlName { fn fmt_fields(&self, node: &GraphqlName, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlNameFields { value_token } = node.as_fields(); + + write![f, [value_token.format()]] } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/named_type.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/named_type.rs index af028575e717..a88658d49356 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/named_type.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/named_type.rs @@ -1,10 +1,13 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlNamedType; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlNamedType, GraphqlNamedTypeFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlNamedType; impl FormatNodeRule for FormatGraphqlNamedType { fn fmt_fields(&self, node: &GraphqlNamedType, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlNamedTypeFields { name } = node.as_fields(); + + write!(f, [name.format()]) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/non_null_type.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/non_null_type.rs index f713d4b6e29c..9b52d7132b58 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/non_null_type.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/non_null_type.rs @@ -1,10 +1,12 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlNonNullType; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlNonNullType, GraphqlNonNullTypeFields}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlNonNullType; impl FormatNodeRule for FormatGraphqlNonNullType { fn fmt_fields(&self, node: &GraphqlNonNullType, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlNonNullTypeFields { base, excl_token } = node.as_fields(); + + write!(f, [base.format(), excl_token.format()]) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/object_field.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/object_field.rs index 99d90dc7dbb1..cd16bacaf2cd 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/object_field.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/object_field.rs @@ -1,10 +1,20 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlObjectField; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlObjectField, GraphqlObjectFieldFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlObjectField; impl FormatNodeRule for FormatGraphqlObjectField { fn fmt_fields(&self, node: &GraphqlObjectField, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlObjectFieldFields { + name, + colon_token, + value, + } = node.as_fields(); + + write!( + f, + [name.format(), colon_token.format(), space(), value.format()] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/operation_type.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/operation_type.rs index 3e56a8fa751e..4e2ec1b51364 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/operation_type.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/operation_type.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlOperationType; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlOperationType, GraphqlOperationTypeFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlOperationType; impl FormatNodeRule for FormatGraphqlOperationType { @@ -9,6 +10,8 @@ impl FormatNodeRule for FormatGraphqlOperationType { node: &GraphqlOperationType, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlOperationTypeFields { value_token } = node.as_fields(); + + write![f, [value_token.format(),]] } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/root_operation_types.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/root_operation_types.rs index fa6779786d6c..9550eca48aa8 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/root_operation_types.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/root_operation_types.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlRootOperationTypes; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlRootOperationTypes, GraphqlRootOperationTypesFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlRootOperationTypes; impl FormatNodeRule for FormatGraphqlRootOperationTypes { @@ -9,6 +10,19 @@ impl FormatNodeRule for FormatGraphqlRootOperationTyp node: &GraphqlRootOperationTypes, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlRootOperationTypesFields { + l_curly_token, + root_operation_type, + r_curly_token, + } = node.as_fields(); + + write!( + f, + [ + l_curly_token.format(), + block_indent(&root_operation_type.format()), + r_curly_token.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/selection_set.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/selection_set.rs index d93580d919c7..038425cfc104 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/selection_set.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/selection_set.rs @@ -1,10 +1,24 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlSelectionSet; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlSelectionSet, GraphqlSelectionSetFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlSelectionSet; impl FormatNodeRule for FormatGraphqlSelectionSet { fn fmt_fields(&self, node: &GraphqlSelectionSet, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlSelectionSetFields { + l_curly_token, + selections, + r_curly_token, + } = node.as_fields(); + + write!( + f, + [ + l_curly_token.format(), + block_indent(&selections.format()), + r_curly_token.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/type_condition.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/type_condition.rs index 534855968ebc..d61edd088760 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/type_condition.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/type_condition.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlTypeCondition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlTypeCondition, GraphqlTypeConditionFields}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlTypeCondition; impl FormatNodeRule for FormatGraphqlTypeCondition { @@ -9,6 +9,8 @@ impl FormatNodeRule for FormatGraphqlTypeCondition { node: &GraphqlTypeCondition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlTypeConditionFields { on_token, ty } = node.as_fields(); + + write!(f, [on_token.format(), space(), ty.format()]) } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/union_member_types.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/union_member_types.rs index 888defd6ecc7..305af92cacff 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/union_member_types.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/union_member_types.rs @@ -1,6 +1,9 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlUnionMemberTypes; -use biome_rowan::AstNode; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{ + GraphqlSyntaxToken, GraphqlUnionMemberTypes, GraphqlUnionMemberTypesFields, +}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlUnionMemberTypes; impl FormatNodeRule for FormatGraphqlUnionMemberTypes { @@ -9,6 +12,54 @@ impl FormatNodeRule for FormatGraphqlUnionMemberTypes { node: &GraphqlUnionMemberTypes, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlUnionMemberTypesFields { + eq_token, + bitwise_or_token, + members, + } = node.as_fields(); + + write!( + f, + [ + space(), + eq_token.format(), + if_group_fits_on_line(&space()), + soft_block_indent(&format_args![ + FormatTypeLeadingSeparator { + separator: "|", + leading_separator: bitwise_or_token.as_ref(), + }, + members.format(), + ]) + ] + ) + } +} + +pub struct FormatTypeLeadingSeparator<'a> { + separator: &'static str, + leading_separator: Option<&'a GraphqlSyntaxToken>, +} + +impl Format for FormatTypeLeadingSeparator<'_> { + fn fmt(&self, f: &mut GraphqlFormatter) -> FormatResult<()> { + match &self.leading_separator { + Some(token) => { + let content = format_with(|f| { + write!(f, [soft_line_break_or_space(), token.format(), space()]) + }); + write!(f, [format_only_if_breaks(token, &content)]) + } + None => { + let content = format_with(|f| { + write!( + f, + [soft_line_break_or_space(), text(self.separator), space()] + ) + }); + + write!(f, [if_group_breaks(&content)]) + } + } } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/variable.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/variable.rs index c4d8b7d12679..f196332807da 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/variable.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/variable.rs @@ -1,10 +1,13 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlVariable; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlVariable, GraphqlVariableFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlVariable; impl FormatNodeRule for FormatGraphqlVariable { fn fmt_fields(&self, node: &GraphqlVariable, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlVariableFields { dollar_token, name } = node.as_fields(); + + write![f, [dollar_token.format(), name.format(),]] } } diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/variable_definitions.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/variable_definitions.rs index 37ac716737e5..a118db881e88 100644 --- a/crates/biome_graphql_formatter/src/graphql/auxiliary/variable_definitions.rs +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/variable_definitions.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlVariableDefinitions; -use biome_rowan::AstNode; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlVariableDefinitions, GraphqlVariableDefinitionsFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlVariableDefinitions; impl FormatNodeRule for FormatGraphqlVariableDefinitions { @@ -9,6 +10,19 @@ impl FormatNodeRule for FormatGraphqlVariableDefinit node: &GraphqlVariableDefinitions, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlVariableDefinitionsFields { + l_paren_token, + elements, + r_paren_token, + } = node.as_fields(); + + write!( + f, + [group(&format_args!( + l_paren_token.format(), + soft_block_indent(&elements.format()), + r_paren_token.format(), + ))] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/arguments_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/arguments_definition.rs index 2c4a3fa328f0..3e72801709c7 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/arguments_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/arguments_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlArgumentsDefinition; -use biome_rowan::AstNode; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlArgumentsDefinition, GraphqlArgumentsDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlArgumentsDefinition; impl FormatNodeRule for FormatGraphqlArgumentsDefinition { @@ -9,6 +10,19 @@ impl FormatNodeRule for FormatGraphqlArgumentsDefini node: &GraphqlArgumentsDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlArgumentsDefinitionFields { + l_paren_token, + arguments, + r_paren_token, + } = node.as_fields(); + + write!( + f, + [group(&format_args!( + l_paren_token.format(), + soft_block_indent(&arguments.format()), + r_paren_token.format(), + ))] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/directive_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/directive_definition.rs index 634d67658e72..6c91e388fd99 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/directive_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/directive_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlDirectiveDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlDirectiveDefinition, GraphqlDirectiveDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlDirectiveDefinition; impl FormatNodeRule for FormatGraphqlDirectiveDefinition { @@ -9,6 +10,41 @@ impl FormatNodeRule for FormatGraphqlDirectiveDefini node: &GraphqlDirectiveDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlDirectiveDefinitionFields { + description, + directive_token, + at_token, + name, + arguments, + repeatable_token, + on_token, + bitwise_or_token, + locations, + } = node.as_fields(); + + if let Some(description) = description { + write!(f, [description.format(), hard_line_break(),])?; + } + + if let Some(bitwise_or_token) = bitwise_or_token { + write!(f, [format_removed(&bitwise_or_token)])?; + } + + write!( + f, + [ + directive_token.format(), + space(), + at_token.format(), + name.format(), + arguments.format(), + space(), + repeatable_token.format(), + space(), + on_token.format(), + space(), + locations.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/enum_type_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/enum_type_definition.rs index 8f59404f1bd2..f335573b44ae 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/enum_type_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/enum_type_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlEnumTypeDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlEnumTypeDefinition, GraphqlEnumTypeDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlEnumTypeDefinition; impl FormatNodeRule for FormatGraphqlEnumTypeDefinition { @@ -9,6 +10,28 @@ impl FormatNodeRule for FormatGraphqlEnumTypeDefiniti node: &GraphqlEnumTypeDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlEnumTypeDefinitionFields { + description, + enum_token, + name, + directives, + enum_values, + } = node.as_fields(); + + if let Some(description) = description { + write!(f, [description.format(), hard_line_break(),])?; + } + + write!( + f, + [ + enum_token.format(), + space(), + name.format(), + directives.format(), + space(), + enum_values.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/enum_value_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/enum_value_definition.rs index 655f2959b975..d6580d7e6c81 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/enum_value_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/enum_value_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlEnumValueDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlEnumValueDefinition, GraphqlEnumValueDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlEnumValueDefinition; impl FormatNodeRule for FormatGraphqlEnumValueDefinition { @@ -9,6 +10,16 @@ impl FormatNodeRule for FormatGraphqlEnumValueDefini node: &GraphqlEnumValueDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlEnumValueDefinitionFields { + description, + value, + directives, + } = node.as_fields(); + + if let Some(description) = description { + write!(f, [description.format(), hard_line_break(),])?; + } + + write!(f, [value.format(), directives.format(),]) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/enum_values_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/enum_values_definition.rs index 7514332e2e13..74b5a93b3174 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/enum_values_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/enum_values_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlEnumValuesDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlEnumValuesDefinition, GraphqlEnumValuesDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlEnumValuesDefinition; impl FormatNodeRule for FormatGraphqlEnumValuesDefinition { @@ -9,6 +10,19 @@ impl FormatNodeRule for FormatGraphqlEnumValuesDefi node: &GraphqlEnumValuesDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlEnumValuesDefinitionFields { + l_curly_token, + values, + r_curly_token, + } = node.as_fields(); + + write!( + f, + [ + l_curly_token.format(), + block_indent(&values.format()), + r_curly_token.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/field_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/field_definition.rs index 7d396f7768c4..fe0a9041c421 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/field_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/field_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlFieldDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlFieldDefinition, GraphqlFieldDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlFieldDefinition; impl FormatNodeRule for FormatGraphqlFieldDefinition { @@ -9,6 +10,29 @@ impl FormatNodeRule for FormatGraphqlFieldDefinition { node: &GraphqlFieldDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlFieldDefinitionFields { + description, + name, + arguments, + colon_token, + ty, + directives, + } = node.as_fields(); + + if let Some(description) = description { + write!(f, [description.format(), hard_line_break(),])?; + } + + write!( + f, + [ + name.format(), + arguments.format(), + colon_token.format(), + space(), + ty.format(), + directives.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/fields_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/fields_definition.rs index 95829215c600..5718b9a24969 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/fields_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/fields_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlFieldsDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlFieldsDefinition, GraphqlFieldsDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlFieldsDefinition; impl FormatNodeRule for FormatGraphqlFieldsDefinition { @@ -9,6 +10,19 @@ impl FormatNodeRule for FormatGraphqlFieldsDefinition { node: &GraphqlFieldsDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlFieldsDefinitionFields { + l_curly_token, + fields, + r_curly_token, + } = node.as_fields(); + + write!( + f, + [ + l_curly_token.format(), + block_indent(&fields.format()), + r_curly_token.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/fragment_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/fragment_definition.rs index a064069b800a..f214469c90db 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/fragment_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/fragment_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlFragmentDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlFragmentDefinition, GraphqlFragmentDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlFragmentDefinition; impl FormatNodeRule for FormatGraphqlFragmentDefinition { @@ -9,6 +10,26 @@ impl FormatNodeRule for FormatGraphqlFragmentDefiniti node: &GraphqlFragmentDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlFragmentDefinitionFields { + fragment_token, + name, + type_condition, + directives, + selection_set, + } = node.as_fields(); + + write!( + f, + [ + fragment_token.format(), + space(), + name.format(), + space(), + type_condition.format(), + directives.format(), + space(), + selection_set.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/input_fields_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/input_fields_definition.rs index 3e6e9eea8032..22a75b68b8d6 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/input_fields_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/input_fields_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlInputFieldsDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlInputFieldsDefinition, GraphqlInputFieldsDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlInputFieldsDefinition; impl FormatNodeRule for FormatGraphqlInputFieldsDefinition { @@ -9,6 +10,19 @@ impl FormatNodeRule for FormatGraphqlInputFieldsDe node: &GraphqlInputFieldsDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlInputFieldsDefinitionFields { + l_curly_token, + fields, + r_curly_token, + } = node.as_fields(); + + write![ + f, + [ + l_curly_token.format(), + block_indent(&fields.format()), + r_curly_token.format() + ] + ] } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/input_object_type_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/input_object_type_definition.rs index 9b857e484779..13d68e4432bd 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/input_object_type_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/input_object_type_definition.rs @@ -1,6 +1,9 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlInputObjectTypeDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{ + GraphqlInputObjectTypeDefinition, GraphqlInputObjectTypeDefinitionFields, +}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlInputObjectTypeDefinition; impl FormatNodeRule for FormatGraphqlInputObjectTypeDefinition { @@ -9,6 +12,26 @@ impl FormatNodeRule for FormatGraphqlInputObje node: &GraphqlInputObjectTypeDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlInputObjectTypeDefinitionFields { + description, + input_token, + name, + directives, + input_fields, + } = node.as_fields(); + + write!( + f, + [ + description.format(), + hard_line_break(), + input_token.format(), + space(), + name.format(), + directives.format(), + space(), + input_fields.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/input_value_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/input_value_definition.rs index e870b9e8a6da..4beea9c7cfc4 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/input_value_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/input_value_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlInputValueDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlInputValueDefinition, GraphqlInputValueDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlInputValueDefinition; impl FormatNodeRule for FormatGraphqlInputValueDefinition { @@ -9,6 +10,27 @@ impl FormatNodeRule for FormatGraphqlInputValueDefi node: &GraphqlInputValueDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlInputValueDefinitionFields { + description, + name, + colon_token, + ty, + default, + directives, + } = node.as_fields(); + + write!( + f, + [ + description.format(), + soft_line_break(), + name.format(), + colon_token.format(), + space(), + ty.format(), + default.format(), + directives.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/interface_type_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/interface_type_definition.rs index 390ce0b99af2..c81a23955319 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/interface_type_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/interface_type_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlInterfaceTypeDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlInterfaceTypeDefinition, GraphqlInterfaceTypeDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlInterfaceTypeDefinition; impl FormatNodeRule for FormatGraphqlInterfaceTypeDefinition { @@ -9,6 +10,31 @@ impl FormatNodeRule for FormatGraphqlInterfaceTy node: &GraphqlInterfaceTypeDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlInterfaceTypeDefinitionFields { + description, + interface_token, + name, + implements, + directives, + fields, + } = node.as_fields(); + + if let Some(description) = description { + write!(f, [description.format(), hard_line_break(),])?; + } + + write!(f, [interface_token.format(), space(), name.format(),])?; + + if let Some(implements) = implements { + write!(f, [space(), implements.format(),])?; + } + + write!(f, [directives.format()])?; + + if let Some(fields) = fields { + write!(f, [space(), fields.format(),])?; + } + + Ok(()) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/object_type_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/object_type_definition.rs index ca08c40d510c..5fb802a89394 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/object_type_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/object_type_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlObjectTypeDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlObjectTypeDefinition, GraphqlObjectTypeDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlObjectTypeDefinition; impl FormatNodeRule for FormatGraphqlObjectTypeDefinition { @@ -9,6 +10,29 @@ impl FormatNodeRule for FormatGraphqlObjectTypeDefi node: &GraphqlObjectTypeDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlObjectTypeDefinitionFields { + description, + type_token, + name, + implements, + directives, + fields, + } = node.as_fields(); + + write!( + f, + [ + description.format(), + hard_line_break(), + type_token.format(), + space(), + name.format(), + space(), + implements.format(), + directives.format(), + space(), + fields.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/operation_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/operation_definition.rs index 3c2fdc6acd6f..dee658fa3f4f 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/operation_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/operation_definition.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlOperationDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlOperationDefinition, GraphqlOperationDefinitionFields}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlOperationDefinition; impl FormatNodeRule for FormatGraphqlOperationDefinition { @@ -9,6 +9,33 @@ impl FormatNodeRule for FormatGraphqlOperationDefini node: &GraphqlOperationDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlOperationDefinitionFields { + ty, + name, + variables, + directives, + selection_set, + } = node.as_fields(); + + write!(f, [ty.format()])?; + + if let Some(name) = name.as_ref() { + // add space between operation type and name + write!(f, [space(), name.format()])?; + } else if variables.is_some() { + // if we don't have a name but we have variables, add a space + // between the operation type and the variables + write!(f, [space()])?; + } + + write!( + f, + [ + variables.format(), + directives.format(), + space(), + selection_set.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/root_operation_type_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/root_operation_type_definition.rs index 7c77b9de945c..0d0d1b97550d 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/root_operation_type_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/root_operation_type_definition.rs @@ -1,6 +1,9 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlRootOperationTypeDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{ + GraphqlRootOperationTypeDefinition, GraphqlRootOperationTypeDefinitionFields, +}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlRootOperationTypeDefinition; impl FormatNodeRule @@ -11,6 +14,20 @@ impl FormatNodeRule node: &GraphqlRootOperationTypeDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlRootOperationTypeDefinitionFields { + operation_type, + colon_token, + named_type, + } = node.as_fields(); + + write!( + f, + [ + operation_type.format(), + colon_token.format(), + space(), + named_type.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/scalar_type_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/scalar_type_definition.rs index 22802eda830d..c78cfe4350ec 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/scalar_type_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/scalar_type_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlScalarTypeDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlScalarTypeDefinition, GraphqlScalarTypeDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlScalarTypeDefinition; impl FormatNodeRule for FormatGraphqlScalarTypeDefinition { @@ -9,6 +10,25 @@ impl FormatNodeRule for FormatGraphqlScalarTypeDefi node: &GraphqlScalarTypeDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlScalarTypeDefinitionFields { + description, + scalar_token, + name, + directives, + } = node.as_fields(); + + if let Some(description) = description { + write!(f, [description.format(), hard_line_break(),])?; + } + + write!( + f, + [ + scalar_token.format(), + space(), + name.format(), + directives.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/schema_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/schema_definition.rs index 2b7038b08d53..d4791d292082 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/schema_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/schema_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlSchemaDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlSchemaDefinition, GraphqlSchemaDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlSchemaDefinition; impl FormatNodeRule for FormatGraphqlSchemaDefinition { @@ -9,6 +10,25 @@ impl FormatNodeRule for FormatGraphqlSchemaDefinition { node: &GraphqlSchemaDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlSchemaDefinitionFields { + description, + schema_token, + directives, + root_operation_types, + } = node.as_fields(); + + if let Some(description) = description { + write!(f, [description.format(), hard_line_break(),])?; + } + + write!( + f, + [ + schema_token.format(), + directives.format(), + space(), + root_operation_types.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/union_type_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/union_type_definition.rs index 78401ea8dbe8..016f9a536ab5 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/union_type_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/union_type_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlUnionTypeDefinition; -use biome_rowan::AstNode; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlUnionTypeDefinition, GraphqlUnionTypeDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlUnionTypeDefinition; impl FormatNodeRule for FormatGraphqlUnionTypeDefinition { @@ -9,6 +10,31 @@ impl FormatNodeRule for FormatGraphqlUnionTypeDefini node: &GraphqlUnionTypeDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlUnionTypeDefinitionFields { + description, + union_token, + name, + directives, + union_members, + } = node.as_fields(); + + write!( + f, + [group(&format_args!( + format_with(|f| { + if let Some(description) = description.as_ref() { + write!(f, [description.format(), hard_line_break(),])?; + } + Ok(()) + }), + group(&format_args!( + union_token.format(), + space(), + name.format(), + directives.format(), + union_members.format() + )) + ))] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/variable_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/variable_definition.rs index 5e3953a88483..0cc34f8b6498 100644 --- a/crates/biome_graphql_formatter/src/graphql/definitions/variable_definition.rs +++ b/crates/biome_graphql_formatter/src/graphql/definitions/variable_definition.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlVariableDefinition; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlVariableDefinition, GraphqlVariableDefinitionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlVariableDefinition; impl FormatNodeRule for FormatGraphqlVariableDefinition { @@ -9,6 +10,24 @@ impl FormatNodeRule for FormatGraphqlVariableDefiniti node: &GraphqlVariableDefinition, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlVariableDefinitionFields { + variable, + colon_token, + ty, + default, + directives, + } = node.as_fields(); + + write!( + f, + [ + variable.format(), + colon_token.format(), + space(), + ty.format(), + default.format(), + directives.format(), + ] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/extensions/enum_type_extension.rs b/crates/biome_graphql_formatter/src/graphql/extensions/enum_type_extension.rs index 130bd3cc24b0..ad44ad67349d 100644 --- a/crates/biome_graphql_formatter/src/graphql/extensions/enum_type_extension.rs +++ b/crates/biome_graphql_formatter/src/graphql/extensions/enum_type_extension.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlEnumTypeExtension; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlEnumTypeExtension, GraphqlEnumTypeExtensionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlEnumTypeExtension; impl FormatNodeRule for FormatGraphqlEnumTypeExtension { @@ -9,6 +10,26 @@ impl FormatNodeRule for FormatGraphqlEnumTypeExtension node: &GraphqlEnumTypeExtension, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlEnumTypeExtensionFields { + extend_token, + enum_token, + name, + directives, + enum_values, + } = node.as_fields(); + + write![ + f, + [ + extend_token.format(), + space(), + enum_token.format(), + space(), + name.format(), + directives.format(), + space(), + enum_values.format(), + ] + ] } } diff --git a/crates/biome_graphql_formatter/src/graphql/extensions/input_object_type_extension.rs b/crates/biome_graphql_formatter/src/graphql/extensions/input_object_type_extension.rs index c3e0c4f51703..37acc13f73fa 100644 --- a/crates/biome_graphql_formatter/src/graphql/extensions/input_object_type_extension.rs +++ b/crates/biome_graphql_formatter/src/graphql/extensions/input_object_type_extension.rs @@ -1,6 +1,9 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlInputObjectTypeExtension; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{ + GraphqlInputObjectTypeExtension, GraphqlInputObjectTypeExtensionFields, +}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlInputObjectTypeExtension; impl FormatNodeRule for FormatGraphqlInputObjectTypeExtension { @@ -9,6 +12,26 @@ impl FormatNodeRule for FormatGraphqlInputObjec node: &GraphqlInputObjectTypeExtension, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlInputObjectTypeExtensionFields { + extend_token, + input_token, + name, + directives, + input_fields, + } = node.as_fields(); + + write![ + f, + [ + extend_token.format(), + space(), + input_token.format(), + space(), + name.format(), + directives.format(), + space(), + input_fields.format(), + ] + ] } } diff --git a/crates/biome_graphql_formatter/src/graphql/extensions/interface_type_extension.rs b/crates/biome_graphql_formatter/src/graphql/extensions/interface_type_extension.rs index 1127784082ee..e01e18d94a27 100644 --- a/crates/biome_graphql_formatter/src/graphql/extensions/interface_type_extension.rs +++ b/crates/biome_graphql_formatter/src/graphql/extensions/interface_type_extension.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlInterfaceTypeExtension; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlInterfaceTypeExtension, GraphqlInterfaceTypeExtensionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlInterfaceTypeExtension; impl FormatNodeRule for FormatGraphqlInterfaceTypeExtension { @@ -9,6 +10,36 @@ impl FormatNodeRule for FormatGraphqlInterfaceTyp node: &GraphqlInterfaceTypeExtension, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlInterfaceTypeExtensionFields { + extend_token, + interface_token, + name, + implements, + directives, + fields, + } = node.as_fields(); + + write!( + f, + [ + extend_token.format(), + space(), + interface_token.format(), + space(), + name.format(), + ] + )?; + + if let Some(implements) = implements { + write!(f, [space(), implements.format(),])?; + } + + write!(f, [directives.format()])?; + + if let Some(fields) = fields { + write!(f, [space(), fields.format(),])?; + } + + Ok(()) } } diff --git a/crates/biome_graphql_formatter/src/graphql/extensions/object_type_extension.rs b/crates/biome_graphql_formatter/src/graphql/extensions/object_type_extension.rs index 35e7b16e7713..c3a0ef1dbf0d 100644 --- a/crates/biome_graphql_formatter/src/graphql/extensions/object_type_extension.rs +++ b/crates/biome_graphql_formatter/src/graphql/extensions/object_type_extension.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlObjectTypeExtension; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlObjectTypeExtension, GraphqlObjectTypeExtensionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlObjectTypeExtension; impl FormatNodeRule for FormatGraphqlObjectTypeExtension { @@ -9,6 +10,28 @@ impl FormatNodeRule for FormatGraphqlObjectTypeExten node: &GraphqlObjectTypeExtension, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlObjectTypeExtensionFields { + extend_token, + type_token, + name, + implements, + directives, + fields, + } = node.as_fields(); + + write![ + f, + [ + extend_token.format(), + space(), + type_token.format(), + space(), + name.format(), + implements.format(), + directives.format(), + space(), + fields.format(), + ] + ] } } diff --git a/crates/biome_graphql_formatter/src/graphql/extensions/scalar_type_extension.rs b/crates/biome_graphql_formatter/src/graphql/extensions/scalar_type_extension.rs index 6b51e848b155..4adcb63b3b64 100644 --- a/crates/biome_graphql_formatter/src/graphql/extensions/scalar_type_extension.rs +++ b/crates/biome_graphql_formatter/src/graphql/extensions/scalar_type_extension.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlScalarTypeExtension; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlScalarTypeExtension, GraphqlScalarTypeExtensionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlScalarTypeExtension; impl FormatNodeRule for FormatGraphqlScalarTypeExtension { @@ -9,6 +10,23 @@ impl FormatNodeRule for FormatGraphqlScalarTypeExten node: &GraphqlScalarTypeExtension, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlScalarTypeExtensionFields { + extend_token, + scalar_token, + name, + directives, + } = node.as_fields(); + + write![ + f, + [ + extend_token.format(), + space(), + scalar_token.format(), + space(), + name.format(), + directives.format(), + ] + ] } } diff --git a/crates/biome_graphql_formatter/src/graphql/extensions/schema_extension.rs b/crates/biome_graphql_formatter/src/graphql/extensions/schema_extension.rs index 428bc7c05ca2..92b0947a4585 100644 --- a/crates/biome_graphql_formatter/src/graphql/extensions/schema_extension.rs +++ b/crates/biome_graphql_formatter/src/graphql/extensions/schema_extension.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlSchemaExtension; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlSchemaExtension, GraphqlSchemaExtensionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlSchemaExtension; impl FormatNodeRule for FormatGraphqlSchemaExtension { @@ -9,6 +10,27 @@ impl FormatNodeRule for FormatGraphqlSchemaExtension { node: &GraphqlSchemaExtension, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlSchemaExtensionFields { + extend_token, + schema_token, + directives, + root_operation_types, + } = node.as_fields(); + + write!( + f, + [ + extend_token.format(), + space(), + schema_token.format(), + directives.format(), + ] + )?; + + if let Some(root_operation_types) = root_operation_types { + write!(f, [space(), root_operation_types.format(),])?; + } + + Ok(()) } } diff --git a/crates/biome_graphql_formatter/src/graphql/extensions/union_type_extension.rs b/crates/biome_graphql_formatter/src/graphql/extensions/union_type_extension.rs index e225a12078b7..1bdfa42eaea7 100644 --- a/crates/biome_graphql_formatter/src/graphql/extensions/union_type_extension.rs +++ b/crates/biome_graphql_formatter/src/graphql/extensions/union_type_extension.rs @@ -1,6 +1,7 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlUnionTypeExtension; -use biome_rowan::AstNode; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlUnionTypeExtension, GraphqlUnionTypeExtensionFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlUnionTypeExtension; impl FormatNodeRule for FormatGraphqlUnionTypeExtension { @@ -9,6 +10,25 @@ impl FormatNodeRule for FormatGraphqlUnionTypeExtensi node: &GraphqlUnionTypeExtension, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlUnionTypeExtensionFields { + extend_token, + union_token, + name, + directives, + union_members, + } = node.as_fields(); + + write![ + f, + [group(&format_args!( + extend_token.format(), + space(), + union_token.format(), + space(), + name.format(), + directives.format(), + union_members.format() + ))] + ] } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/argument_definition_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/argument_definition_list.rs index 3822dd4ebe92..4f3b68372355 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/argument_definition_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/argument_definition_list.rs @@ -1,5 +1,7 @@ use crate::prelude::*; +use biome_formatter::write; use biome_graphql_syntax::GraphqlArgumentDefinitionList; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlArgumentDefinitionList; impl FormatRule for FormatGraphqlArgumentDefinitionList { @@ -9,6 +11,24 @@ impl FormatRule for FormatGraphqlArgumentDefiniti node: &GraphqlArgumentDefinitionList, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + let mut join = f.join_nodes_with_soft_line(); + let last_index = node.len().saturating_sub(1); + + for (index, node) in node.iter().enumerate() { + join.entry( + node.syntax(), + &format_with(|f| { + write!(f, [node.format()])?; + + if index != last_index { + write!(f, [if_group_fits_on_line(&text(","))])?; + } + + Ok(()) + }), + ) + } + + join.finish() } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/argument_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/argument_list.rs index 7621d0c79e94..0b8f4a53833a 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/argument_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/argument_list.rs @@ -1,10 +1,30 @@ use crate::prelude::*; +use biome_formatter::write; use biome_graphql_syntax::GraphqlArgumentList; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlArgumentList; impl FormatRule for FormatGraphqlArgumentList { type Context = GraphqlFormatContext; fn fmt(&self, node: &GraphqlArgumentList, f: &mut GraphqlFormatter) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + let mut join = f.join_nodes_with_soft_line(); + let last_index = node.len().saturating_sub(1); + + for (index, node) in node.iter().enumerate() { + join.entry( + node.syntax(), + &format_with(|f| { + write!(f, [node.format()])?; + + if index != last_index { + write!(f, [if_group_fits_on_line(&text(","))])?; + } + + Ok(()) + }), + ) + } + + join.finish() } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/definition_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/definition_list.rs index bb2560cdfc64..939893841700 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/definition_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/definition_list.rs @@ -1,10 +1,20 @@ use crate::prelude::*; use biome_graphql_syntax::GraphqlDefinitionList; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlDefinitionList; impl FormatRule for FormatGraphqlDefinitionList { type Context = GraphqlFormatContext; fn fmt(&self, node: &GraphqlDefinitionList, f: &mut GraphqlFormatter) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + let mut join = f.join_nodes_with_hardline(); + + for definition in node { + join.entry( + definition.syntax(), + &format_or_verbatim(definition.format()), + ); + } + + join.finish() } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/directive_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/directive_list.rs index 4bc77b4e59a9..8fc894acb8dc 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/directive_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/directive_list.rs @@ -1,10 +1,36 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlDirectiveList; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlDirectiveList, GraphqlSyntaxKind}; +use biome_rowan::SyntaxNodeOptionExt; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlDirectiveList; impl FormatRule for FormatGraphqlDirectiveList { type Context = GraphqlFormatContext; fn fmt(&self, node: &GraphqlDirectiveList, f: &mut GraphqlFormatter) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + if node.len() == 0 { + return Ok(()); + } + + let list = format_once(|f| { + f.join_with(soft_line_break_or_space()) + .entries(node.iter().formatted()) + .finish() + }); + + if matches!( + node.syntax().parent().kind(), + Some( + GraphqlSyntaxKind::GRAPHQL_FRAGMENT_DEFINITION + | GraphqlSyntaxKind::GRAPHQL_OPERATION_DEFINITION + ) + ) { + write!( + f, + [group(&format_args!(&soft_line_break_or_space(), &list))] + ) + } else { + write!(f, [space(), group(&soft_block_indent(&list))]) + } } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/directive_location_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/directive_location_list.rs index 620d03cd6ccf..374ed863294e 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/directive_location_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/directive_location_list.rs @@ -1,4 +1,5 @@ use crate::prelude::*; +use biome_formatter::write; use biome_graphql_syntax::GraphqlDirectiveLocationList; #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlDirectiveLocationList; @@ -9,6 +10,22 @@ impl FormatRule for FormatGraphqlDirectiveLocation node: &GraphqlDirectiveLocationList, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + for (index, element) in node.elements().enumerate() { + let node = element.node(); + + if index != 0 { + write!(f, [space()])?; + } + + write!(f, [node.format()])?; + + let trailing_separator = element.trailing_separator()?; + + if let Some(token) = trailing_separator { + write![f, [space(), token.format()]]?; + } + } + + Ok(()) } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/enum_value_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/enum_value_list.rs index f70f095cd17b..5dbaef3beb81 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/enum_value_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/enum_value_list.rs @@ -5,6 +5,15 @@ pub(crate) struct FormatGraphqlEnumValueList; impl FormatRule for FormatGraphqlEnumValueList { type Context = GraphqlFormatContext; fn fmt(&self, node: &GraphqlEnumValueList, f: &mut GraphqlFormatter) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + let mut join = f.join_nodes_with_hardline(); + + for definition in node { + join.entry( + definition.syntax(), + &format_or_verbatim(definition.format()), + ); + } + + join.finish() } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/field_definition_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/field_definition_list.rs index 27c3a31e1ca3..c4b39845aa14 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/field_definition_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/field_definition_list.rs @@ -5,6 +5,15 @@ pub(crate) struct FormatGraphqlFieldDefinitionList; impl FormatRule for FormatGraphqlFieldDefinitionList { type Context = GraphqlFormatContext; fn fmt(&self, node: &GraphqlFieldDefinitionList, f: &mut GraphqlFormatter) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + let mut join = f.join_nodes_with_hardline(); + + for definition in node { + join.entry( + definition.syntax(), + &format_or_verbatim(definition.format()), + ); + } + + join.finish() } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/implements_interface_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/implements_interface_list.rs index dbbe570caf51..fdb761da8a65 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/implements_interface_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/implements_interface_list.rs @@ -1,5 +1,7 @@ use crate::prelude::*; +use biome_formatter::write; use biome_graphql_syntax::GraphqlImplementsInterfaceList; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlImplementsInterfaceList; impl FormatRule for FormatGraphqlImplementsInterfaceList { @@ -9,6 +11,22 @@ impl FormatRule for FormatGraphqlImplementsInter node: &GraphqlImplementsInterfaceList, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + for (index, element) in node.elements().enumerate() { + let node = element.node(); + + if index != 0 { + write!(f, [space()])?; + } + + write!(f, [node.format()])?; + + let trailing_separator = element.trailing_separator()?; + + if let Some(token) = trailing_separator { + write![f, [space(), token.format()]]?; + } + } + + Ok(()) } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/input_field_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/input_field_list.rs index c8beebb8f8d0..030588effca1 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/input_field_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/input_field_list.rs @@ -5,6 +5,15 @@ pub(crate) struct FormatGraphqlInputFieldList; impl FormatRule for FormatGraphqlInputFieldList { type Context = GraphqlFormatContext; fn fmt(&self, node: &GraphqlInputFieldList, f: &mut GraphqlFormatter) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + let mut join = f.join_nodes_with_hardline(); + + for definition in node { + join.entry( + definition.syntax(), + &format_or_verbatim(definition.format()), + ); + } + + join.finish() } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/list_value_element_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/list_value_element_list.rs index 72b17f250572..8b755bf70ed1 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/list_value_element_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/list_value_element_list.rs @@ -1,5 +1,7 @@ use crate::prelude::*; +use biome_formatter::format_args; use biome_graphql_syntax::GraphqlListValueElementList; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlListValueElementList; impl FormatRule for FormatGraphqlListValueElementList { @@ -9,6 +11,11 @@ impl FormatRule for FormatGraphqlListValueElementLi node: &GraphqlListValueElementList, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + f.join_with(&format_args!( + if_group_fits_on_line(&format_args![text(","), space()]), + soft_line_break(), + )) + .entries(node.iter().formatted()) + .finish() } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/object_value_member_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/object_value_member_list.rs index 697f98b975b5..65cd07862589 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/object_value_member_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/object_value_member_list.rs @@ -1,5 +1,7 @@ use crate::prelude::*; +use biome_formatter::format_args; use biome_graphql_syntax::GraphqlObjectValueMemberList; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlObjectValueMemberList; impl FormatRule for FormatGraphqlObjectValueMemberList { @@ -9,6 +11,11 @@ impl FormatRule for FormatGraphqlObjectValueMember node: &GraphqlObjectValueMemberList, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + f.join_with(&format_args!( + if_group_fits_on_line(&format_args![text(","), space()]), + soft_line_break(), + )) + .entries(node.iter().formatted()) + .finish() } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/root_operation_type_definition_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/root_operation_type_definition_list.rs index 9a4e24abad80..adb39694f2d9 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/root_operation_type_definition_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/root_operation_type_definition_list.rs @@ -11,6 +11,15 @@ impl FormatRule node: &GraphqlRootOperationTypeDefinitionList, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + let mut join = f.join_nodes_with_hardline(); + + for operation_type in node { + join.entry( + operation_type.syntax(), + &format_or_verbatim(operation_type.format()), + ); + } + + join.finish() } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/selection_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/selection_list.rs index d7a49426e34e..c88e27036b97 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/selection_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/selection_list.rs @@ -5,6 +5,15 @@ pub(crate) struct FormatGraphqlSelectionList; impl FormatRule for FormatGraphqlSelectionList { type Context = GraphqlFormatContext; fn fmt(&self, node: &GraphqlSelectionList, f: &mut GraphqlFormatter) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + let mut join = f.join_nodes_with_hardline(); + + for operation_type in node { + join.entry( + operation_type.syntax(), + &format_or_verbatim(operation_type.format()), + ); + } + + join.finish() } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/union_member_type_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/union_member_type_list.rs index 3f12f5a24b4b..826bf48f96b9 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/union_member_type_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/union_member_type_list.rs @@ -1,17 +1,48 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlUnionMemberTypeList; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlLanguage, GraphqlNamedType, GraphqlUnionMemberTypeList}; +use biome_rowan::AstSeparatedElement; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlUnionMemberTypeList; impl FormatRule for FormatGraphqlUnionMemberTypeList { type Context = GraphqlFormatContext; fn fmt(&self, node: &GraphqlUnionMemberTypeList, f: &mut GraphqlFormatter) -> FormatResult<()> { - let separator = soft_line_break_or_space(); - let mut joiner = f.join_with(&separator); + let last_index = node.len().saturating_sub(1); + + f.join_with(space()) + .entries( + node.elements() + .enumerate() + .map(|(index, item)| FormatTypeVariant { + last: index == last_index, + element: item, + }), + ) + .finish() + } +} + +pub struct FormatTypeVariant { + last: bool, + element: AstSeparatedElement, +} + +impl Format for FormatTypeVariant { + fn fmt(&self, f: &mut GraphqlFormatter) -> FormatResult<()> { + let separator = self.element.trailing_separator()?; + let node = self.element.node()?; + + write!(f, [node.format()])?; - for formatted in node.format_separated("|") { - joiner.entry(&formatted); + if let Some(token) = separator { + if self.last { + write!(f, [format_removed(token)])?; + } else { + write![f, [soft_line_break_or_space(), token.format()]]?; + } } - joiner.finish() + Ok(()) } } diff --git a/crates/biome_graphql_formatter/src/graphql/lists/variable_definition_list.rs b/crates/biome_graphql_formatter/src/graphql/lists/variable_definition_list.rs index 41931961a53e..11feccd7a1e2 100644 --- a/crates/biome_graphql_formatter/src/graphql/lists/variable_definition_list.rs +++ b/crates/biome_graphql_formatter/src/graphql/lists/variable_definition_list.rs @@ -1,4 +1,5 @@ use crate::prelude::*; +use biome_formatter::format_args; use biome_graphql_syntax::GraphqlVariableDefinitionList; #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlVariableDefinitionList; @@ -9,6 +10,11 @@ impl FormatRule for FormatGraphqlVariableDefiniti node: &GraphqlVariableDefinitionList, f: &mut GraphqlFormatter, ) -> FormatResult<()> { - f.join().entries(node.iter().formatted()).finish() + f.join_with(&format_args!( + if_group_fits_on_line(&format_args![text(","), space()]), + soft_line_break(), + )) + .entries(node.iter().formatted()) + .finish() } } diff --git a/crates/biome_graphql_formatter/src/graphql/value/boolean_value.rs b/crates/biome_graphql_formatter/src/graphql/value/boolean_value.rs index 63c7447a0e69..fc1791d9018d 100644 --- a/crates/biome_graphql_formatter/src/graphql/value/boolean_value.rs +++ b/crates/biome_graphql_formatter/src/graphql/value/boolean_value.rs @@ -1,10 +1,12 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlBooleanValue; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlBooleanValue, GraphqlBooleanValueFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlBooleanValue; impl FormatNodeRule for FormatGraphqlBooleanValue { fn fmt_fields(&self, node: &GraphqlBooleanValue, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlBooleanValueFields { value_token } = node.as_fields(); + write![f, [value_token.format()]] } } diff --git a/crates/biome_graphql_formatter/src/graphql/value/default_value.rs b/crates/biome_graphql_formatter/src/graphql/value/default_value.rs index 4dee26fcef7a..470fc4e1047d 100644 --- a/crates/biome_graphql_formatter/src/graphql/value/default_value.rs +++ b/crates/biome_graphql_formatter/src/graphql/value/default_value.rs @@ -1,10 +1,13 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlDefaultValue; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlDefaultValue, GraphqlDefaultValueFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlDefaultValue; impl FormatNodeRule for FormatGraphqlDefaultValue { fn fmt_fields(&self, node: &GraphqlDefaultValue, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlDefaultValueFields { eq_token, value } = node.as_fields(); + + write!(f, [space(), eq_token.format(), space(), value.format(),]) } } diff --git a/crates/biome_graphql_formatter/src/graphql/value/enum_value.rs b/crates/biome_graphql_formatter/src/graphql/value/enum_value.rs index 1204f7e564a9..316ac2d56b1a 100644 --- a/crates/biome_graphql_formatter/src/graphql/value/enum_value.rs +++ b/crates/biome_graphql_formatter/src/graphql/value/enum_value.rs @@ -1,10 +1,12 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlEnumValue; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlEnumValue, GraphqlEnumValueFields}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlEnumValue; impl FormatNodeRule for FormatGraphqlEnumValue { fn fmt_fields(&self, node: &GraphqlEnumValue, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlEnumValueFields { graphql_name } = node.as_fields(); + + write!(f, [graphql_name.format()]) } } diff --git a/crates/biome_graphql_formatter/src/graphql/value/float_value.rs b/crates/biome_graphql_formatter/src/graphql/value/float_value.rs index 63755b50e770..1f20194c08c8 100644 --- a/crates/biome_graphql_formatter/src/graphql/value/float_value.rs +++ b/crates/biome_graphql_formatter/src/graphql/value/float_value.rs @@ -1,10 +1,15 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlFloatValue; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlFloatValue, GraphqlFloatValueFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlFloatValue; impl FormatNodeRule for FormatGraphqlFloatValue { fn fmt_fields(&self, node: &GraphqlFloatValue, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlFloatValueFields { + graphql_float_literal_token, + } = node.as_fields(); + + write![f, [graphql_float_literal_token.format()]] } } diff --git a/crates/biome_graphql_formatter/src/graphql/value/int_value.rs b/crates/biome_graphql_formatter/src/graphql/value/int_value.rs index 3f4a759400a5..005dd58f4c0a 100644 --- a/crates/biome_graphql_formatter/src/graphql/value/int_value.rs +++ b/crates/biome_graphql_formatter/src/graphql/value/int_value.rs @@ -1,10 +1,15 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlIntValue; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlIntValue, GraphqlIntValueFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlIntValue; impl FormatNodeRule for FormatGraphqlIntValue { fn fmt_fields(&self, node: &GraphqlIntValue, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlIntValueFields { + graphql_int_literal_token, + } = node.as_fields(); + + write![f, [graphql_int_literal_token.format()]] } } diff --git a/crates/biome_graphql_formatter/src/graphql/value/list_value.rs b/crates/biome_graphql_formatter/src/graphql/value/list_value.rs index 9e868635434d..474d87d12938 100644 --- a/crates/biome_graphql_formatter/src/graphql/value/list_value.rs +++ b/crates/biome_graphql_formatter/src/graphql/value/list_value.rs @@ -1,10 +1,24 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlListValue; -use biome_rowan::AstNode; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlListValue, GraphqlListValueFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlListValue; impl FormatNodeRule for FormatGraphqlListValue { fn fmt_fields(&self, node: &GraphqlListValue, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlListValueFields { + l_brack_token, + elements, + r_brack_token, + } = node.as_fields(); + + write![ + f, + [group(&format_args!( + l_brack_token.format(), + soft_block_indent(&elements.format()), + r_brack_token.format() + ))] + ] } } diff --git a/crates/biome_graphql_formatter/src/graphql/value/null_value.rs b/crates/biome_graphql_formatter/src/graphql/value/null_value.rs index b2a43eae40a0..e830c3f60086 100644 --- a/crates/biome_graphql_formatter/src/graphql/value/null_value.rs +++ b/crates/biome_graphql_formatter/src/graphql/value/null_value.rs @@ -1,10 +1,13 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlNullValue; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlNullValue, GraphqlNullValueFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlNullValue; impl FormatNodeRule for FormatGraphqlNullValue { fn fmt_fields(&self, node: &GraphqlNullValue, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlNullValueFields { null_token } = node.as_fields(); + + write![f, [null_token.format()]] } } diff --git a/crates/biome_graphql_formatter/src/graphql/value/object_value.rs b/crates/biome_graphql_formatter/src/graphql/value/object_value.rs index 585e4ac04ea9..fdb85bceb2f0 100644 --- a/crates/biome_graphql_formatter/src/graphql/value/object_value.rs +++ b/crates/biome_graphql_formatter/src/graphql/value/object_value.rs @@ -1,10 +1,24 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlObjectValue; -use biome_rowan::AstNode; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlObjectValue, GraphqlObjectValueFields}; + #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlObjectValue; impl FormatNodeRule for FormatGraphqlObjectValue { fn fmt_fields(&self, node: &GraphqlObjectValue, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlObjectValueFields { + l_curly_token, + members, + r_curly_token, + } = node.as_fields(); + + write!( + f, + [group(&format_args![ + l_curly_token.format(), + soft_block_indent_with_maybe_space(&members.format(), true), // TODO implement options.bracket_spacing + r_curly_token.format() + ])] + ) } } diff --git a/crates/biome_graphql_formatter/src/graphql/value/string_value.rs b/crates/biome_graphql_formatter/src/graphql/value/string_value.rs index 76dcf50bad33..1a357d286254 100644 --- a/crates/biome_graphql_formatter/src/graphql/value/string_value.rs +++ b/crates/biome_graphql_formatter/src/graphql/value/string_value.rs @@ -1,10 +1,14 @@ use crate::prelude::*; -use biome_graphql_syntax::GraphqlStringValue; -use biome_rowan::AstNode; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlStringValue, GraphqlStringValueFields}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatGraphqlStringValue; impl FormatNodeRule for FormatGraphqlStringValue { fn fmt_fields(&self, node: &GraphqlStringValue, f: &mut GraphqlFormatter) -> FormatResult<()> { - format_verbatim_node(node.syntax()).fmt(f) + let GraphqlStringValueFields { + graphql_string_literal_token, + } = node.as_fields(); + + write![f, [graphql_string_literal_token.format()]] } } diff --git a/crates/biome_graphql_formatter/src/lib.rs b/crates/biome_graphql_formatter/src/lib.rs index a1dae4026354..bc6d9577f41d 100644 --- a/crates/biome_graphql_formatter/src/lib.rs +++ b/crates/biome_graphql_formatter/src/lib.rs @@ -4,7 +4,6 @@ mod cst; mod generated; mod graphql; mod prelude; -mod separated; use crate::comments::GraphqlCommentStyle; pub(crate) use crate::context::GraphqlFormatContext; diff --git a/crates/biome_graphql_formatter/src/prelude.rs b/crates/biome_graphql_formatter/src/prelude.rs index 5aa565352a69..cecf0bab06c7 100644 --- a/crates/biome_graphql_formatter/src/prelude.rs +++ b/crates/biome_graphql_formatter/src/prelude.rs @@ -11,5 +11,3 @@ pub(crate) use biome_formatter::prelude::*; pub(crate) use biome_rowan::{ AstNode as _, AstNodeList as _, AstNodeSlotMap as _, AstSeparatedList as _, }; - -pub(crate) use crate::separated::FormatAstSeparatedListExtension; diff --git a/crates/biome_graphql_formatter/src/separated.rs b/crates/biome_graphql_formatter/src/separated.rs deleted file mode 100644 index 144951fcf4bb..000000000000 --- a/crates/biome_graphql_formatter/src/separated.rs +++ /dev/null @@ -1,59 +0,0 @@ -use crate::prelude::*; -use crate::FormatGraphqlSyntaxToken; -use biome_formatter::separated::{ - FormatSeparatedElementRule, FormatSeparatedIter, TrailingSeparator, -}; -use biome_formatter::FormatRefWithRule; -use biome_graphql_syntax::{GraphqlLanguage, GraphqlSyntaxToken}; -use biome_rowan::{AstNode, AstSeparatedList, AstSeparatedListElementsIterator}; -use std::marker::PhantomData; - -#[derive(Clone)] -pub(crate) struct GraphqlFormatSeparatedElementRule { - node: PhantomData, -} - -impl FormatSeparatedElementRule for GraphqlFormatSeparatedElementRule -where - N: AstNode + AsFormat + 'static, -{ - type Context = GraphqlFormatContext; - type FormatNode<'a> = N::Format<'a>; - type FormatSeparator<'a> = FormatRefWithRule<'a, GraphqlSyntaxToken, FormatGraphqlSyntaxToken>; - - fn format_node<'a>(&self, node: &'a N) -> Self::FormatNode<'a> { - node.format() - } - - fn format_separator<'a>(&self, separator: &'a GraphqlSyntaxToken) -> Self::FormatSeparator<'a> { - separator.format() - } -} - -type GraphqlFormatSeparatedIter = FormatSeparatedIter< - AstSeparatedListElementsIterator, - Node, - GraphqlFormatSeparatedElementRule, ->; - -/// AST Separated list formatting extension methods -pub(crate) trait FormatAstSeparatedListExtension: - AstSeparatedList -{ - /// Prints a separated list of nodes - /// - /// Trailing separators will be reused from the original list or created by - /// calling the `separator_factory` function. The last trailing separator - /// will not be printed by default. Use `with_trailing_separator` to add it - /// in where necessary. - fn format_separated(&self, separator: &'static str) -> GraphqlFormatSeparatedIter { - GraphqlFormatSeparatedIter::new( - self.elements(), - separator, - GraphqlFormatSeparatedElementRule { node: PhantomData }, - ) - .with_trailing_separator(TrailingSeparator::Disallowed) - } -} - -impl FormatAstSeparatedListExtension for T where T: AstSeparatedList {} diff --git a/crates/biome_graphql_formatter/tests/quick_test.rs b/crates/biome_graphql_formatter/tests/quick_test.rs index 333b1b3ba051..ca77350018b8 100644 --- a/crates/biome_graphql_formatter/tests/quick_test.rs +++ b/crates/biome_graphql_formatter/tests/quick_test.rs @@ -13,22 +13,27 @@ mod language { // use this test check if your snippet prints as you wish, without using a snapshot fn quick_test() { let src = r#" -{ - hero @deprecated -} +type Artist implements Node & Entity { + # The ID of an object + id: ID! -{ - hero @deprecated(reason: "Deprecated") -} + # The MBID of the entity. + mbid: MBID! -{ - hero @input(type: String) -} + # A list of recordings linked to this entity. + recordings(after: String, first: Int): RecordingConnection + + # A list of releases linked to this entity. + releases( + # Filter by one or more release group types. + type: [ReleaseGroupType] + + # Filter by one or more release statuses. + status: [ReleaseStatus] + after: String + first: Int + ): ReleaseConnection -{ - hero - @deprecated(reason: "Deprecated") - @addExternalFields(source: "profiles") } "#; diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/directive_definition.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/directive_definition.graphql new file mode 100644 index 000000000000..e2ae334c0d1e --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/directive_definition.graphql @@ -0,0 +1,35 @@ +directive +@example + +on + FIELD + +directive @example +on + FIELD_DEFINITION + + | + ARGUMENT_DEFINITION + +directive @example +on + | FIELD + + | + FRAGMENT_SPREAD + | + INLINE_FRAGMENT + +"deprecated" +directive +@delegateField(name: String!) +repeatable on + OBJECT + | INTERFACE + +directive +@directive(directive: + directive) + + +on FIELD diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/directive_definition.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/directive_definition.graphql.snap new file mode 100644 index 000000000000..dca4025c147e --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/directive_definition.graphql.snap @@ -0,0 +1,72 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/directive_definition.graphql +--- +# Input + +```graphql +directive +@example + +on + FIELD + +directive @example +on + FIELD_DEFINITION + + | + ARGUMENT_DEFINITION + +directive @example +on + | FIELD + + | + FRAGMENT_SPREAD + | + INLINE_FRAGMENT + +"deprecated" +directive +@delegateField(name: String!) +repeatable on + OBJECT + | INTERFACE + +directive +@directive(directive: + directive) + + +on FIELD + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +directive @example on FIELD + +directive @example on FIELD_DEFINITION | ARGUMENT_DEFINITION + +directive @example on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + +"deprecated" +directive @delegateField(name: String!) repeatable on OBJECT | INTERFACE + +directive @directive(directive: directive) on FIELD +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum.graphql new file mode 100644 index 000000000000..40773d21fcae --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum.graphql @@ -0,0 +1,35 @@ + enum name + { + NORTH + EAST + + + SOUTH + WEST + + + union + type + interface + enum +} + +enum Direction { } + +enum Direction + +enum +Direction + +@deprecated + +{ + "north" NORTH + + + @deprecated +} + +"This is an enum" + +enum Direction @deprecated diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum.graphql.snap new file mode 100644 index 000000000000..7637200bece9 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum.graphql.snap @@ -0,0 +1,86 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/enum.graphql +--- +# Input + +```graphql + enum name + { + NORTH + EAST + + + SOUTH + WEST + + + union + type + interface + enum +} + +enum Direction { } + +enum Direction + +enum +Direction + +@deprecated + +{ + "north" NORTH + + + @deprecated +} + +"This is an enum" + +enum Direction @deprecated + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +enum name { + NORTH + EAST + + SOUTH + WEST + + union + type + interface + enum +} + +enum Direction {} + +enum Direction + +enum Direction @deprecated { + "north" + NORTH @deprecated +} + +"This is an enum" +enum Direction @deprecated +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum_extension.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum_extension.graphql new file mode 100644 index 000000000000..ec6635b03c1a --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum_extension.graphql @@ -0,0 +1,26 @@ +extend + +enum + +Direction + +@deprecated + +extend + +enum Direction + +{ + NORTH +} + +extend enum + +Direction + +@deprecated + +{ + NORTH +} + diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum_extension.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum_extension.graphql.snap new file mode 100644 index 000000000000..7e1c2deb2d50 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/enum_extension.graphql.snap @@ -0,0 +1,62 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/enum_extension.graphql +--- +# Input + +```graphql +extend + +enum + +Direction + +@deprecated + +extend + +enum Direction + +{ + NORTH +} + +extend enum + +Direction + +@deprecated + +{ + NORTH +} + + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +extend enum Direction @deprecated + +extend enum Direction { + NORTH +} + +extend enum Direction @deprecated { + NORTH +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/fragment.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/fragment.graphql new file mode 100644 index 000000000000..0a0ddcd5f755 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/fragment.graphql @@ -0,0 +1,31 @@ +fragment friendFields + +on + +User +{ + id + + + name + + profilePic(size: 50) +} + +fragment friendFields on User @deprecated { + id + + + name + + + profilePic(size: 50) + + + query + + { + fragment + } + +} diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/fragment.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/fragment.graphql.snap new file mode 100644 index 000000000000..b94045c3b883 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/fragment.graphql.snap @@ -0,0 +1,77 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/fragment.graphql +--- +# Input + +```graphql +fragment friendFields + +on + +User +{ + id + + + name + + profilePic(size: 50) +} + +fragment friendFields on User @deprecated { + id + + + name + + + profilePic(size: 50) + + + query + + { + fragment + } + +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +fragment friendFields on User { + id + + name + + profilePic(size: 50) +} + +fragment friendFields on User @deprecated { + id + + name + + profilePic(size: 50) + + query { + fragment + } +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object.graphql new file mode 100644 index 000000000000..ad67d25ad567 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object.graphql @@ -0,0 +1,57 @@ +input Point2D { + x: Float + y: Float +} + +input Point2D { + + +} + +input Point2D + +input Point2D + + +@deprecated + + +{ + + + + x: Float +} + +"This is an input object" + + +input +Point2D + + +@deprecated + +input Point2D + +{ + x: + + Float = 0 + "this is y" + + y: Float + + @deprecated +} + +input + +input + +@input { + input: + + input +} + diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object.graphql.snap new file mode 100644 index 000000000000..71354898d58a --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object.graphql.snap @@ -0,0 +1,109 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/input_object.graphql +--- +# Input + +```graphql +input Point2D { + x: Float + y: Float +} + +input Point2D { + + +} + +input Point2D + +input Point2D + + +@deprecated + + +{ + + + + x: Float +} + +"This is an input object" + + +input +Point2D + + +@deprecated + +input Point2D + +{ + x: + + Float = 0 + "this is y" + + y: Float + + @deprecated +} + +input + +input + +@input { + input: + + input +} + + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +input Point2D { + x: Float + y: Float +} + +input Point2D {} + +input Point2D + +input Point2D @deprecated { + x: Float +} + +"This is an input object" +input Point2D @deprecated + +input Point2D { + x: Float = 0 + "this is y" + y: Float @deprecated +} + +input input @input { + input: input +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object_extension.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object_extension.graphql new file mode 100644 index 000000000000..62c3c441bf19 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object_extension.graphql @@ -0,0 +1,29 @@ +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_formatter/tests/specs/graphql/definitions/input_object_extension.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object_extension.graphql.snap new file mode 100644 index 000000000000..7484ed42c35f --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/input_object_extension.graphql.snap @@ -0,0 +1,69 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/input_object_extension.graphql +--- +# Input + +```graphql +extend + +input + +Point2D + +{ + x: Float + + + y: Float +} + +extend input + +Point2D + +@deprecated + +extend + +input Point2D + +@deprecated { + x: Float + + + y: Float +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +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_formatter/tests/specs/graphql/definitions/interface.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface.graphql new file mode 100644 index 000000000000..3b174bcfeaf1 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface.graphql @@ -0,0 +1,91 @@ +interface + Person + +{ + + name: String + + age: Int + picture: Url +} + +interface + +Person + +@deprecated + +{ + name: + + String +} + +interface Person + +implements Character @deprecated{ + + name:String +} + +interface Person + +implements Character + +{ + name: + + String +} + +interface Person + +interface Person implements + + Character + +interface Person + +@deprecated + +interface Person + +implements Character + +@deprecated + +interface Person + +implements Character + +& Character1 @deprecated + +interface Person { + name(start_with: + + String): String + + "filder by age" age: + + Int @deprecated + + + picture(size: Int = 0): Url + + + height("filter by height" + + greater_than: Int @deprecated): Int + weight("filter by weight" + + greater_than: Int = 0 @deprecated): Int +} + +interface + +interface +implements interface { + interface: + + interface +} diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface.graphql.snap new file mode 100644 index 000000000000..e0209d3f3e20 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface.graphql.snap @@ -0,0 +1,162 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/interface.graphql +--- +# Input + +```graphql +interface + Person + +{ + + name: String + + age: Int + picture: Url +} + +interface + +Person + +@deprecated + +{ + name: + + String +} + +interface Person + +implements Character @deprecated{ + + name:String +} + +interface Person + +implements Character + +{ + name: + + String +} + +interface Person + +interface Person implements + + Character + +interface Person + +@deprecated + +interface Person + +implements Character + +@deprecated + +interface Person + +implements Character + +& Character1 @deprecated + +interface Person { + name(start_with: + + String): String + + "filder by age" age: + + Int @deprecated + + + picture(size: Int = 0): Url + + + height("filter by height" + + greater_than: Int @deprecated): Int + weight("filter by weight" + + greater_than: Int = 0 @deprecated): Int +} + +interface + +interface +implements interface { + interface: + + interface +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +interface Person { + name: String + + age: Int + picture: Url +} + +interface Person @deprecated { + name: String +} + +interface Person implements Character @deprecated { + name: String +} + +interface Person implements Character { + name: String +} + +interface Person + +interface Person implements Character + +interface Person @deprecated + +interface Person implements Character @deprecated + +interface Person implements Character & Character1 @deprecated + +interface Person { + name(start_with: String): String + + "filder by age" + age: Int @deprecated + + picture(size: Int = 0): Url + + height("filter by height"greater_than: Int @deprecated): Int + weight("filter by weight"greater_than: Int = 0 @deprecated): Int +} + +interface interface implements interface { + interface: interface +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface_extension.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface_extension.graphql new file mode 100644 index 000000000000..b8bc2fa64cf1 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface_extension.graphql @@ -0,0 +1,45 @@ +extend + +interface + +Story { + isHiddenLocally: + + Boolean +} + +extend + +interface User + +@addedDirective + +extend + +interface User implements Character + +extend + + interface User + + implements Character + +@deprecated + +extend + +interface User + + @deprecated { + name: String +} + +extend + +interface + +User implements Character + +@deprecated { + name: String +} diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface_extension.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface_extension.graphql.snap new file mode 100644 index 000000000000..f420f8b85929 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/interface_extension.graphql.snap @@ -0,0 +1,89 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/interface_extension.graphql +--- +# Input + +```graphql +extend + +interface + +Story { + isHiddenLocally: + + Boolean +} + +extend + +interface User + +@addedDirective + +extend + +interface User implements Character + +extend + + interface User + + implements Character + +@deprecated + +extend + +interface User + + @deprecated { + name: String +} + +extend + +interface + +User implements Character + +@deprecated { + name: String +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +extend interface Story { + isHiddenLocally: Boolean +} + +extend interface User @addedDirective + +extend interface User implements Character + +extend interface User implements Character @deprecated + +extend interface User @deprecated { + name: String +} + +extend interface User implements Character @deprecated { + name: String +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object.graphql new file mode 100644 index 000000000000..da0245f5c0d7 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object.graphql @@ -0,0 +1,97 @@ +type Person { + name: String + age: Int + picture: Url +} + +type + +Person + +@deprecated { + name: String +} + +type Animal + +{ +"type of the animal" + + +type:String +} + +type Person +implements Character @deprecated { + name: + + String +} + +type Person implements Character { + name: String +} + +type Person + +type Person + +implements Character + +type Person + +implements Character & type + +type Person + +@deprecated + +type Person implements + +Character @deprecated + +type Person + +implements + +Character & Character1 + +@deprecated + +"This is a person" + + + type Person{ + name(start_with: + String): String + "filder by age" age: Int @deprecated + picture(size: Int = 0): Url + height( + + "filter by height" + + greater_than: Int @deprecated): + + Int + weight("filter by weight" + + greater_than: Int = 0 @deprecated): + + Int + "filter by weight" + + weight("filter by weight" greater_than: + + Int = 0 @deprecated): Int +} + +type type + +implements type + +{ + type: + + type +} + diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object.graphql.snap new file mode 100644 index 000000000000..0e0961fe4b3d --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object.graphql.snap @@ -0,0 +1,174 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/object.graphql +--- +# Input + +```graphql +type Person { + name: String + age: Int + picture: Url +} + +type + +Person + +@deprecated { + name: String +} + +type Animal + +{ +"type of the animal" + + +type:String +} + +type Person +implements Character @deprecated { + name: + + String +} + +type Person implements Character { + name: String +} + +type Person + +type Person + +implements Character + +type Person + +implements Character & type + +type Person + +@deprecated + +type Person implements + +Character @deprecated + +type Person + +implements + +Character & Character1 + +@deprecated + +"This is a person" + + + type Person{ + name(start_with: + String): String + "filder by age" age: Int @deprecated + picture(size: Int = 0): Url + height( + + "filter by height" + + greater_than: Int @deprecated): + + Int + weight("filter by weight" + + greater_than: Int = 0 @deprecated): + + Int + "filter by weight" + + weight("filter by weight" greater_than: + + Int = 0 @deprecated): Int +} + +type type + +implements type + +{ + type: + + type +} + + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +type Person { + name: String + age: Int + picture: Url +} + +type Person @deprecated { + name: String +} + +type Animal { + "type of the animal" + type: String +} + +type Person implements Character @deprecated { + name: String +} + +type Person implements Character { + name: String +} + +type Person + +type Person implements Character + +type Person implements Character & type + +type Person @deprecated + +type Person implements Character @deprecated + +type Person implements Character & Character1 @deprecated + +"This is a person" +type Person { + name(start_with: String): String + "filder by age" + age: Int @deprecated + picture(size: Int = 0): Url + height("filter by height"greater_than: Int @deprecated): Int + weight("filter by weight"greater_than: Int = 0 @deprecated): Int + "filter by weight" + weight("filter by weight"greater_than: Int = 0 @deprecated): Int +} + +type type implements type { + type: type +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object_extension.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object_extension.graphql new file mode 100644 index 000000000000..251cf1f5ea10 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object_extension.graphql @@ -0,0 +1,37 @@ +extend type Story { + + + isHiddenLocally: Boolean +} + +extend + + type User @addedDirective + +extend type + + User implements +Character + +extend type User + + implements Character + + @deprecated + +extend type + + User +@deprecated { + name:String + + +} + +extend type + User implements + + Character +@deprecated { + name:String +} diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object_extension.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object_extension.graphql.snap new file mode 100644 index 000000000000..c911b98f85a3 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object_extension.graphql.snap @@ -0,0 +1,350 @@ +--- +source: crates/biome_graphql_parser/tests/spec_test.rs +expression: snapshot +--- +## Input +```graphql +extend type Story { + isHiddenLocally: Boolean +} + +extend type User @addedDirective + +extend type User implements Character + +extend type User implements Character @deprecated + +extend type User @deprecated { + name: String +} + +extend type User implements Character @deprecated { + name: String +} + +``` + +## AST + +``` +GraphqlRoot { + bom_token: missing (optional), + definitions: GraphqlDefinitionList [ + GraphqlObjectTypeExtension { + extend_token: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")], + type_token: TYPE_KW@7..12 "type" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@12..18 "Story" [] [Whitespace(" ")], + }, + implements: missing (optional), + directives: GraphqlDirectiveList [], + fields: GraphqlFieldsDefinition { + l_curly_token: L_CURLY@18..19 "{" [] [], + fields: GraphqlFieldDefinitionList [ + GraphqlFieldDefinition { + description: missing (optional), + name: GraphqlName { + value_token: GRAPHQL_NAME@19..37 "isHiddenLocally" [Newline("\n"), Whitespace(" ")] [], + }, + arguments: missing (optional), + colon_token: COLON@37..39 ":" [] [Whitespace(" ")], + ty: GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@39..46 "Boolean" [] [], + }, + }, + directives: GraphqlDirectiveList [], + }, + ], + r_curly_token: R_CURLY@46..48 "}" [Newline("\n")] [], + }, + }, + GraphqlObjectTypeExtension { + extend_token: EXTEND_KW@48..57 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + type_token: TYPE_KW@57..62 "type" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@62..67 "User" [] [Whitespace(" ")], + }, + implements: missing (optional), + directives: GraphqlDirectiveList [ + GraphqlDirective { + at_token: AT@67..68 "@" [] [], + name: GraphqlName { + value_token: GRAPHQL_NAME@68..82 "addedDirective" [] [], + }, + arguments: missing (optional), + }, + ], + fields: missing (optional), + }, + GraphqlObjectTypeExtension { + extend_token: EXTEND_KW@82..91 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + type_token: TYPE_KW@91..96 "type" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@96..101 "User" [] [Whitespace(" ")], + }, + implements: GraphqlImplementsInterfaces { + implements_token: IMPLEMENTS_KW@101..112 "implements" [] [Whitespace(" ")], + amp_token: missing (optional), + interfaces: GraphqlImplementsInterfaceList [ + GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@112..121 "Character" [] [], + }, + }, + ], + }, + directives: GraphqlDirectiveList [], + fields: missing (optional), + }, + GraphqlObjectTypeExtension { + extend_token: EXTEND_KW@121..130 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + type_token: TYPE_KW@130..135 "type" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@135..140 "User" [] [Whitespace(" ")], + }, + implements: GraphqlImplementsInterfaces { + implements_token: IMPLEMENTS_KW@140..151 "implements" [] [Whitespace(" ")], + amp_token: missing (optional), + interfaces: GraphqlImplementsInterfaceList [ + GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@151..161 "Character" [] [Whitespace(" ")], + }, + }, + ], + }, + directives: GraphqlDirectiveList [ + GraphqlDirective { + at_token: AT@161..162 "@" [] [], + name: GraphqlName { + value_token: GRAPHQL_NAME@162..172 "deprecated" [] [], + }, + arguments: missing (optional), + }, + ], + fields: missing (optional), + }, + GraphqlObjectTypeExtension { + extend_token: EXTEND_KW@172..181 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + type_token: TYPE_KW@181..186 "type" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@186..191 "User" [] [Whitespace(" ")], + }, + implements: missing (optional), + directives: GraphqlDirectiveList [ + GraphqlDirective { + at_token: AT@191..192 "@" [] [], + name: GraphqlName { + value_token: GRAPHQL_NAME@192..203 "deprecated" [] [Whitespace(" ")], + }, + arguments: missing (optional), + }, + ], + fields: GraphqlFieldsDefinition { + l_curly_token: L_CURLY@203..204 "{" [] [], + fields: GraphqlFieldDefinitionList [ + GraphqlFieldDefinition { + description: missing (optional), + name: GraphqlName { + value_token: GRAPHQL_NAME@204..211 "name" [Newline("\n"), Whitespace(" ")] [], + }, + arguments: missing (optional), + colon_token: COLON@211..213 ":" [] [Whitespace(" ")], + ty: GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@213..219 "String" [] [], + }, + }, + directives: GraphqlDirectiveList [], + }, + ], + r_curly_token: R_CURLY@219..221 "}" [Newline("\n")] [], + }, + }, + GraphqlObjectTypeExtension { + extend_token: EXTEND_KW@221..230 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")], + type_token: TYPE_KW@230..235 "type" [] [Whitespace(" ")], + name: GraphqlName { + value_token: GRAPHQL_NAME@235..240 "User" [] [Whitespace(" ")], + }, + implements: GraphqlImplementsInterfaces { + implements_token: IMPLEMENTS_KW@240..251 "implements" [] [Whitespace(" ")], + amp_token: missing (optional), + interfaces: GraphqlImplementsInterfaceList [ + GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@251..261 "Character" [] [Whitespace(" ")], + }, + }, + ], + }, + directives: GraphqlDirectiveList [ + GraphqlDirective { + at_token: AT@261..262 "@" [] [], + name: GraphqlName { + value_token: GRAPHQL_NAME@262..273 "deprecated" [] [Whitespace(" ")], + }, + arguments: missing (optional), + }, + ], + fields: GraphqlFieldsDefinition { + l_curly_token: L_CURLY@273..274 "{" [] [], + fields: GraphqlFieldDefinitionList [ + GraphqlFieldDefinition { + description: missing (optional), + name: GraphqlName { + value_token: GRAPHQL_NAME@274..281 "name" [Newline("\n"), Whitespace(" ")] [], + }, + arguments: missing (optional), + colon_token: COLON@281..283 ":" [] [Whitespace(" ")], + ty: GraphqlNamedType { + name: GraphqlName { + value_token: GRAPHQL_NAME@283..289 "String" [] [], + }, + }, + directives: GraphqlDirectiveList [], + }, + ], + r_curly_token: R_CURLY@289..291 "}" [Newline("\n")] [], + }, + }, + ], + eof_token: EOF@291..292 "" [Newline("\n")] [], +} +``` + +## CST + +``` +0: GRAPHQL_ROOT@0..292 + 0: (empty) + 1: GRAPHQL_DEFINITION_LIST@0..291 + 0: GRAPHQL_OBJECT_TYPE_EXTENSION@0..48 + 0: EXTEND_KW@0..7 "extend" [] [Whitespace(" ")] + 1: TYPE_KW@7..12 "type" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@12..18 + 0: GRAPHQL_NAME@12..18 "Story" [] [Whitespace(" ")] + 3: (empty) + 4: GRAPHQL_DIRECTIVE_LIST@18..18 + 5: GRAPHQL_FIELDS_DEFINITION@18..48 + 0: L_CURLY@18..19 "{" [] [] + 1: GRAPHQL_FIELD_DEFINITION_LIST@19..46 + 0: GRAPHQL_FIELD_DEFINITION@19..46 + 0: (empty) + 1: GRAPHQL_NAME@19..37 + 0: GRAPHQL_NAME@19..37 "isHiddenLocally" [Newline("\n"), Whitespace(" ")] [] + 2: (empty) + 3: COLON@37..39 ":" [] [Whitespace(" ")] + 4: GRAPHQL_NAMED_TYPE@39..46 + 0: GRAPHQL_NAME@39..46 + 0: GRAPHQL_NAME@39..46 "Boolean" [] [] + 5: GRAPHQL_DIRECTIVE_LIST@46..46 + 2: R_CURLY@46..48 "}" [Newline("\n")] [] + 1: GRAPHQL_OBJECT_TYPE_EXTENSION@48..82 + 0: EXTEND_KW@48..57 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: TYPE_KW@57..62 "type" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@62..67 + 0: GRAPHQL_NAME@62..67 "User" [] [Whitespace(" ")] + 3: (empty) + 4: GRAPHQL_DIRECTIVE_LIST@67..82 + 0: GRAPHQL_DIRECTIVE@67..82 + 0: AT@67..68 "@" [] [] + 1: GRAPHQL_NAME@68..82 + 0: GRAPHQL_NAME@68..82 "addedDirective" [] [] + 2: (empty) + 5: (empty) + 2: GRAPHQL_OBJECT_TYPE_EXTENSION@82..121 + 0: EXTEND_KW@82..91 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: TYPE_KW@91..96 "type" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@96..101 + 0: GRAPHQL_NAME@96..101 "User" [] [Whitespace(" ")] + 3: GRAPHQL_IMPLEMENTS_INTERFACES@101..121 + 0: IMPLEMENTS_KW@101..112 "implements" [] [Whitespace(" ")] + 1: (empty) + 2: GRAPHQL_IMPLEMENTS_INTERFACE_LIST@112..121 + 0: GRAPHQL_NAMED_TYPE@112..121 + 0: GRAPHQL_NAME@112..121 + 0: GRAPHQL_NAME@112..121 "Character" [] [] + 4: GRAPHQL_DIRECTIVE_LIST@121..121 + 5: (empty) + 3: GRAPHQL_OBJECT_TYPE_EXTENSION@121..172 + 0: EXTEND_KW@121..130 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: TYPE_KW@130..135 "type" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@135..140 + 0: GRAPHQL_NAME@135..140 "User" [] [Whitespace(" ")] + 3: GRAPHQL_IMPLEMENTS_INTERFACES@140..161 + 0: IMPLEMENTS_KW@140..151 "implements" [] [Whitespace(" ")] + 1: (empty) + 2: GRAPHQL_IMPLEMENTS_INTERFACE_LIST@151..161 + 0: GRAPHQL_NAMED_TYPE@151..161 + 0: GRAPHQL_NAME@151..161 + 0: GRAPHQL_NAME@151..161 "Character" [] [Whitespace(" ")] + 4: GRAPHQL_DIRECTIVE_LIST@161..172 + 0: GRAPHQL_DIRECTIVE@161..172 + 0: AT@161..162 "@" [] [] + 1: GRAPHQL_NAME@162..172 + 0: GRAPHQL_NAME@162..172 "deprecated" [] [] + 2: (empty) + 5: (empty) + 4: GRAPHQL_OBJECT_TYPE_EXTENSION@172..221 + 0: EXTEND_KW@172..181 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: TYPE_KW@181..186 "type" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@186..191 + 0: GRAPHQL_NAME@186..191 "User" [] [Whitespace(" ")] + 3: (empty) + 4: GRAPHQL_DIRECTIVE_LIST@191..203 + 0: GRAPHQL_DIRECTIVE@191..203 + 0: AT@191..192 "@" [] [] + 1: GRAPHQL_NAME@192..203 + 0: GRAPHQL_NAME@192..203 "deprecated" [] [Whitespace(" ")] + 2: (empty) + 5: GRAPHQL_FIELDS_DEFINITION@203..221 + 0: L_CURLY@203..204 "{" [] [] + 1: GRAPHQL_FIELD_DEFINITION_LIST@204..219 + 0: GRAPHQL_FIELD_DEFINITION@204..219 + 0: (empty) + 1: GRAPHQL_NAME@204..211 + 0: GRAPHQL_NAME@204..211 "name" [Newline("\n"), Whitespace(" ")] [] + 2: (empty) + 3: COLON@211..213 ":" [] [Whitespace(" ")] + 4: GRAPHQL_NAMED_TYPE@213..219 + 0: GRAPHQL_NAME@213..219 + 0: GRAPHQL_NAME@213..219 "String" [] [] + 5: GRAPHQL_DIRECTIVE_LIST@219..219 + 2: R_CURLY@219..221 "}" [Newline("\n")] [] + 5: GRAPHQL_OBJECT_TYPE_EXTENSION@221..291 + 0: EXTEND_KW@221..230 "extend" [Newline("\n"), Newline("\n")] [Whitespace(" ")] + 1: TYPE_KW@230..235 "type" [] [Whitespace(" ")] + 2: GRAPHQL_NAME@235..240 + 0: GRAPHQL_NAME@235..240 "User" [] [Whitespace(" ")] + 3: GRAPHQL_IMPLEMENTS_INTERFACES@240..261 + 0: IMPLEMENTS_KW@240..251 "implements" [] [Whitespace(" ")] + 1: (empty) + 2: GRAPHQL_IMPLEMENTS_INTERFACE_LIST@251..261 + 0: GRAPHQL_NAMED_TYPE@251..261 + 0: GRAPHQL_NAME@251..261 + 0: GRAPHQL_NAME@251..261 "Character" [] [Whitespace(" ")] + 4: GRAPHQL_DIRECTIVE_LIST@261..273 + 0: GRAPHQL_DIRECTIVE@261..273 + 0: AT@261..262 "@" [] [] + 1: GRAPHQL_NAME@262..273 + 0: GRAPHQL_NAME@262..273 "deprecated" [] [Whitespace(" ")] + 2: (empty) + 5: GRAPHQL_FIELDS_DEFINITION@273..291 + 0: L_CURLY@273..274 "{" [] [] + 1: GRAPHQL_FIELD_DEFINITION_LIST@274..289 + 0: GRAPHQL_FIELD_DEFINITION@274..289 + 0: (empty) + 1: GRAPHQL_NAME@274..281 + 0: GRAPHQL_NAME@274..281 "name" [Newline("\n"), Whitespace(" ")] [] + 2: (empty) + 3: COLON@281..283 ":" [] [Whitespace(" ")] + 4: GRAPHQL_NAMED_TYPE@283..289 + 0: GRAPHQL_NAME@283..289 + 0: GRAPHQL_NAME@283..289 "String" [] [] + 5: GRAPHQL_DIRECTIVE_LIST@289..289 + 2: R_CURLY@289..291 "}" [Newline("\n")] [] + 2: EOF@291..292 "" [Newline("\n")] [] + +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar.graphql new file mode 100644 index 000000000000..25d90085e041 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar.graphql @@ -0,0 +1,10 @@ +scalar UUID + @specifiedBy + (url: "https://tools.ietf.org/html/rfc4122") +"abc" + scalar +URL +@specifiedBy(url: "https://tools.ietf.org/html/rfc3986") + +scalar scalar @scalar(scalar: +scalar) diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar.graphql.snap new file mode 100644 index 000000000000..ddcef6401373 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar.graphql.snap @@ -0,0 +1,42 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/scalar.graphql +--- +# Input + +```graphql +scalar UUID + @specifiedBy + (url: "https://tools.ietf.org/html/rfc4122") +"abc" + scalar +URL +@specifiedBy(url: "https://tools.ietf.org/html/rfc3986") + +scalar scalar @scalar(scalar: +scalar) + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +scalar UUID @specifiedBy(url: "https://tools.ietf.org/html/rfc4122") +"abc" +scalar URL @specifiedBy(url: "https://tools.ietf.org/html/rfc3986") + +scalar scalar @scalar(scalar: scalar) +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar_extension.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar_extension.graphql new file mode 100644 index 000000000000..07a792ed522c --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar_extension.graphql @@ -0,0 +1,7 @@ +extend + +scalar + +Date + +@scalar_extension diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar_extension.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar_extension.graphql.snap new file mode 100644 index 000000000000..ed7af871bdbc --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/scalar_extension.graphql.snap @@ -0,0 +1,35 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/scalar_extension.graphql +--- +# Input + +```graphql +extend + +scalar + +Date + +@scalar_extension + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +extend scalar Date @scalar_extension +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema.graphql new file mode 100644 index 000000000000..9ceff4546cc8 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema.graphql @@ -0,0 +1,32 @@ +schema { + query: MyQueryRootType + mutation: MyMutationRootType + + + + + subscription: MySubscriptionRootType +} + +"decs" schema +{ + query: MyQueryRootType + mutation: MyMutationRootType +} + +"""sth""" + +schema { + + + query: MyQueryRootType +} + +schema { + + query: query + + + mutation: mutation + subscription: subscription +} diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema.graphql.snap new file mode 100644 index 000000000000..d2018fee2fde --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema.graphql.snap @@ -0,0 +1,83 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/schema.graphql +--- +# Input + +```graphql +schema { + query: MyQueryRootType + mutation: MyMutationRootType + + + + + subscription: MySubscriptionRootType +} + +"decs" schema +{ + query: MyQueryRootType + mutation: MyMutationRootType +} + +"""sth""" + +schema { + + + query: MyQueryRootType +} + +schema { + + query: query + + + mutation: mutation + subscription: subscription +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +schema { + query: MyQueryRootType + mutation: MyMutationRootType + + subscription: MySubscriptionRootType +} + +"decs" +schema { + query: MyQueryRootType + mutation: MyMutationRootType +} + +"""sth""" +schema { + query: MyQueryRootType +} + +schema { + query: query + + mutation: mutation + subscription: subscription +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema_extension.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema_extension.graphql new file mode 100644 index 000000000000..f1954cec7e48 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema_extension.graphql @@ -0,0 +1,27 @@ +extend schema { + query: MyQueryRootType + + + mutation: MyMutationRootType + + subscription: MySubscriptionRootType +} + +extend +schema + +@decs { + query: + MyQueryRootType + + + mutation: MyMutationRootType +} + +extend +schema @decs{ + query:MyQueryRootType + mutation: + + MyMutationRootType +} diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema_extension.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema_extension.graphql.snap new file mode 100644 index 000000000000..2d92fedcfbdb --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/schema_extension.graphql.snap @@ -0,0 +1,72 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/schema_extension.graphql +--- +# Input + +```graphql +extend schema { + query: MyQueryRootType + + + mutation: MyMutationRootType + + subscription: MySubscriptionRootType +} + +extend +schema + +@decs { + query: + MyQueryRootType + + + mutation: MyMutationRootType +} + +extend +schema @decs{ + query:MyQueryRootType + mutation: + + MyMutationRootType +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +extend schema { + query: MyQueryRootType + + mutation: MyMutationRootType + + subscription: MySubscriptionRootType +} + +extend schema @decs { + query: MyQueryRootType + + mutation: MyMutationRootType +} + +extend schema @decs { + query: MyQueryRootType + mutation: MyMutationRootType +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union.graphql new file mode 100644 index 000000000000..bc99a6763c88 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union.graphql @@ -0,0 +1,20 @@ +union +SearchResult = + Photo | Person + +union +SearchResult = + | Photo + | Person + | union + +union +union = union +| union + +union +SearchResult + @deprecated + +union SearchResult +@deprecated = Photo | Person diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union.graphql.snap new file mode 100644 index 000000000000..3cd7c4aea7a3 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union.graphql.snap @@ -0,0 +1,56 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/union.graphql +--- +# Input + +```graphql +union +SearchResult = + Photo | Person + +union +SearchResult = + | Photo + | Person + | union + +union +union = union +| union + +union +SearchResult + @deprecated + +union SearchResult +@deprecated = Photo | Person + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +union SearchResult = Photo | Person + +union SearchResult = Photo | Person | union + +union union = union | union + +union SearchResult @deprecated + +union SearchResult @deprecated = Photo | Person +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union_extension.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union_extension.graphql new file mode 100644 index 000000000000..f5a1e9d0b412 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union_extension.graphql @@ -0,0 +1,3 @@ +extend union SearchResult = Photo | Person + +extend union SearchResult @deprecated diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union_extension.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union_extension.graphql.snap new file mode 100644 index 000000000000..b13b8550cd4b --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/union_extension.graphql.snap @@ -0,0 +1,33 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/union_extension.graphql +--- +# Input + +```graphql +extend union SearchResult = Photo | Person + +extend union SearchResult @deprecated + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +extend union SearchResult = Photo | Person + +extend union SearchResult @deprecated +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/directive.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/directive.graphql index 6fbdff6ac040..7baea0ef0892 100644 --- a/crates/biome_graphql_formatter/tests/specs/graphql/directive.graphql +++ b/crates/biome_graphql_formatter/tests/specs/graphql/directive.graphql @@ -1,3 +1,58 @@ { - hero @deprecated + + + hero + + + @deprecated + + +} + +{ + hero + + + @deprecated(reason: + + "Deprecated" + + ) + + +} + +{ + + hero + + @input + + (type: + + String) + + +} + +{ + hero + + + @deprecated( + + reason: + + "Deprecated" + + ) + @addExternalFields + + + (source: + + + "profiles" + + ) } diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/directive.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/directive.graphql.snap index dfb4a417c1d7..55c27d15f385 100644 --- a/crates/biome_graphql_formatter/tests/specs/graphql/directive.graphql.snap +++ b/crates/biome_graphql_formatter/tests/specs/graphql/directive.graphql.snap @@ -6,7 +6,62 @@ info: graphql/directive.graphql ```graphql { - hero @deprecated + + + hero + + + @deprecated + + +} + +{ + hero + + + @deprecated(reason: + + "Deprecated" + + ) + + +} + +{ + + hero + + @input + + (type: + + String) + + +} + +{ + hero + + + @deprecated( + + reason: + + "Deprecated" + + ) + @addExternalFields + + + (source: + + + "profiles" + + ) } ``` @@ -28,12 +83,18 @@ Quote style: Double Quotes ```graphql { - hero @deprecated + hero @deprecated } -``` - +{ + hero @deprecated(reason: "Deprecated") +} -## Unimplemented nodes/tokens +{ + hero @input(type: String) +} -"{\n hero @deprecated\n}" => 0..22 +{ + hero @deprecated(reason: "Deprecated") @addExternalFields(source: "profiles") +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/operation.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/operation.graphql new file mode 100644 index 000000000000..70849f150123 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/operation.graphql @@ -0,0 +1,159 @@ +query { + + + likeStory + + +} + +# shorthand +{ + + + likeStory + + + +} + +mutation + +{ + + + likeStory + + +} + +subscription + +{ + + + storyLiked + + +} + +# with name +query likeStory + + { + + + likeStory +} + +query query + + { + + + likeStory + + + } + +# with variables +query ( $storyId: ID!) { + + + likeStory + + ( + + storyId: $storyId + + ) + + + +} + +query + +( $storyId: + +ID = + +"1" + + + ) { + + + likeStory + + ( + + storyId: + + + $storyId + + ) + + + +} + +# with directives +query ( + + $storyId: + + ID! + +) + +@skip + +(if: +true) + + { + + + likeStory( + + storyId: + + $storyId + + ) + + + +} + +query + +enum( + $true: false +) { + + null + + mutation + + enum + + + Direction + + @deprecated { + + NORTH + + + + WEST + + + + + } + + +} diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/operation.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/operation.graphql.snap new file mode 100644 index 000000000000..5b8196cc5a7d --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/operation.graphql.snap @@ -0,0 +1,239 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/operation.graphql +--- +# Input + +```graphql +query { + + + likeStory + + +} + +# shorthand +{ + + + likeStory + + + +} + +mutation + +{ + + + likeStory + + +} + +subscription + +{ + + + storyLiked + + +} + +# with name +query likeStory + + { + + + likeStory +} + +query query + + { + + + likeStory + + + } + +# with variables +query ( $storyId: ID!) { + + + likeStory + + ( + + storyId: $storyId + + ) + + + +} + +query + +( $storyId: + +ID = + +"1" + + + ) { + + + likeStory + + ( + + storyId: + + + $storyId + + ) + + + +} + +# with directives +query ( + + $storyId: + + ID! + +) + +@skip + +(if: +true) + + { + + + likeStory( + + storyId: + + $storyId + + ) + + + +} + +query + +enum( + $true: false +) { + + null + + mutation + + enum + + + Direction + + @deprecated { + + NORTH + + + + WEST + + + + + } + + +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +query { + likeStory +} + +# shorthand +{ + likeStory +} + +mutation { + likeStory +} + +subscription { + storyLiked +} + +# with name +query likeStory { + likeStory +} + +query query { + likeStory +} + +# with variables +query ($storyId: ID!) { + likeStory(storyId: $storyId) +} + +query ($storyId: ID = "1") { + likeStory(storyId: $storyId) +} + +# with directives +query ($storyId: ID!) @skip(if: true) { + likeStory(storyId: $storyId) +} + +query enum($true: false) { + null + + mutation + + enum + + Direction @deprecated { + NORTH + + WEST + } +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/selection_set.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/selection_set.graphql new file mode 100644 index 000000000000..621c15358c43 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/selection_set.graphql @@ -0,0 +1,249 @@ +{ + + hero + + +} + +# with nested fields +{ + + + hero { + + + + name, age + + + } + + +} + +# with argument +{ + + hero( + + name: "Tony Stark" + + ) +} + +{ + hero( + + name: "Tony Stark" + + ) { + country, + + + + + name, + age + + + } + + +} + +{ + hero ( + + + name: "Tony Stark", + + + + + age: 53, + + + height: 6.1 + + + alive: false, + + + + location: null + + + birthplace: {city: "New York", state: "NY", country: "USA"} + + + friends: ["Pepper", "Rhodey"] + + + ) { + country, + + + name, + + + age, + + + height(unit: FOOT), + wife( name: "Pepper"){ + + + name + } + + + } +} + +{ + hero + + (name: + $name + ) +} + +# with aliases +{ + ironMan: + + hero( + name: + "Tony Stark" + ) +} + +{ + ironMan: + + hero(name: "Tony Stark") { + country, + + + name, + age, + + + firstWife: + + wife(name: "Pepper") + + { + name + } + + + } + +} + +# with directives +{ + + + hero + + @deprecated + + +} + +{ + ironMan: + + hero(name: "Tony Stark" + + ) @deprecated + + { + country @deprecated, + + + name, + + + age + } + + +} + +# Fragment spread +{ + ...heroFragment +} + +{ + + + ...heroFragment + + @deprecated + + +} + +{ + ironMan: + + + hero(name: "Tony Stark") + + @deprecated { + + + ...heroAttributes + + + } + + +} + +# Inline Fragment spread +{ + + + ... { + + + hero + } + + +} + +{ + + + ... @deprecated { + + + hero + } + + +} + +{ + ironMan: + + + hero(name: + + "Tony Stark") @deprecated { + ... on Hero @deprecated + + { + name, + + + age + } + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/selection_set.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/selection_set.graphql.snap new file mode 100644 index 000000000000..19c083164aef --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/selection_set.graphql.snap @@ -0,0 +1,405 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/selection_set.graphql +--- +# Input + +```graphql +{ + + hero + + +} + +# with nested fields +{ + + + hero { + + + + name, age + + + } + + +} + +# with argument +{ + + hero( + + name: "Tony Stark" + + ) +} + +{ + hero( + + name: "Tony Stark" + + ) { + country, + + + + + name, + age + + + } + + +} + +{ + hero ( + + + name: "Tony Stark", + + + + + age: 53, + + + height: 6.1 + + + alive: false, + + + + location: null + + + birthplace: {city: "New York", state: "NY", country: "USA"} + + + friends: ["Pepper", "Rhodey"] + + + ) { + country, + + + name, + + + age, + + + height(unit: FOOT), + wife( name: "Pepper"){ + + + name + } + + + } +} + +{ + hero + + (name: + $name + ) +} + +# with aliases +{ + ironMan: + + hero( + name: + "Tony Stark" + ) +} + +{ + ironMan: + + hero(name: "Tony Stark") { + country, + + + name, + age, + + + firstWife: + + wife(name: "Pepper") + + { + name + } + + + } + +} + +# with directives +{ + + + hero + + @deprecated + + +} + +{ + ironMan: + + hero(name: "Tony Stark" + + ) @deprecated + + { + country @deprecated, + + + name, + + + age + } + + +} + +# Fragment spread +{ + ...heroFragment +} + +{ + + + ...heroFragment + + @deprecated + + +} + +{ + ironMan: + + + hero(name: "Tony Stark") + + @deprecated { + + + ...heroAttributes + + + } + + +} + +# Inline Fragment spread +{ + + + ... { + + + hero + } + + +} + +{ + + + ... @deprecated { + + + hero + } + + +} + +{ + ironMan: + + + hero(name: + + "Tony Stark") @deprecated { + ... on Hero @deprecated + + { + name, + + + age + } + } +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +{ + hero +} + +# with nested fields +{ + hero { + name + age + } +} + +# with argument +{ + hero(name: "Tony Stark") +} + +{ + hero(name: "Tony Stark") { + country + + name + age + } +} + +{ + hero( + name: "Tony Stark" + + age: 53 + + height: 6.1 + + alive: false + + location: null + + birthplace: { city: "New York", state: "NY", country: "USA" } + + friends: ["Pepper", "Rhodey"] + ) { + country + + name + + age + + height(unit: FOOT) + wife(name: "Pepper") { + name + } + } +} + +{ + hero(name: $name) +} + +# with aliases +{ + ironMan: hero(name: "Tony Stark") +} + +{ + ironMan: hero(name: "Tony Stark") { + country + + name + age + + firstWife: wife(name: "Pepper") { + name + } + } +} + +# with directives +{ + hero @deprecated +} + +{ + ironMan: hero(name: "Tony Stark") @deprecated { + country @deprecated + + name + + age + } +} + +# Fragment spread +{ + ...heroFragment +} + +{ + ...heroFragment @deprecated +} + +{ + ironMan: hero(name: "Tony Stark") @deprecated { + ...heroAttributes + } +} + +# Inline Fragment spread +{ + ... { + hero + } +} + +{ + ... @deprecated { + hero + } +} + +{ + ironMan: hero(name: "Tony Stark") @deprecated { + ... on Hero @deprecated { + name + + age + } + } +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/simple.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/simple.graphql new file mode 100644 index 000000000000..17c1f96bc4e7 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/simple.graphql @@ -0,0 +1,59 @@ +{ + hero + @deprecated(reason: "Deprecated", reason: "Deprecated", + + + reason: "Deprecated") + @addExternalFields(source: "profiles") +} +{ + field_value( + int_value: 1, + float_value: 1.1, + + + string_value: "string", + + + boolean_value: true, + + + null_value: null, + enum_value: ENUM_VALUE, + + + + enum_value: enum, + enum_value: on, + + + list_value: [12222222222221222222222222122222222222212222222222221222222222222, + + + + 2, + + + + 33333], + object_value: {key: "value" + + + + + key: "value" key: "value" key: "value" key: "value"} + ) +} + + +query ($storyId: ID!, + + + + $like: Boolean, + + + + $comments: [String!], $tags: [String!]!, $posts: [PostInput]!, $input: [input!]!) { + likeStory(storyId: $storyId) +} diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/simple.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/simple.graphql.snap new file mode 100644 index 000000000000..98c68d27ea1c --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/simple.graphql.snap @@ -0,0 +1,136 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/simple.graphql +--- +# Input + +```graphql +{ + hero + @deprecated(reason: "Deprecated", reason: "Deprecated", + + + reason: "Deprecated") + @addExternalFields(source: "profiles") +} +{ + field_value( + int_value: 1, + float_value: 1.1, + + + string_value: "string", + + + boolean_value: true, + + + null_value: null, + enum_value: ENUM_VALUE, + + + + enum_value: enum, + enum_value: on, + + + list_value: [12222222222221222222222222122222222222212222222222221222222222222, + + + + 2, + + + + 33333], + object_value: {key: "value" + + + + + key: "value" key: "value" key: "value" key: "value"} + ) +} + + +query ($storyId: ID!, + + + + $like: Boolean, + + + + $comments: [String!], $tags: [String!]!, $posts: [PostInput]!, $input: [input!]!) { + likeStory(storyId: $storyId) +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +{ + hero + @deprecated( + reason: "Deprecated" + reason: "Deprecated" + + reason: "Deprecated" + ) + @addExternalFields(source: "profiles") +} +{ + field_value( + int_value: 1 + float_value: 1.1 + + string_value: "string" + + boolean_value: true + + null_value: null + enum_value: ENUM_VALUE + + enum_value: enum + enum_value: on + + list_value: [ + 12222222222221222222222222122222222222212222222222221222222222222 + 2 + 33333 + ] + object_value: { + key: "value" + key: "value" + key: "value" + key: "value" + key: "value" + } + ) +} + +query ( + $storyId: ID! + $like: Boolean + $comments: [String!] + $tags: [String!]! + $posts: [PostInput]! + $input: [input!]! +) { + likeStory(storyId: $storyId) +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/type.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/type.graphql new file mode 100644 index 000000000000..0a4c51605877 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/type.graphql @@ -0,0 +1,12 @@ +query ($storyId: ID!, $like: Boolean, + + $comments: [String!], $tags: [String!]!, + + $posts: [PostInput]!, $input: [input!]! + +) { + + + likeStory(storyId: $storyId) +} + diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/type.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/type.graphql.snap new file mode 100644 index 000000000000..2be3c0205518 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/type.graphql.snap @@ -0,0 +1,49 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/type.graphql +--- +# Input + +```graphql +query ($storyId: ID!, $like: Boolean, + + $comments: [String!], $tags: [String!]!, + + $posts: [PostInput]!, $input: [input!]! + +) { + + + likeStory(storyId: $storyId) +} + + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +query ( + $storyId: ID! + $like: Boolean + $comments: [String!] + $tags: [String!]! + $posts: [PostInput]! + $input: [input!]! +) { + likeStory(storyId: $storyId) +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/value.graphql b/crates/biome_graphql_formatter/tests/specs/graphql/value.graphql new file mode 100644 index 000000000000..c9e845d30296 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/value.graphql @@ -0,0 +1,14 @@ +{ + field_value( + int_value: 1, + float_value: 1.1, + string_value: "string", + boolean_value: true, + null_value: null, + enum_value: ENUM_VALUE, + enum_value: enum, + enum_value: on, + list_value: [1, 2, 3], + object_value: {key: "value"} + ) +} diff --git a/crates/biome_graphql_formatter/tests/specs/graphql/value.graphql.snap b/crates/biome_graphql_formatter/tests/specs/graphql/value.graphql.snap new file mode 100644 index 000000000000..8601715f58c8 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/value.graphql.snap @@ -0,0 +1,55 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/value.graphql +--- +# Input + +```graphql +{ + field_value( + int_value: 1, + float_value: 1.1, + string_value: "string", + boolean_value: true, + null_value: null, + enum_value: ENUM_VALUE, + enum_value: enum, + enum_value: on, + list_value: [1, 2, 3], + object_value: {key: "value"} + ) +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +{ + field_value( + int_value: 1 + float_value: 1.1 + string_value: "string" + boolean_value: true + null_value: null + enum_value: ENUM_VALUE + enum_value: enum + enum_value: on + list_value: [1, 2, 3] + object_value: { key: "value" } + ) +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/arguments/hello.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/arguments/hello.graphql new file mode 100644 index 000000000000..8c6b65099914 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/arguments/hello.graphql @@ -0,0 +1,4 @@ +{ + short(var: $var, int: 5, float: 5.6, bool: true, string: "hello world!") + long(var: $thisIsAReallyLongVariableNameRight, int: 52342342342, float: 5.6, bool: true, string: "hello world this is a very long string!") +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/arguments/hello.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/arguments/hello.graphql.prettier-snap new file mode 100644 index 000000000000..36b9e9c10602 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/arguments/hello.graphql.prettier-snap @@ -0,0 +1,10 @@ +{ + short(var: $var, int: 5, float: 5.6, bool: true, string: "hello world!") + long( + var: $thisIsAReallyLongVariableNameRight + int: 52342342342 + float: 5.6 + bool: true + string: "hello world this is a very long string!" + ) +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/bracket-spacing/bracket_spacing.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/bracket-spacing/bracket_spacing.graphql new file mode 100644 index 000000000000..0e047c3f5466 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/bracket-spacing/bracket_spacing.graphql @@ -0,0 +1,6 @@ +fragment Visit on HighlightedVisit + @argumentDefinitions( + count: {type: "Int", defaultValue: 20} + ) { + name +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/bracket-spacing/bracket_spacing.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/bracket-spacing/bracket_spacing.graphql.prettier-snap new file mode 100644 index 000000000000..12fd671be9eb --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/bracket-spacing/bracket_spacing.graphql.prettier-snap @@ -0,0 +1,4 @@ +fragment Visit on HighlightedVisit +@argumentDefinitions(count: { type: "Int", defaultValue: 20 }) { + name +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/argument_comment.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/argument_comment.graphql new file mode 100644 index 000000000000..b23f6c998ad3 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/argument_comment.graphql @@ -0,0 +1,7 @@ + +query ( + $string: String, # Some variable comment + $bool: Boolean # Some comment + ) { + someField + } diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/argument_comment.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/argument_comment.graphql.prettier-snap new file mode 100644 index 000000000000..5299d8079d45 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/argument_comment.graphql.prettier-snap @@ -0,0 +1,6 @@ +query ( + $string: String # Some variable comment + $bool: Boolean # Some comment +) { + someField +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/fields.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/fields.graphql new file mode 100644 index 000000000000..db15974d038e --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/fields.graphql @@ -0,0 +1,5 @@ +query { + someField # Trailing comment +} + + diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/fields.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/fields.graphql.prettier-snap new file mode 100644 index 000000000000..02ac5669741d --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/fields.graphql.prettier-snap @@ -0,0 +1,3 @@ +query { + someField # Trailing comment +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql new file mode 100644 index 000000000000..1d39a8193ab0 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql @@ -0,0 +1,7 @@ +#type Type1 +#implements +#A & B & +# comment 1 +# C & D & +# comment 2 +# E {a: a} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql.prettier-snap new file mode 100644 index 000000000000..7a35c46f8750 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql.prettier-snap @@ -0,0 +1,7 @@ +type Type1 implements A & B & +# comment 1 +C & D & +# comment 2 +E { + a: a +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql.snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql.snap new file mode 100644 index 000000000000..a5e0408a24c9 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/interfaces.graphql.snap @@ -0,0 +1,49 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/comments/interfaces.graphql +--- +# Input + +```graphql +#type Type1 +#implements +#A & B & +# comment 1 +# C & D & +# comment 2 +# E {a: a} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Biome +@@ -1,7 +1,7 @@ +-type Type1 implements A & B & ++#type Type1 ++#implements ++#A & B & + # comment 1 +-C & D & ++# C & D & + # comment 2 +-E { +- a: a +-} ++# E {a: a} +``` + +# Output + +```graphql +#type Type1 +#implements +#A & B & +# comment 1 +# C & D & +# comment 2 +# E {a: a} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/tokens.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/tokens.graphql new file mode 100644 index 000000000000..accf80178be5 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/tokens.graphql @@ -0,0 +1,7 @@ +# import "./claimsFragment.gql" + +query claimsByBookingReferenceAndLastName($bookingReference: String!, $lastName: String!) { + claimsByBookingReferenceAndLastName(bookingReference: $bookingReference, lastName: $lastName) { + ... claim + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/tokens.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/tokens.graphql.prettier-snap new file mode 100644 index 000000000000..395f6ea799a2 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/comments/tokens.graphql.prettier-snap @@ -0,0 +1,13 @@ +# import "./claimsFragment.gql" + +query claimsByBookingReferenceAndLastName( + $bookingReference: String! + $lastName: String! +) { + claimsByBookingReferenceAndLastName( + bookingReference: $bookingReference + lastName: $lastName + ) { + ...claim + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql new file mode 100644 index 000000000000..8c4fd565baa8 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql @@ -0,0 +1,32 @@ +query MyFirstQuery { + hello +} + +mutation +MyFirstMutation { + world +} + +subscription, ThisIsASub, { + excellent +} + +, query, ThisIsASub, { + excellent +} + +query { + noName +} + +{ + noOperationType +} + +query ($unnamed: String) { + id +} + +query Named($var: String) { + id +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql.prettier-snap new file mode 100644 index 000000000000..bf5c6cf5f6f7 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql.prettier-snap @@ -0,0 +1,31 @@ +query MyFirstQuery { + hello +} + +mutation MyFirstMutation { + world +} + +subscription ThisIsASub { + excellent +} + +query ThisIsASub { + excellent +} + +query { + noName +} + +{ + noOperationType +} + +query ($unnamed: String) { + id +} + +query Named($var: String) { + id +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql.snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql.snap new file mode 100644 index 000000000000..77d98597a481 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/definitions/fields.graphql.snap @@ -0,0 +1,94 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/fields.graphql +--- +# Input + +```graphql +query MyFirstQuery { + hello +} + +mutation +MyFirstMutation { + world +} + +subscription, ThisIsASub, { + excellent +} + +, query, ThisIsASub, { + excellent +} + +query { + noName +} + +{ + noOperationType +} + +query ($unnamed: String) { + id +} + +query Named($var: String) { + id +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Biome +@@ -10,7 +10,7 @@ + excellent + } + +-query ThisIsASub { ++, query ThisIsASub { + excellent + } + +``` + +# Output + +```graphql +query MyFirstQuery { + hello +} + +mutation MyFirstMutation { + world +} + +subscription ThisIsASub { + excellent +} + +, query ThisIsASub { + excellent +} + +query { + noName +} + +{ + noOperationType +} + +query ($unnamed: String) { + id +} + +query Named($var: String) { + id +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/deprecation/directives.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/deprecation/directives.graphql new file mode 100644 index 000000000000..1e24cbbfae28 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/deprecation/directives.graphql @@ -0,0 +1,71 @@ +# https://github.com/graphql/graphql-js/pull/2733/files + +type Query { + someField( + nonDeprecated: String + deprecated: String @deprecated(reason: "Removed in 1.0") + deprecatedWithEmptyReason: String @deprecated(reason: "") + ): String +} + + +type Query { + someField( + nonDeprecated: String + deprecated: String @deprecated(reason: "Removed in 1.0") + ): String +} + +input SomeInputObject { + nonDeprecated: String + deprecated: String @deprecated(reason: "Removed in 1.0") + deprecatedWithEmptyReason: String @deprecated(reason: "") +} +type Query { + someField(someArg: SomeInputObject): String +} + +input SomeInputObject { + nonDeprecated: String + deprecated: String @deprecated(reason: "Removed in 1.0") +} +type Query { + someField(someArg: SomeInputObject): String +} + +type Query { + field(arg: SomeInputObject): String +} +input SomeInputObject { + badField: String! @deprecated + optionalField: String @deprecated + anotherOptionalField: String! = "" @deprecated +} + +directive @BadDirective( + badArg: String! @deprecated + optionalArg: String @deprecated + anotherOptionalArg: String! = "" @deprecated +) on FIELD +type Query { + test( + badArg: String! @deprecated + optionalArg: String @deprecated + anotherOptionalArg: String! = "" @deprecated + ): String +} + +input MyInput { + oldInput: String @deprecated + otherInput: String @deprecated(reason: "Use newInput") + newInput: String +} + +type Query { + field1: String @deprecated + field2: Int @deprecated(reason: "Because I said so") + enum: MyEnum + field3(oldArg: String @deprecated, arg: String): String + field4(oldArg: String @deprecated(reason: "Why not?"), arg: String): String + field5(arg: MyInput): String +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/deprecation/directives.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/deprecation/directives.graphql.prettier-snap new file mode 100644 index 000000000000..3a98882c06bf --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/deprecation/directives.graphql.prettier-snap @@ -0,0 +1,70 @@ +# https://github.com/graphql/graphql-js/pull/2733/files + +type Query { + someField( + nonDeprecated: String + deprecated: String @deprecated(reason: "Removed in 1.0") + deprecatedWithEmptyReason: String @deprecated(reason: "") + ): String +} + +type Query { + someField( + nonDeprecated: String + deprecated: String @deprecated(reason: "Removed in 1.0") + ): String +} + +input SomeInputObject { + nonDeprecated: String + deprecated: String @deprecated(reason: "Removed in 1.0") + deprecatedWithEmptyReason: String @deprecated(reason: "") +} +type Query { + someField(someArg: SomeInputObject): String +} + +input SomeInputObject { + nonDeprecated: String + deprecated: String @deprecated(reason: "Removed in 1.0") +} +type Query { + someField(someArg: SomeInputObject): String +} + +type Query { + field(arg: SomeInputObject): String +} +input SomeInputObject { + badField: String! @deprecated + optionalField: String @deprecated + anotherOptionalField: String! = "" @deprecated +} + +directive @BadDirective( + badArg: String! @deprecated + optionalArg: String @deprecated + anotherOptionalArg: String! = "" @deprecated +) on FIELD +type Query { + test( + badArg: String! @deprecated + optionalArg: String @deprecated + anotherOptionalArg: String! = "" @deprecated + ): String +} + +input MyInput { + oldInput: String @deprecated + otherInput: String @deprecated(reason: "Use newInput") + newInput: String +} + +type Query { + field1: String @deprecated + field2: Int @deprecated(reason: "Because I said so") + enum: MyEnum + field3(oldArg: String @deprecated, arg: String): String + field4(oldArg: String @deprecated(reason: "Why not?"), arg: String): String + field5(arg: MyInput): String +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directive-decl/directive_decl.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directive-decl/directive_decl.graphql new file mode 100644 index 000000000000..318e0552bc32 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directive-decl/directive_decl.graphql @@ -0,0 +1,18 @@ +directive @a on QUERY +directive @a(as: String) on QUERY +directive @a(as: String = 1) on QUERY +directive @a(as: String, b: Int!) on QUERY +directive @a(as: String! = 1 @deprecated) on QUERY +directive @a(as: String! = 1 @deprecated) on QUERY | MUTATION +directive @a(as: String! = 1 @deprecated) repeatable on QUERY | MUTATION + +directive @a on QUERY +directive @a repeatable on QUERY + + +directive @a(as: String) on QUERY + + + + +directive @a(as: String = 1) on QUERY diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directive-decl/directive_decl.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directive-decl/directive_decl.graphql.prettier-snap new file mode 100644 index 000000000000..496a5c0688e9 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directive-decl/directive_decl.graphql.prettier-snap @@ -0,0 +1,14 @@ +directive @a on QUERY +directive @a(as: String) on QUERY +directive @a(as: String = 1) on QUERY +directive @a(as: String, b: Int!) on QUERY +directive @a(as: String! = 1 @deprecated) on QUERY +directive @a(as: String! = 1 @deprecated) on QUERY | MUTATION +directive @a(as: String! = 1 @deprecated) repeatable on QUERY | MUTATION + +directive @a on QUERY +directive @a repeatable on QUERY + +directive @a(as: String) on QUERY + +directive @a(as: String = 1) on QUERY diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directives/directives.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directives/directives.graphql new file mode 100644 index 000000000000..6a28c0618671 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directives/directives.graphql @@ -0,0 +1,20 @@ +query MyQuery @directive( + arg: 5 +) { + field + @skip(if: true) @nope + otherField + ...fragmentSpread, @include(if: ["this isn't even a boolean", "wow, that's really odd",,,,,]) +} + +fragment YouCanHaveDirectivesHereToo on SomeType @yesReally(what: "yes") { + fields + ... on AType @what(sup: "yo") @otherDirective { goodbye} + ... @notEvenATypeHere(args: [1, 2, 3]) { + hello + } + + thisFieldHasALotOfDirectives @thisIsthefirst @thisIsTheSecond @thisIsTheThird @thisIstheFourthWillBeTooLongForSure (and: "it has arguments as well") +} + +query QueryWVars($x: String) @directive { hey } diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directives/directives.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directives/directives.graphql.prettier-snap new file mode 100644 index 000000000000..3b2bcf665a12 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/directives/directives.graphql.prettier-snap @@ -0,0 +1,26 @@ +query MyQuery @directive(arg: 5) { + field @skip(if: true) @nope + otherField + ...fragmentSpread + @include(if: ["this isn't even a boolean", "wow, that's really odd"]) +} + +fragment YouCanHaveDirectivesHereToo on SomeType @yesReally(what: "yes") { + fields + ... on AType @what(sup: "yo") @otherDirective { + goodbye + } + ... @notEvenATypeHere(args: [1, 2, 3]) { + hello + } + + thisFieldHasALotOfDirectives + @thisIsthefirst + @thisIsTheSecond + @thisIsTheThird + @thisIstheFourthWillBeTooLongForSure(and: "it has arguments as well") +} + +query QueryWVars($x: String) @directive { + hey +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/enum/enum.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/enum/enum.graphql new file mode 100644 index 000000000000..16189a909704 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/enum/enum.graphql @@ -0,0 +1,5 @@ +enum State { + PENDING + VISIBLE + ARCHIVED +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/enum/enum.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/enum/enum.graphql.prettier-snap new file mode 100644 index 000000000000..16189a909704 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/enum/enum.graphql.prettier-snap @@ -0,0 +1,5 @@ +enum State { + PENDING + VISIBLE + ARCHIVED +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fields/fields.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fields/fields.graphql new file mode 100644 index 000000000000..6e9cd37cef49 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fields/fields.graphql @@ -0,0 +1,4 @@ +{ + posts {, title, votes, author {, firstName, posts {, author { firstName } } + }} +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fields/fields.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fields/fields.graphql.prettier-snap new file mode 100644 index 000000000000..67c7c337a4f7 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fields/fields.graphql.prettier-snap @@ -0,0 +1,14 @@ +{ + posts { + title + votes + author { + firstName + posts { + author { + firstName + } + } + } + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql new file mode 100644 index 000000000000..87b49373f1bf --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql @@ -0,0 +1,7 @@ +fragment F($var: Int) on Type { + field +} + +fragment G($first_variable: Int, $second_variable: String = "Very complex default argument value") on Type { + field +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql.prettier-snap new file mode 100644 index 000000000000..99b8981dab49 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql.prettier-snap @@ -0,0 +1,10 @@ +fragment F($var: Int) on Type { + field +} + +fragment G( + $first_variable: Int + $second_variable: String = "Very complex default argument value" +) on Type { + field +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql.snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql.snap new file mode 100644 index 000000000000..10bcddeaead6 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragment-variables/fragment_variables.graphql.snap @@ -0,0 +1,160 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/fragment-variables/fragment_variables.graphql +--- +# Input + +```graphql +fragment F($var: Int) on Type { + field +} + +fragment G($first_variable: Int, $second_variable: String = "Very complex default argument value") on Type { + field +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Biome +@@ -2,9 +2,6 @@ + field + } + +-fragment G( +- $first_variable: Int +- $second_variable: String = "Very complex default argument value" +-) on Type { ++fragment G($first_variable: Int, $second_variable: String = "Very complex default argument value") on Type { + field + } +``` + +# Output + +```graphql +fragment F($var: Int) on Type { + field +} + +fragment G($first_variable: Int, $second_variable: String = "Very complex default argument value") on Type { + field +} +``` + +# Errors +``` +fragment_variables.graphql:1:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `on` but instead found `(` + + > 1 │ fragment F($var: Int) on Type { + │ ^ + 2 │ field + 3 │ } + + i Remove ( + +fragment_variables.graphql:1:21 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a field, a fragment spread, or an inline fragment but instead found ')'. + + > 1 │ fragment F($var: Int) on Type { + │ ^ + 2 │ field + 3 │ } + + i Expected a field, a fragment spread, or an inline fragment here. + + > 1 │ fragment F($var: Int) on Type { + │ ^ + 2 │ field + 3 │ } + +fragment_variables.graphql:5:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected an argument but instead found '$'. + + 3 │ } + 4 │ + > 5 │ fragment G($first_variable: Int, $second_variable: String = "Very complex default argument value") on Type { + │ ^ + 6 │ field + 7 │ } + + i Expected an argument here. + + 3 │ } + 4 │ + > 5 │ fragment G($first_variable: Int, $second_variable: String = "Very complex default argument value") on Type { + │ ^ + 6 │ field + 7 │ } + +fragment_variables.graphql:5:36 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected an argument but instead found '$'. + + 3 │ } + 4 │ + > 5 │ fragment G($first_variable: Int, $second_variable: String = "Very complex default argument value") on Type { + │ ^ + 6 │ field + 7 │ } + + i Expected an argument here. + + 3 │ } + 4 │ + > 5 │ fragment G($first_variable: Int, $second_variable: String = "Very complex default argument value") on Type { + │ ^ + 6 │ field + 7 │ } + +fragment_variables.graphql:5:61 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected an argument but instead found '= "Very complex default argument value"'. + + 3 │ } + 4 │ + > 5 │ fragment G($first_variable: Int, $second_variable: String = "Very complex default argument value") on Type { + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 6 │ field + 7 │ } + + i Expected an argument here. + + 3 │ } + 4 │ + > 5 │ fragment G($first_variable: Int, $second_variable: String = "Very complex default argument value") on Type { + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 6 │ field + 7 │ } + +fragment_variables.graphql:8:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `}` but instead the file ends + + 6 │ field + 7 │ } + > 8 │ + │ + + i the file ends here + + 6 │ field + 7 │ } + > 8 │ + │ + + +``` + +# Lines exceeding max width of 80 characters +``` + 5: fragment G($first_variable: Int, $second_variable: String = "Very complex default argument value") on Type { +``` diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragments/fragments.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragments/fragments.graphql new file mode 100644 index 000000000000..6b1a89305e0e --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragments/fragments.graphql @@ -0,0 +1,15 @@ +{ + field + ... XYZ + ... on TheType { + ...AFragment + ... { + noTypeCondition + } + } +} + +fragment XYZ on ABC { + field + ...AFragment +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragments/fragments.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragments/fragments.graphql.prettier-snap new file mode 100644 index 000000000000..bd189a666adb --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/fragments/fragments.graphql.prettier-snap @@ -0,0 +1,15 @@ +{ + field + ...XYZ + ... on TheType { + ...AFragment + ... { + noTypeCondition + } + } +} + +fragment XYZ on ABC { + field + ...AFragment +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/hello/hello.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/hello/hello.graphql new file mode 100644 index 000000000000..cec7c68e798b --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/hello/hello.graphql @@ -0,0 +1,5 @@ +{ + project(name: "GraphQL") { + tagline + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/hello/hello.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/hello/hello.graphql.prettier-snap new file mode 100644 index 000000000000..cec7c68e798b --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/hello/hello.graphql.prettier-snap @@ -0,0 +1,5 @@ +{ + project(name: "GraphQL") { + tagline + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/interface.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/interface.graphql new file mode 100644 index 000000000000..5ac6a0c05eef --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/interface.graphql @@ -0,0 +1,43 @@ +# https://github.com/graphql/graphql-spec/blob/master/spec/Section%203%20--%20Type%20System.md#interfaces + +interface Actor { + id: ID + name: String +} + +interface Resource implements Node +{ + id: ID! + url: String +} + +interface Resource implements +Node { + id: ID! + url: String +} + +interface Image implements Resource +& Node { + id: ID! + url: String + thumbnail: String +} + +interface Node implements Named & +Node { + id: ID! + name: String +} + +interface Named implements +Node & Named { + id: ID! + name: String +} + +# `InterfaceTypeExtension` +extend interface Bar implements +A& B & C { + two(argument: InputType!): Type +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/interface.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/interface.graphql.prettier-snap new file mode 100644 index 000000000000..10ea4fd0ffd7 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/interface.graphql.prettier-snap @@ -0,0 +1,37 @@ +# https://github.com/graphql/graphql-spec/blob/master/spec/Section%203%20--%20Type%20System.md#interfaces + +interface Actor { + id: ID + name: String +} + +interface Resource implements Node { + id: ID! + url: String +} + +interface Resource implements Node { + id: ID! + url: String +} + +interface Image implements Resource & Node { + id: ID! + url: String + thumbnail: String +} + +interface Node implements Named & Node { + id: ID! + name: String +} + +interface Named implements Node & Named { + id: ID! + name: String +} + +# `InterfaceTypeExtension` +extend interface Bar implements A & B & C { + two(argument: InputType!): Type +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def.graphql new file mode 100644 index 000000000000..e1f769194f87 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def.graphql @@ -0,0 +1,22 @@ +type Artist implements Node & Entity { + # The ID of an object + id: ID! + + # The MBID of the entity. + mbid: MBID! + + # A list of recordings linked to this entity. + recordings(after: String, first: Int): RecordingConnection + + # A list of releases linked to this entity. + releases( + # Filter by one or more release group types. + type: [ReleaseGroupType] + + # Filter by one or more release statuses. + status: [ReleaseStatus] + after: String + first: Int + ): ReleaseConnection + +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def.graphql.prettier-snap new file mode 100644 index 000000000000..9fc66c74d56d --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def.graphql.prettier-snap @@ -0,0 +1,21 @@ +type Artist implements Node & Entity { + # The ID of an object + id: ID! + + # The MBID of the entity. + mbid: MBID! + + # A list of recordings linked to this entity. + recordings(after: String, first: Int): RecordingConnection + + # A list of releases linked to this entity. + releases( + # Filter by one or more release group types. + type: [ReleaseGroupType] + + # Filter by one or more release statuses. + status: [ReleaseStatus] + after: String + first: Int + ): ReleaseConnection +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_mixed_syntax.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_mixed_syntax.graphql new file mode 100644 index 000000000000..0117d333be09 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_mixed_syntax.graphql @@ -0,0 +1,22 @@ +type MixedArtist implements Node& Entity & Releasable { + # The ID of an object + id: ID! + + # The MBID of the entity. + mbid: MBID! + + # A list of recordings linked to this entity. + recordings(after: String, first: Int): RecordingConnection + + # A list of releases linked to this entity. + releases( + # Filter by one or more release group types. + type: [ReleaseGroupType] + + # Filter by one or more release statuses. + status: [ReleaseStatus] + after: String + first: Int + ): ReleaseConnection + +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_mixed_syntax.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_mixed_syntax.graphql.prettier-snap new file mode 100644 index 000000000000..bd6eac26ce5c --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_mixed_syntax.graphql.prettier-snap @@ -0,0 +1,21 @@ +type MixedArtist implements Node & Entity & Releasable { + # The ID of an object + id: ID! + + # The MBID of the entity. + mbid: MBID! + + # A list of recordings linked to this entity. + recordings(after: String, first: Int): RecordingConnection + + # A list of releases linked to this entity. + releases( + # Filter by one or more release group types. + type: [ReleaseGroupType] + + # Filter by one or more release statuses. + status: [ReleaseStatus] + after: String + first: Int + ): ReleaseConnection +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_old_syntax.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_old_syntax.graphql new file mode 100644 index 000000000000..17f3a83acb44 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_old_syntax.graphql @@ -0,0 +1,22 @@ +type OldArtist implements Node& Entity { + # The ID of an object + id: ID! + + # The MBID of the entity. + mbid: MBID! + + # A list of recordings linked to this entity. + recordings(after: String, first: Int): RecordingConnection + + # A list of releases linked to this entity. + releases( + # Filter by one or more release group types. + type: [ReleaseGroupType] + + # Filter by one or more release statuses. + status: [ReleaseStatus] + after: String + first: Int + ): ReleaseConnection + +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_old_syntax.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_old_syntax.graphql.prettier-snap new file mode 100644 index 000000000000..8b1076d5186f --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/object_type_def_old_syntax.graphql.prettier-snap @@ -0,0 +1,21 @@ +type OldArtist implements Node & Entity { + # The ID of an object + id: ID! + + # The MBID of the entity. + mbid: MBID! + + # A list of recordings linked to this entity. + recordings(after: String, first: Int): RecordingConnection + + # A list of releases linked to this entity. + releases( + # Filter by one or more release group types. + type: [ReleaseGroupType] + + # Filter by one or more release statuses. + status: [ReleaseStatus] + after: String + first: Int + ): ReleaseConnection +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql new file mode 100644 index 000000000000..0dd4fd782c95 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql @@ -0,0 +1,30 @@ +# This file used to test legacy syntax of interfaces that already removed in `graphql` v16 +# Some comments are outdated +#type Type1 implements A& B& C& D +# {&&&&&&&& +# Should separate by `,` not `&` +#{a: a} + +#type Type2 implements A& B& C& D +# &&&&{}&&&& +# Should separate by `,` not `&` +#{a: a} + +#type Type3 implements A& +# &&&&&&&& comment line 1 + # &&&&&&&& comment line 2 +#B& C& D +#{a: a} + +#type Type4 implements A +# &&&&&&&& comment line 1 +#& + # &&&&&&&& comment line 2 +#B& C& D +#{a: a} + +#type Type5 implements A +# &&&&&&&& comment line 1 + # &&&&&&&& comment line 2 +#&B& C& D +#{a: a} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql.prettier-snap new file mode 100644 index 000000000000..b768e3aa39ec --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql.prettier-snap @@ -0,0 +1,34 @@ +# This file used to test legacy syntax of interfaces that already removed in `graphql` v16 +# Some comments are outdated +type Type1 implements A & B & C & D { + # {&&&&&&&& + # Should separate by `,` not `&` + a: a +} + +type Type2 implements A & B & C & D { + # &&&&{}&&&& + # Should separate by `,` not `&` + a: a +} + +type Type3 implements A & +# &&&&&&&& comment line 1 +# &&&&&&&& comment line 2 +B & C & D { + a: a +} + +type Type4 implements A & +# &&&&&&&& comment line 1 +# &&&&&&&& comment line 2 +B & C & D { + a: a +} + +type Type5 implements A & +# &&&&&&&& comment line 1 +# &&&&&&&& comment line 2 +B & C & D { + a: a +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql.snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql.snap new file mode 100644 index 000000000000..c4e74430ce4d --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/interface/separator-detection.graphql.snap @@ -0,0 +1,140 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/interface/separator-detection.graphql +--- +# Input + +```graphql +# This file used to test legacy syntax of interfaces that already removed in `graphql` v16 +# Some comments are outdated +#type Type1 implements A& B& C& D +# {&&&&&&&& +# Should separate by `,` not `&` +#{a: a} + +#type Type2 implements A& B& C& D +# &&&&{}&&&& +# Should separate by `,` not `&` +#{a: a} + +#type Type3 implements A& +# &&&&&&&& comment line 1 + # &&&&&&&& comment line 2 +#B& C& D +#{a: a} + +#type Type4 implements A +# &&&&&&&& comment line 1 +#& + # &&&&&&&& comment line 2 +#B& C& D +#{a: a} + +#type Type5 implements A +# &&&&&&&& comment line 1 + # &&&&&&&& comment line 2 +#&B& C& D +#{a: a} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Biome +@@ -1,34 +1,30 @@ + # This file used to test legacy syntax of interfaces that already removed in `graphql` v16 + # Some comments are outdated +-type Type1 implements A & B & C & D { +- # {&&&&&&&& +- # Should separate by `,` not `&` +- a: a +-} ++#type Type1 implements A& B& C& D ++# {&&&&&&&& ++# Should separate by `,` not `&` ++#{a: a} + +-type Type2 implements A & B & C & D { +- # &&&&{}&&&& +- # Should separate by `,` not `&` +- a: a +-} ++#type Type2 implements A& B& C& D ++# &&&&{}&&&& ++# Should separate by `,` not `&` ++#{a: a} + +-type Type3 implements A & ++#type Type3 implements A& + # &&&&&&&& comment line 1 + # &&&&&&&& comment line 2 +-B & C & D { +- a: a +-} ++#B& C& D ++#{a: a} + +-type Type4 implements A & ++#type Type4 implements A + # &&&&&&&& comment line 1 ++#& + # &&&&&&&& comment line 2 +-B & C & D { +- a: a +-} ++#B& C& D ++#{a: a} + +-type Type5 implements A & ++#type Type5 implements A + # &&&&&&&& comment line 1 + # &&&&&&&& comment line 2 +-B & C & D { +- a: a +-} ++#&B& C& D ++#{a: a} +``` + +# Output + +```graphql +# This file used to test legacy syntax of interfaces that already removed in `graphql` v16 +# Some comments are outdated +#type Type1 implements A& B& C& D +# {&&&&&&&& +# Should separate by `,` not `&` +#{a: a} + +#type Type2 implements A& B& C& D +# &&&&{}&&&& +# Should separate by `,` not `&` +#{a: a} + +#type Type3 implements A& +# &&&&&&&& comment line 1 +# &&&&&&&& comment line 2 +#B& C& D +#{a: a} + +#type Type4 implements A +# &&&&&&&& comment line 1 +#& +# &&&&&&&& comment line 2 +#B& C& D +#{a: a} + +#type Type5 implements A +# &&&&&&&& comment line 1 +# &&&&&&&& comment line 2 +#&B& C& D +#{a: a} +``` + +# Lines exceeding max width of 80 characters +``` + 1: # This file used to test legacy syntax of interfaces that already removed in `graphql` v16 +``` diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql new file mode 100644 index 000000000000..7b7908a46b3d --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql @@ -0,0 +1,57 @@ +# Copyright (c) 2015-present, Facebook, Inc. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +query queryName($foo: ComplexType, $site: Site = MOBILE) { + whoever123is: node(id: [123, 456]) { + id , + ... on User @defer { + field2 { + id , + alias: field1(first:10, after:$foo,) @include(if: $foo) { + id, + ...frag + } + } + } + ... @skip(unless: $foo) { + id + } + ... { + id + } + } +} + +mutation likeStory { + like(story: 123) @defer { + story { + id + } + } +} + +subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) { + storyLikeSubscribe(input: $input) { + story { + likers { + count + } + likeSentence { + text + } + } + } +} + +fragment frag on Friend { + foo(size: $size, bar: $b, obj: {key: "value", block: """ + block string uses \""" + """}) +} + +{ + unnamed(truthy: true, falsey: false, nullish: null), + query +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql.prettier-snap new file mode 100644 index 000000000000..ac6d3862665b --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql.prettier-snap @@ -0,0 +1,64 @@ +# Copyright (c) 2015-present, Facebook, Inc. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +query queryName($foo: ComplexType, $site: Site = MOBILE) { + whoever123is: node(id: [123, 456]) { + id + ... on User @defer { + field2 { + id + alias: field1(first: 10, after: $foo) @include(if: $foo) { + id + ...frag + } + } + } + ... @skip(unless: $foo) { + id + } + ... { + id + } + } +} + +mutation likeStory { + like(story: 123) @defer { + story { + id + } + } +} + +subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) { + storyLikeSubscribe(input: $input) { + story { + likers { + count + } + likeSentence { + text + } + } + } +} + +fragment frag on Friend { + foo( + size: $size + bar: $b + obj: { + key: "value" + block: """ + block string uses \""" + """ + } + ) +} + +{ + unnamed(truthy: true, falsey: false, nullish: null) + query +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql.snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql.snap new file mode 100644 index 000000000000..104ca57b190c --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/kitchen_sink.graphql.snap @@ -0,0 +1,152 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/kitchen-sink/kitchen_sink.graphql +--- +# Input + +```graphql +# Copyright (c) 2015-present, Facebook, Inc. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +query queryName($foo: ComplexType, $site: Site = MOBILE) { + whoever123is: node(id: [123, 456]) { + id , + ... on User @defer { + field2 { + id , + alias: field1(first:10, after:$foo,) @include(if: $foo) { + id, + ...frag + } + } + } + ... @skip(unless: $foo) { + id + } + ... { + id + } + } +} + +mutation likeStory { + like(story: 123) @defer { + story { + id + } + } +} + +subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) { + storyLikeSubscribe(input: $input) { + story { + likers { + count + } + likeSentence { + text + } + } + } +} + +fragment frag on Friend { + foo(size: $size, bar: $b, obj: {key: "value", block: """ + block string uses \""" + """}) +} + +{ + unnamed(truthy: true, falsey: false, nullish: null), + query +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Biome +@@ -53,7 +53,7 @@ + key: "value" + block: """ + block string uses \""" +- """ ++ """ + } + ) + } +``` + +# Output + +```graphql +# Copyright (c) 2015-present, Facebook, Inc. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +query queryName($foo: ComplexType, $site: Site = MOBILE) { + whoever123is: node(id: [123, 456]) { + id + ... on User @defer { + field2 { + id + alias: field1(first: 10, after: $foo) @include(if: $foo) { + id + ...frag + } + } + } + ... @skip(unless: $foo) { + id + } + ... { + id + } + } +} + +mutation likeStory { + like(story: 123) @defer { + story { + id + } + } +} + +subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) { + storyLikeSubscribe(input: $input) { + story { + likers { + count + } + likeSentence { + text + } + } + } +} + +fragment frag on Friend { + foo( + size: $size + bar: $b + obj: { + key: "value" + block: """ + block string uses \""" + """ + } + ) +} + +{ + unnamed(truthy: true, falsey: false, nullish: null) + query +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/schema_kitchen_sink.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/schema_kitchen_sink.graphql new file mode 100644 index 000000000000..e4a5327bfcef --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/schema_kitchen_sink.graphql @@ -0,0 +1,124 @@ +# Copyright (c) 2015-present, Facebook, Inc. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +schema { + query: QueryType + mutation: MutationType +} + +extend schema @directive { + subscription: Subscription +} + +""" +This is a description +of the `Foo` type. +""" +type Foo implements Bar { + one: Type + two(argument: InputType!): Type + three(argument: InputType, other: String): Int + four(argument: String = "string"): String + five(argument: [String] = ["string", "string"]): String + six(argument: InputType = {key: "value"}): Type + seven(argument: Int = null): Type +} + +type AnnotatedObject @onObject(arg: "value") { + annotatedField(arg: Type = "default" @onArg): Type @onField +} + +type UndefinedType + +extend type Foo { + seven(argument: [String]): Type +} + +extend type Foo @onType + +""" +This is a description +""" +interface Bar { + one: Type + four(argument: String = "string"): String +} + +interface AnnotatedInterface @onInterface { + annotatedField(arg: Type @onArg): Type @onField +} + +interface UndefinedInterface + +extend interface Bar { + two(argument: InputType!): Type +} + +extend interface Bar @onInterface + +union Feed = Story | Article | Advert + +union AnnotatedUnion @onUnion = A | B + +union AnnotatedUnionTwo @onUnion = | A | B + +union UndefinedUnion + +extend union Feed = Photo | Video + +extend union Feed @onUnion + +scalar CustomScalar + +scalar AnnotatedScalar @onScalar + +extend scalar CustomScalar @onScalar + +enum Site { + DESKTOP + MOBILE +} + +enum AnnotatedEnum @onEnum { + ANNOTATED_VALUE @onEnumValue + OTHER_VALUE +} + +enum UndefinedEnum + +extend enum Site { + VR +} + +extend enum Site @onEnum + +input InputType { + key: String! + answer: Int = 42 +} + +input AnnotatedInput @onInputObject { + annotatedField: Type @onField +} + +input UndefinedInput + +extend input InputType { + other: Float = 1.23e4 +} + +extend input InputType @onInputObject + +directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + +directive @include(if: Boolean!) + on FIELD + | FRAGMENT_SPREAD + | INLINE_FRAGMENT + +directive @include2(if: Boolean!) on + | FIELD + | FRAGMENT_SPREAD + | INLINE_FRAGMENT diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/schema_kitchen_sink.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/schema_kitchen_sink.graphql.prettier-snap new file mode 100644 index 000000000000..eb3ca39841b4 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/kitchen-sink/schema_kitchen_sink.graphql.prettier-snap @@ -0,0 +1,118 @@ +# Copyright (c) 2015-present, Facebook, Inc. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +schema { + query: QueryType + mutation: MutationType +} + +extend schema @directive { + subscription: Subscription +} + +""" +This is a description +of the `Foo` type. +""" +type Foo implements Bar { + one: Type + two(argument: InputType!): Type + three(argument: InputType, other: String): Int + four(argument: String = "string"): String + five(argument: [String] = ["string", "string"]): String + six(argument: InputType = { key: "value" }): Type + seven(argument: Int = null): Type +} + +type AnnotatedObject @onObject(arg: "value") { + annotatedField(arg: Type = "default" @onArg): Type @onField +} + +type UndefinedType + +extend type Foo { + seven(argument: [String]): Type +} + +extend type Foo @onType + +""" +This is a description +""" +interface Bar { + one: Type + four(argument: String = "string"): String +} + +interface AnnotatedInterface @onInterface { + annotatedField(arg: Type @onArg): Type @onField +} + +interface UndefinedInterface + +extend interface Bar { + two(argument: InputType!): Type +} + +extend interface Bar @onInterface + +union Feed = Story | Article | Advert + +union AnnotatedUnion @onUnion = A | B + +union AnnotatedUnionTwo @onUnion = A | B + +union UndefinedUnion + +extend union Feed = Photo | Video + +extend union Feed @onUnion + +scalar CustomScalar + +scalar AnnotatedScalar @onScalar + +extend scalar CustomScalar @onScalar + +enum Site { + DESKTOP + MOBILE +} + +enum AnnotatedEnum @onEnum { + ANNOTATED_VALUE @onEnumValue + OTHER_VALUE +} + +enum UndefinedEnum + +extend enum Site { + VR +} + +extend enum Site @onEnum + +input InputType { + key: String! + answer: Int = 42 +} + +input AnnotatedInput @onInputObject { + annotatedField: Type @onField +} + +input UndefinedInput + +extend input InputType { + other: Float = 1.23e4 +} + +extend input InputType @onInputObject + +directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + +directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT + +directive @include2(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/lists/lists.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/lists/lists.graphql new file mode 100644 index 000000000000..099d2bbad651 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/lists/lists.graphql @@ -0,0 +1,4 @@ +{ + shortWithList(list: [1, 2, 3]) + longWithList(list: ["hello world this is a very long string!","hello world this is a very long string!", "hello world this is a very long string!"]) +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/lists/lists.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/lists/lists.graphql.prettier-snap new file mode 100644 index 000000000000..5dd0bbc2e8e6 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/lists/lists.graphql.prettier-snap @@ -0,0 +1,10 @@ +{ + shortWithList(list: [1, 2, 3]) + longWithList( + list: [ + "hello world this is a very long string!" + "hello world this is a very long string!" + "hello world this is a very long string!" + ] + ) +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directive_decl.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directive_decl.graphql new file mode 100644 index 000000000000..23fab7d4de40 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directive_decl.graphql @@ -0,0 +1,10 @@ +directive @dir( + # comment + arg1: String + + + # comment + arg2: String + arg3: String + +) on QUERY diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directive_decl.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directive_decl.graphql.prettier-snap new file mode 100644 index 000000000000..53cd4a65283e --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directive_decl.graphql.prettier-snap @@ -0,0 +1,8 @@ +directive @dir( + # comment + arg1: String + + # comment + arg2: String + arg3: String +) on QUERY diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directives.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directives.graphql new file mode 100644 index 000000000000..0829a33c778b --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directives.graphql @@ -0,0 +1,17 @@ +query MyQuery @directive( + arg: 5 + + # comment + arg2: 10 + +) { + field @skip( + if: true + + # comment + cursor: 10 + + ) @nope + otherField + ...fragmentSpread, @include(if: ["this isn't even a boolean", "wow, that's really odd",,,,,]) +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directives.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directives.graphql.prettier-snap new file mode 100644 index 000000000000..eee4188c11b1 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/directives.graphql.prettier-snap @@ -0,0 +1,19 @@ +query MyQuery +@directive( + arg: 5 + + # comment + arg2: 10 +) { + field + @skip( + if: true + + # comment + cursor: 10 + ) + @nope + otherField + ...fragmentSpread + @include(if: ["this isn't even a boolean", "wow, that's really odd"]) +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/enum.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/enum.graphql new file mode 100644 index 000000000000..29ee21fa7307 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/enum.graphql @@ -0,0 +1,11 @@ +enum State { + # pending state + PENDING + + # visible states + VISIBLE + INVISIBLE + + # archive state + ARCHIVED +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/enum.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/enum.graphql.prettier-snap new file mode 100644 index 000000000000..29ee21fa7307 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/enum.graphql.prettier-snap @@ -0,0 +1,11 @@ +enum State { + # pending state + PENDING + + # visible states + VISIBLE + INVISIBLE + + # archive state + ARCHIVED +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/fields.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/fields.graphql new file mode 100644 index 000000000000..6541ac56445c --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/fields.graphql @@ -0,0 +1,35 @@ +query MyFirstQuery { + # comment + field { + + subfield + + # comment + subfield + + } + + field + #comment + field + +} + +mutation MyFirstMutation { + + # comment + name + + comment # comment + kind + +} + +subscription MySubscription { + + name + + comment + kind + +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/fields.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/fields.graphql.prettier-snap new file mode 100644 index 000000000000..930aa14ddc50 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/fields.graphql.prettier-snap @@ -0,0 +1,28 @@ +query MyFirstQuery { + # comment + field { + subfield + + # comment + subfield + } + + field + #comment + field +} + +mutation MyFirstMutation { + # comment + name + + comment # comment + kind +} + +subscription MySubscription { + name + + comment + kind +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/input.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/input.graphql new file mode 100644 index 000000000000..d884414df449 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/input.graphql @@ -0,0 +1,8 @@ +input Params { + # Id + id: ID + + # Name + name: String + +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/input.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/input.graphql.prettier-snap new file mode 100644 index 000000000000..ead426ba76e3 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/input.graphql.prettier-snap @@ -0,0 +1,7 @@ +input Params { + # Id + id: ID + + # Name + name: String +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/interface.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/interface.graphql new file mode 100644 index 000000000000..ca7c232c6761 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/interface.graphql @@ -0,0 +1,9 @@ +interface Actor { + # Id + id: ID + + # Actor fields + name: String + kind: String + +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/interface.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/interface.graphql.prettier-snap new file mode 100644 index 000000000000..e52426954049 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/interface.graphql.prettier-snap @@ -0,0 +1,8 @@ +interface Actor { + # Id + id: ID + + # Actor fields + name: String + kind: String +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/object_type_def.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/object_type_def.graphql new file mode 100644 index 000000000000..d5b85677b73a --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/object_type_def.graphql @@ -0,0 +1,22 @@ +type Artist implements Node& Entity { + # The ID of an object + id: ID! + + # The MBID of the entity. + mbid: MBID! + + # A list of recordings linked to this entity. + recordings(after: String, first: Int): RecordingConnection + + # A list of releases linked to this entity. + releases( + # Filter by one or more release group types. + type: [ReleaseGroupType] + + # Filter by one or more release statuses. + status: [ReleaseStatus] + after: String + first: Int + ): ReleaseConnection + +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/object_type_def.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/object_type_def.graphql.prettier-snap new file mode 100644 index 000000000000..9fc66c74d56d --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/object_type_def.graphql.prettier-snap @@ -0,0 +1,21 @@ +type Artist implements Node & Entity { + # The ID of an object + id: ID! + + # The MBID of the entity. + mbid: MBID! + + # A list of recordings linked to this entity. + recordings(after: String, first: Int): RecordingConnection + + # A list of releases linked to this entity. + releases( + # Filter by one or more release group types. + type: [ReleaseGroupType] + + # Filter by one or more release statuses. + status: [ReleaseStatus] + after: String + first: Int + ): ReleaseConnection +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/schema.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/schema.graphql new file mode 100644 index 000000000000..5f0591a5fefd --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/schema.graphql @@ -0,0 +1,10 @@ +# Schema +schema { + # Query and Mutation + query: Root + mutation: Mutation + + # Subscription + subscription: Subscription + +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/schema.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/schema.graphql.prettier-snap new file mode 100644 index 000000000000..ebfbe43d52d7 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/newline/schema.graphql.prettier-snap @@ -0,0 +1,9 @@ +# Schema +schema { + # Query and Mutation + query: Root + mutation: Mutation + + # Subscription + subscription: Subscription +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/arguments.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/arguments.graphql new file mode 100644 index 000000000000..1d5e903d9b2a --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/arguments.graphql @@ -0,0 +1,3 @@ +type Video { + playable_url(quality: String, preferred: String): Url +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/arguments.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/arguments.graphql.prettier-snap new file mode 100644 index 000000000000..1d5e903d9b2a --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/arguments.graphql.prettier-snap @@ -0,0 +1,3 @@ +type Video { + playable_url(quality: String, preferred: String): Url +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/directives.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/directives.graphql new file mode 100644 index 000000000000..195b829bba19 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/directives.graphql @@ -0,0 +1,3 @@ +type PokemonType { + pokemon_type: String @mock(value: "Electric") +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/directives.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/directives.graphql.prettier-snap new file mode 100644 index 000000000000..195b829bba19 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/directives.graphql.prettier-snap @@ -0,0 +1,3 @@ +type PokemonType { + pokemon_type: String @mock(value: "Electric") +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/extend.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/extend.graphql new file mode 100644 index 000000000000..09e9b610dac5 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/extend.graphql @@ -0,0 +1,3 @@ +extend type Feedback { + custom_int: Int +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/extend.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/extend.graphql.prettier-snap new file mode 100644 index 000000000000..09e9b610dac5 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/extend.graphql.prettier-snap @@ -0,0 +1,3 @@ +extend type Feedback { + custom_int: Int +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/implements.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/implements.graphql new file mode 100644 index 000000000000..d12fc47d4af7 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/implements.graphql @@ -0,0 +1,3 @@ +type VRMConversation implements Node& Entity @foo { + a: Int +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/implements.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/implements.graphql.prettier-snap new file mode 100644 index 000000000000..799c725da0b2 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/implements.graphql.prettier-snap @@ -0,0 +1,3 @@ +type VRMConversation implements Node & Entity @foo { + a: Int +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/input.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/input.graphql new file mode 100644 index 000000000000..6782b9b4931f --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/input.graphql @@ -0,0 +1,4 @@ +input Params { + app_id: ID! + key_hash: String! +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/input.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/input.graphql.prettier-snap new file mode 100644 index 000000000000..6782b9b4931f --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/input.graphql.prettier-snap @@ -0,0 +1,4 @@ +input Params { + app_id: ID! + key_hash: String! +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/object_type_def.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/object_type_def.graphql new file mode 100644 index 000000000000..ce8c7eff763d --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/object_type_def.graphql @@ -0,0 +1,4 @@ +type FeedHomeStories { + debug_info: String + query_title: String +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/object_type_def.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/object_type_def.graphql.prettier-snap new file mode 100644 index 000000000000..ce8c7eff763d --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/object-type-def/object_type_def.graphql.prettier-snap @@ -0,0 +1,4 @@ +type FeedHomeStories { + debug_info: String + query_title: String +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/objects/objects.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/objects/objects.graphql new file mode 100644 index 000000000000..d52152c361ee --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/objects/objects.graphql @@ -0,0 +1,9 @@ +{ + shortWithObj(obj: { hello: "world", x: 5 }) + multilineObj(obj: { + hello: "world", + x: 5 + }) + longWithObj(obj: { ,,longString: "hello world this is a very long string!", list: [1, 2, 3, 4, 5, 6, 7] }) + emptyObj(arg: {}) +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/objects/objects.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/objects/objects.graphql.prettier-snap new file mode 100644 index 000000000000..4a629299f71c --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/objects/objects.graphql.prettier-snap @@ -0,0 +1,11 @@ +{ + shortWithObj(obj: { hello: "world", x: 5 }) + multilineObj(obj: { hello: "world", x: 5 }) + longWithObj( + obj: { + longString: "hello world this is a very long string!" + list: [1, 2, 3, 4, 5, 6, 7] + } + ) + emptyObj(arg: {}) +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql new file mode 100644 index 000000000000..14daa32f3d51 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql @@ -0,0 +1,7 @@ +{ + # prettier-ignore + hero { + name + height + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql.prettier-snap new file mode 100644 index 000000000000..14daa32f3d51 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql.prettier-snap @@ -0,0 +1,7 @@ +{ + # prettier-ignore + hero { + name + height + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql.snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql.snap new file mode 100644 index 000000000000..e8c6b6d26639 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/prettier-ignore/prettier-ignore-comment.graphql.snap @@ -0,0 +1,45 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/prettier-ignore/prettier-ignore-comment.graphql +--- +# Input + +```graphql +{ + # prettier-ignore + hero { + name + height + } +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Biome +@@ -1,7 +1,7 @@ + { + # prettier-ignore + hero { +- name ++ name + height + } + } +``` + +# Output + +```graphql +{ + # prettier-ignore + hero { + name + height + } +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/range/issue2296.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/range/issue2296.graphql new file mode 100644 index 000000000000..09df48fca73b --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/range/issue2296.graphql @@ -0,0 +1 @@ +{NP<<>>C{life}} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/range/issue2296.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/range/issue2296.graphql.prettier-snap new file mode 100644 index 000000000000..ff973677c18b --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/range/issue2296.graphql.prettier-snap @@ -0,0 +1,5 @@ +{ + NPC { + life + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/scalar/scalar.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/scalar/scalar.graphql new file mode 100644 index 000000000000..e999eb8c8eeb --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/scalar/scalar.graphql @@ -0,0 +1 @@ +scalar Color @deprecated diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/scalar/scalar.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/scalar/scalar.graphql.prettier-snap new file mode 100644 index 000000000000..e999eb8c8eeb --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/scalar/scalar.graphql.prettier-snap @@ -0,0 +1 @@ +scalar Color @deprecated diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql new file mode 100644 index 000000000000..f426bfad42ad --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql @@ -0,0 +1,13 @@ +"""Schema definition description""" +schema { + query: Root + mutation: Mutation + subscription: Subscription +} + +extend schema { subscription: Subscription } + +# `SchemaExtension`s don't require any operation types and doesn't print +# curlies in their abscence. +extend schema + @directive diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql.prettier-snap new file mode 100644 index 000000000000..7ba968ddc7d7 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql.prettier-snap @@ -0,0 +1,16 @@ +""" +Schema definition description +""" +schema { + query: Root + mutation: Mutation + subscription: Subscription +} + +extend schema { + subscription: Subscription +} + +# `SchemaExtension`s don't require any operation types and doesn't print +# curlies in their abscence. +extend schema @directive diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql.snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql.snap new file mode 100644 index 000000000000..a402f95421ce --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/schema/schema.graphql.snap @@ -0,0 +1,57 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/schema/schema.graphql +--- +# Input + +```graphql +"""Schema definition description""" +schema { + query: Root + mutation: Mutation + subscription: Subscription +} + +extend schema { subscription: Subscription } + +# `SchemaExtension`s don't require any operation types and doesn't print +# curlies in their abscence. +extend schema + @directive + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Biome +@@ -1,6 +1,4 @@ +-""" +-Schema definition description +-""" ++"""Schema definition description""" + schema { + query: Root + mutation: Mutation +``` + +# Output + +```graphql +"""Schema definition description""" +schema { + query: Root + mutation: Mutation + subscription: Subscription +} + +extend schema { + subscription: Subscription +} + +# `SchemaExtension`s don't require any operation types and doesn't print +# curlies in their abscence. +extend schema @directive +``` diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql new file mode 100644 index 000000000000..977a5a80abfd --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql @@ -0,0 +1,74 @@ +""" Customer """ +type Person {name: String} + +""" Customer """ +type Person {name: String} + +""" + + Customer + + +""" +type Person {name: String} + +"""""" +type Person {name: String} + +""" """ +type Person {name: String} + +""" + 1 + 2 +""" +type Person {name: String} + + +""" + + +Empty lines before +""" +type Person {name: String} + +""" +Empty lines after + + +""" +type Person {name: String} + +""" + + +Empty lines around + + +""" +type Person {name: String} + +""" +First line + +Second Line +""" +type Person {name: String} + +""" + + +First line + +Second Line +""" +type Person {name: String} + +""" +First line + +Second Line + + +""" +type Person {name: String} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql.prettier-snap new file mode 100644 index 000000000000..3e4d06058dad --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql.prettier-snap @@ -0,0 +1,88 @@ +""" +Customer +""" +type Person { + name: String +} + +""" +Customer +""" +type Person { + name: String +} + +""" +Customer +""" +type Person { + name: String +} + +""" +""" +type Person { + name: String +} + +""" +""" +type Person { + name: String +} + +""" + 1 +2 +""" +type Person { + name: String +} + +""" +Empty lines before +""" +type Person { + name: String +} + +""" +Empty lines after +""" +type Person { + name: String +} + +""" +Empty lines around +""" +type Person { + name: String +} + +""" +First line + +Second Line +""" +type Person { + name: String +} + +""" +First line + +Second Line +""" +type Person { + name: String +} + +""" +First line + +Second Line +""" +type Person { + name: String +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql.snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql.snap new file mode 100644 index 000000000000..99ec34f4c2af --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/description.graphql.snap @@ -0,0 +1,289 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/string/description.graphql +--- +# Input + +```graphql +""" Customer """ +type Person {name: String} + +""" Customer """ +type Person {name: String} + +""" + + Customer + + +""" +type Person {name: String} + +"""""" +type Person {name: String} + +""" """ +type Person {name: String} + +""" + 1 + 2 +""" +type Person {name: String} + + +""" + + +Empty lines before +""" +type Person {name: String} + +""" +Empty lines after + + +""" +type Person {name: String} + +""" + + +Empty lines around + + +""" +type Person {name: String} + +""" +First line + +Second Line +""" +type Person {name: String} + +""" + + +First line + +Second Line +""" +type Person {name: String} + +""" +First line + +Second Line + + +""" +type Person {name: String} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Biome +@@ -1,45 +1,44 @@ +-""" +-Customer +-""" ++""" Customer """ + type Person { + name: String + } + +-""" +-Customer +-""" ++""" Customer """ + type Person { + name: String + } + + """ +-Customer ++ ++ Customer ++ ++ + """ + type Person { + name: String + } + +-""" +-""" ++"""""" + type Person { + name: String + } + +-""" +-""" ++""" """ + type Person { + name: String + } + + """ +- 1 +-2 ++ 1 ++ 2 + """ + type Person { + name: String + } + + """ ++ ++ + Empty lines before + """ + type Person { +@@ -48,13 +47,19 @@ + + """ + Empty lines after ++ ++ + """ + type Person { + name: String + } + + """ ++ ++ + Empty lines around ++ ++ + """ + type Person { + name: String +@@ -70,6 +75,8 @@ + } + + """ ++ ++ + First line + + Second Line +@@ -82,6 +89,8 @@ + First line + + Second Line ++ ++ + """ + type Person { + name: String +``` + +# Output + +```graphql +""" Customer """ +type Person { + name: String +} + +""" Customer """ +type Person { + name: String +} + +""" + + Customer + + +""" +type Person { + name: String +} + +"""""" +type Person { + name: String +} + +""" """ +type Person { + name: String +} + +""" + 1 + 2 +""" +type Person { + name: String +} + +""" + + +Empty lines before +""" +type Person { + name: String +} + +""" +Empty lines after + + +""" +type Person { + name: String +} + +""" + + +Empty lines around + + +""" +type Person { + name: String +} + +""" +First line + +Second Line +""" +type Person { + name: String +} + +""" + + +First line + +Second Line +""" +type Person { + name: String +} + +""" +First line + +Second Line + + +""" +type Person { + name: String +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql new file mode 100644 index 000000000000..d6b8ceb44685 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql @@ -0,0 +1,60 @@ +query X($a: Int) @relay(meta: "{\"lowPri\": true}") { a } + +"""abc""" +type T { + a: Int +} + +""" +abc +""" +type T { + a: Int +} + +""" + a + b + c + """ +type T { a: Int } + +type Foo { +""" +This is a description +of the `one` field. +""" + one: Type +} + +type Foo { +q("docs" field: String): Type +q("A long string of description of the field parameter to make this break" field: String): Type +q("""docs""" field: String): Type +} + +enum Enum { +""" +Description of `one` +""" +one +} + +input Input { +""" +Description of `one` +""" +one: string +} + +{ + foo(input: {multiline: "ab\ncd"}) { id } +} + +{ + foo(input: {multiline: """ foo """}) { id } +} + +{ + foo(input: {multiline: """ """}) { id } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql.prettier-snap new file mode 100644 index 000000000000..5cb68d933803 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql.prettier-snap @@ -0,0 +1,91 @@ +query X($a: Int) @relay(meta: "{\"lowPri\": true}") { + a +} + +""" +abc +""" +type T { + a: Int +} + +""" +abc +""" +type T { + a: Int +} + +""" +a + b + c +""" +type T { + a: Int +} + +type Foo { + """ + This is a description + of the `one` field. + """ + one: Type +} + +type Foo { + q("docs" field: String): Type + q( + "A long string of description of the field parameter to make this break" + field: String + ): Type + q( + """ + docs + """ + field: String + ): Type +} + +enum Enum { + """ + Description of `one` + """ + one +} + +input Input { + """ + Description of `one` + """ + one: string +} + +{ + foo(input: { multiline: "ab\ncd" }) { + id + } +} + +{ + foo( + input: { + multiline: """ + foo + """ + } + ) { + id + } +} + +{ + foo( + input: { + multiline: """ + """ + } + ) { + id + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql.snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql.snap new file mode 100644 index 000000000000..73fb82d9d16f --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/string/string.graphql.snap @@ -0,0 +1,254 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/string/string.graphql +--- +# Input + +```graphql +query X($a: Int) @relay(meta: "{\"lowPri\": true}") { a } + +"""abc""" +type T { + a: Int +} + +""" +abc +""" +type T { + a: Int +} + +""" + a + b + c + """ +type T { a: Int } + +type Foo { +""" +This is a description +of the `one` field. +""" + one: Type +} + +type Foo { +q("docs" field: String): Type +q("A long string of description of the field parameter to make this break" field: String): Type +q("""docs""" field: String): Type +} + +enum Enum { +""" +Description of `one` +""" +one +} + +input Input { +""" +Description of `one` +""" +one: string +} + +{ + foo(input: {multiline: "ab\ncd"}) { id } +} + +{ + foo(input: {multiline: """ foo """}) { id } +} + +{ + foo(input: {multiline: """ """}) { id } +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Biome +@@ -2,9 +2,7 @@ + a + } + +-""" +-abc +-""" ++"""abc""" + type T { + a: Int + } +@@ -17,47 +15,42 @@ + } + + """ +-a +- b +- c +-""" ++ a ++ b ++ c ++ """ + type T { + a: Int + } + + type Foo { + """ +- This is a description +- of the `one` field. +- """ ++This is a description ++of the `one` field. ++""" + one: Type + } + + type Foo { +- q("docs" field: String): Type ++ q("docs"field: String): Type + q( + "A long string of description of the field parameter to make this break" + field: String + ): Type +- q( +- """ +- docs +- """ +- field: String +- ): Type ++ q("""docs"""field: String): Type + } + + enum Enum { +- """ +- Description of `one` + """ ++Description of `one` ++""" + one + } + + input Input { + """ +- Description of `one` +- """ ++Description of `one` ++""" + one: string + } + +@@ -68,24 +61,13 @@ + } + + { +- foo( +- input: { +- multiline: """ +- foo +- """ +- } +- ) { ++ foo(input: { multiline: """ foo """ }) { + id + } + } + + { +- foo( +- input: { +- multiline: """ +- """ +- } +- ) { ++ foo(input: { multiline: """ """ }) { + id + } + } +``` + +# Output + +```graphql +query X($a: Int) @relay(meta: "{\"lowPri\": true}") { + a +} + +"""abc""" +type T { + a: Int +} + +""" +abc +""" +type T { + a: Int +} + +""" + a + b + c + """ +type T { + a: Int +} + +type Foo { + """ +This is a description +of the `one` field. +""" + one: Type +} + +type Foo { + q("docs"field: String): Type + q( + "A long string of description of the field parameter to make this break" + field: String + ): Type + q("""docs"""field: String): Type +} + +enum Enum { + """ +Description of `one` +""" + one +} + +input Input { + """ +Description of `one` +""" + one: string +} + +{ + foo(input: { multiline: "ab\ncd" }) { + id + } +} + +{ + foo(input: { multiline: """ foo """ }) { + id + } +} + +{ + foo(input: { multiline: """ """ }) { + id + } +} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql new file mode 100644 index 000000000000..436510a00f5b --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql @@ -0,0 +1,20 @@ +query Query( + $pageID: ID! + $scale: Float + $PROJECT_UNIT_PROFILE_PICTURE_SIZE: Int + $PROJECT_UNIT_CARD_SIZE: Int +) @argumentDefinitions( + count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}] + ) { + cover_photo { + image( + width: $PROJECT_UNIT_CARD_SIZE, + height: $PROJECT_UNIT_CARD_SIZE, + sizing: "cover-fill", + scale: $scale, + ) { + uri + } + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql.prettier-snap new file mode 100644 index 000000000000..027b72d7d9e5 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql.prettier-snap @@ -0,0 +1,27 @@ +query Query( + $pageID: ID! + $scale: Float + $PROJECT_UNIT_PROFILE_PICTURE_SIZE: Int + $PROJECT_UNIT_CARD_SIZE: Int +) +@argumentDefinitions( + count: { + type: "Int" + defaultValue: 20 + someSuperSuperSuperSuperLongType: 301 + } + test: [ + { type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301 } + ] +) { + cover_photo { + image( + width: $PROJECT_UNIT_CARD_SIZE + height: $PROJECT_UNIT_CARD_SIZE + sizing: "cover-fill" + scale: $scale + ) { + uri + } + } +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql.snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql.snap new file mode 100644 index 000000000000..b99ec756c65b --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/trailing-comma/trailing.graphql.snap @@ -0,0 +1,197 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/trailing-comma/trailing.graphql +--- +# Input + +```graphql +query Query( + $pageID: ID! + $scale: Float + $PROJECT_UNIT_PROFILE_PICTURE_SIZE: Int + $PROJECT_UNIT_CARD_SIZE: Int +) @argumentDefinitions( + count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}] + ) { + cover_photo { + image( + width: $PROJECT_UNIT_CARD_SIZE, + height: $PROJECT_UNIT_CARD_SIZE, + sizing: "cover-fill", + scale: $scale, + ) { + uri + } + } +} + +``` + + +# Prettier differences + +```diff +--- Prettier ++++ Biome +@@ -3,17 +3,12 @@ + $scale: Float + $PROJECT_UNIT_PROFILE_PICTURE_SIZE: Int + $PROJECT_UNIT_CARD_SIZE: Int +-) +-@argumentDefinitions( +- count: { +- type: "Int" +- defaultValue: 20 +- someSuperSuperSuperSuperLongType: 301 +- } +- test: [ +- { type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301 } +- ] +-) { ++) @argumentDefinitions( ++ count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} ++ test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} ++] ++ ) ++{ + cover_photo { + image( + width: $PROJECT_UNIT_CARD_SIZE +``` + +# Output + +```graphql +query Query( + $pageID: ID! + $scale: Float + $PROJECT_UNIT_PROFILE_PICTURE_SIZE: Int + $PROJECT_UNIT_CARD_SIZE: Int +) @argumentDefinitions( + count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} +] + ) +{ + cover_photo { + image( + width: $PROJECT_UNIT_CARD_SIZE + height: $PROJECT_UNIT_CARD_SIZE + sizing: "cover-fill" + scale: $scale + ) { + uri + } + } +} +``` + +# Errors +``` +trailing.graphql:8:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × expected `]` but instead found `{` + + 6 │ ) @argumentDefinitions( + 7 │ count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + > 8 │ test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}] + │ ^ + 9 │ ) { + 10 │ cover_photo { + + i Remove { + +trailing.graphql:8:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a name but instead found '"Int"'. + + 6 │ ) @argumentDefinitions( + 7 │ count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + > 8 │ test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}] + │ ^^^^^ + 9 │ ) { + 10 │ cover_photo { + + i Expected a name here. + + 6 │ ) @argumentDefinitions( + 7 │ count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + > 8 │ test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}] + │ ^^^^^ + 9 │ ) { + 10 │ cover_photo { + +trailing.graphql:8:40 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a name but instead found '20'. + + 6 │ ) @argumentDefinitions( + 7 │ count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + > 8 │ test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}] + │ ^^ + 9 │ ) { + 10 │ cover_photo { + + i Expected a name here. + + 6 │ ) @argumentDefinitions( + 7 │ count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + > 8 │ test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}] + │ ^^ + 9 │ ) { + 10 │ cover_photo { + +trailing.graphql:8:78 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a name but instead found '301'. + + 6 │ ) @argumentDefinitions( + 7 │ count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + > 8 │ test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}] + │ ^^^ + 9 │ ) { + 10 │ cover_photo { + + i Expected a name here. + + 6 │ ) @argumentDefinitions( + 7 │ count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + > 8 │ test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}] + │ ^^^ + 9 │ ) { + 10 │ cover_photo { + +trailing.graphql:8:82 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Expected a definition but instead found '] + )'. + + 6 │ ) @argumentDefinitions( + 7 │ count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + > 8 │ test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}] + │ ^ + > 9 │ ) { + │ ^ + 10 │ cover_photo { + 11 │ image( + + i Expected a definition here. + + 6 │ ) @argumentDefinitions( + 7 │ count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + > 8 │ test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}] + │ ^ + > 9 │ ) { + │ ^ + 10 │ cover_photo { + 11 │ image( + + +``` + +# Lines exceeding max width of 80 characters +``` + 7: count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} + 8: test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301} +``` diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/type-extension-definition/type-extendsion-syntax.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/type-extension-definition/type-extendsion-syntax.graphql new file mode 100644 index 000000000000..4b67be477019 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/type-extension-definition/type-extendsion-syntax.graphql @@ -0,0 +1,8 @@ +type User { + name: String + birthday: Int +} + +extend type User { + age: Int +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/type-extension-definition/type-extendsion-syntax.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/type-extension-definition/type-extendsion-syntax.graphql.prettier-snap new file mode 100644 index 000000000000..4b67be477019 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/type-extension-definition/type-extendsion-syntax.graphql.prettier-snap @@ -0,0 +1,8 @@ +type User { + name: String + birthday: Int +} + +extend type User { + age: Int +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql new file mode 100644 index 000000000000..04a9752e5546 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql @@ -0,0 +1,15 @@ +union myUnion = ATypeName | ASecondTypeName + +union tooLongNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee = A | B + +union mySecondUnion = ATypeName | ASecondTypeName | AThirdTypeName + +union myThirdUnion = AVeryVeryVeryLongNamedTypeName | ASecondVeryVeryVeryLongedNameTypeName + +union longUnion = A | B | C | D | E | F | G | H | I | J | K | L | A | B | C | D | E | F | G | H | I | J | K | L + +union SearchResult = Conference| Festival | Concert | Venue | Conference| Festival | Concert | Venue + +# comment +# comment2 +union union = B | C | D diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql.prettier-snap new file mode 100644 index 000000000000..d0362bb92ef8 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql.prettier-snap @@ -0,0 +1,51 @@ +union myUnion = ATypeName | ASecondTypeName + +union tooLongNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee = + | A + | B + +union mySecondUnion = ATypeName | ASecondTypeName | AThirdTypeName + +union myThirdUnion = + | AVeryVeryVeryLongNamedTypeName + | ASecondVeryVeryVeryLongedNameTypeName + +union longUnion = + | A + | B + | C + | D + | E + | F + | G + | H + | I + | J + | K + | L + | A + | B + | C + | D + | E + | F + | G + | H + | I + | J + | K + | L + +union SearchResult = + | Conference + | Festival + | Concert + | Venue + | Conference + | Festival + | Concert + | Venue + +# comment +# comment2 +union union = B | C | D diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql.prettier-snap-original b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql.prettier-snap-original new file mode 100644 index 000000000000..d0362bb92ef8 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/union-types/union_types.graphql.prettier-snap-original @@ -0,0 +1,51 @@ +union myUnion = ATypeName | ASecondTypeName + +union tooLongNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee = + | A + | B + +union mySecondUnion = ATypeName | ASecondTypeName | AThirdTypeName + +union myThirdUnion = + | AVeryVeryVeryLongNamedTypeName + | ASecondVeryVeryVeryLongedNameTypeName + +union longUnion = + | A + | B + | C + | D + | E + | F + | G + | H + | I + | J + | K + | L + | A + | B + | C + | D + | E + | F + | G + | H + | I + | J + | K + | L + +union SearchResult = + | Conference + | Festival + | Concert + | Venue + | Conference + | Festival + | Concert + | Venue + +# comment +# comment2 +union union = B | C | D diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/variable-definitions/variable_definitions.graphql b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/variable-definitions/variable_definitions.graphql new file mode 100644 index 000000000000..7c46d9e0768c --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/variable-definitions/variable_definitions.graphql @@ -0,0 +1,25 @@ +query short($foo:ComplexType, $site : Site = MOBILE, $nonNull: Int!) { + hello +} + +query long($foo: ComplexType, $site: Float = 124241.12312, +$bar: String = "Long string here", $arg: String = "Hello world!",,,,, +$nonNull: String!) { + hello +} + +query lists($foo: [Int ], $bar: [Int!], $arg: [ Int! ]!) { + ok +} + +query listslong($foo: [String ], $bar: [String!], $arg: [ Int! ]!, $veryLongName: [ Int! ]) { + ok +} + +query withvariabledirective($foo: Int @directive) { + ok +} + +query withvariabledirectives($foo: Int @directive @another) { + ok +} diff --git a/crates/biome_graphql_formatter/tests/specs/prettier/graphql/variable-definitions/variable_definitions.graphql.prettier-snap b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/variable-definitions/variable_definitions.graphql.prettier-snap new file mode 100644 index 000000000000..e0bb4afa5b17 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/graphql/variable-definitions/variable_definitions.graphql.prettier-snap @@ -0,0 +1,34 @@ +query short($foo: ComplexType, $site: Site = MOBILE, $nonNull: Int!) { + hello +} + +query long( + $foo: ComplexType + $site: Float = 124241.12312 + $bar: String = "Long string here" + $arg: String = "Hello world!" + $nonNull: String! +) { + hello +} + +query lists($foo: [Int], $bar: [Int!], $arg: [Int!]!) { + ok +} + +query listslong( + $foo: [String] + $bar: [String!] + $arg: [Int!]! + $veryLongName: [Int!] +) { + ok +} + +query withvariabledirective($foo: Int @directive) { + ok +} + +query withvariabledirectives($foo: Int @directive @another) { + ok +} diff --git a/crates/biome_graphql_parser/src/parser/definitions/interface.rs b/crates/biome_graphql_parser/src/parser/definitions/interface.rs index 46d7adb13655..1b50916b5949 100644 --- a/crates/biome_graphql_parser/src/parser/definitions/interface.rs +++ b/crates/biome_graphql_parser/src/parser/definitions/interface.rs @@ -78,6 +78,7 @@ pub(super) fn parse_implements_interface(p: &mut GraphqlParser) -> ParsedSyntax let m = p.start(); p.bump(T![implements]); + p.eat(T![&]); // leading ampersand separator is optional ImplementsInterfaceList.parse_list(p); @@ -124,10 +125,6 @@ impl ParseSeparatedList for ImplementsInterfaceList { fn allow_empty(&self) -> bool { false } - - fn allow_leading_seperating_element(&self) -> bool { - true - } } struct ImplementsInterfaceListParseRecovery; diff --git a/crates/biome_graphql_parser/src/parser/definitions/union.rs b/crates/biome_graphql_parser/src/parser/definitions/union.rs index d4c817e62fa9..088ecbc56b06 100644 --- a/crates/biome_graphql_parser/src/parser/definitions/union.rs +++ b/crates/biome_graphql_parser/src/parser/definitions/union.rs @@ -68,6 +68,7 @@ fn parse_union_member_types(p: &mut GraphqlParser) -> ParsedSyntax { } let m = p.start(); p.expect(T![=]); + p.eat(T![|]); // leading pipe separator is optional UnionMemberTypeList.parse_list(p); @@ -107,10 +108,6 @@ impl ParseSeparatedList for UnionMemberTypeList { false } - fn allow_leading_seperating_element(&self) -> bool { - true - } - fn allow_empty(&self) -> bool { false } diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/interface.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/interface.graphql.snap index 49e04bf15048..b09adfbe4632 100644 --- a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/interface.graphql.snap +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/interface.graphql.snap @@ -428,10 +428,8 @@ GraphqlRoot { }, implements: GraphqlImplementsInterfaces { implements_token: IMPLEMENTS_KW@480..491 "implements" [] [Whitespace(" ")], - amp_token: missing (optional), + amp_token: AMP@491..492 "&" [] [], interfaces: GraphqlImplementsInterfaceList [ - missing element, - AMP@491..492 "&" [] [], GraphqlNamedType { name: GraphqlName { value_token: GRAPHQL_NAME@492..504 "interface" [Newline("\n"), Newline("\n")] [Whitespace(" ")], @@ -961,15 +959,13 @@ GraphqlRoot { 0: GRAPHQL_NAME@473..480 "Person" [] [Whitespace(" ")] 3: GRAPHQL_IMPLEMENTS_INTERFACES@480..511 0: IMPLEMENTS_KW@480..491 "implements" [] [Whitespace(" ")] - 1: (empty) - 2: GRAPHQL_IMPLEMENTS_INTERFACE_LIST@491..511 - 0: (empty) - 1: AMP@491..492 "&" [] [] - 2: GRAPHQL_NAMED_TYPE@492..504 + 1: AMP@491..492 "&" [] [] + 2: GRAPHQL_IMPLEMENTS_INTERFACE_LIST@492..511 + 0: GRAPHQL_NAMED_TYPE@492..504 0: GRAPHQL_NAME@492..504 0: GRAPHQL_NAME@492..504 "interface" [Newline("\n"), Newline("\n")] [Whitespace(" ")] - 3: (empty) - 4: GRAPHQL_NAMED_TYPE@504..511 + 1: (empty) + 2: GRAPHQL_NAMED_TYPE@504..511 0: GRAPHQL_NAME@504..511 0: GRAPHQL_NAME@504..511 "Person" [] [Whitespace(" ")] 4: GRAPHQL_DIRECTIVE_LIST@511..524 @@ -1159,427 +1155,427 @@ GraphqlRoot { interface.graphql:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `{` but instead found `name` - + 1 │ interface Person > 2 │ name: String │ ^^^^ 3 │ } - 4 │ - + 4 │ + i Remove name - + interface.graphql:8:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a field definition but instead found 'interface Person'. - + 6 │ name: String - 7 │ + 7 │ > 8 │ interface Person │ ^^^^^^^^^^^^^^^^ 9 │ name: String - 10 │ - + 10 │ + i Expected a field definition here. - + 6 │ name: String - 7 │ + 7 │ > 8 │ interface Person │ ^^^^^^^^^^^^^^^^ 9 │ name: String - 10 │ - + 10 │ + interface.graphql:11:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a field definition but instead found 'interface Person'. - + 9 │ name: String - 10 │ + 10 │ > 11 │ interface Person { │ ^^^^^^^^^^^^^^^^ 12 │ name: 13 │ } - + i Expected a field definition here. - + 9 │ name: String - 10 │ + 10 │ > 11 │ interface Person { │ ^^^^^^^^^^^^^^^^ 12 │ name: 13 │ } - + interface.graphql:11:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `}` but instead found `{` - + 9 │ name: String - 10 │ + 10 │ > 11 │ interface Person { │ ^ 12 │ name: 13 │ } - + i Remove { - + interface.graphql:13:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a name but instead found '}'. - + 11 │ interface Person { 12 │ name: > 13 │ } │ ^ - 14 │ + 14 │ 15 │ interface Person { - + i Expected a name here. - + 11 │ interface Person { 12 │ name: > 13 │ } │ ^ - 14 │ + 14 │ 15 │ interface Person { - + interface.graphql:16:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a name but instead found ':'. - + 15 │ interface Person { > 16 │ : String │ ^ 17 │ } - 18 │ - + 18 │ + i Expected a name here. - + 15 │ interface Person { > 16 │ : String │ ^ 17 │ } - 18 │ - + 18 │ + interface.graphql:20:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a name but instead found ':'. - + 19 │ interface Person { > 20 │ : │ ^ 21 │ } - 22 │ - + 22 │ + i Expected a name here. - + 19 │ interface Person { > 20 │ : │ ^ 21 │ } - 22 │ - + 22 │ + interface.graphql:21:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a type but instead found '}'. - + 19 │ interface Person { 20 │ : > 21 │ } │ ^ - 22 │ + 22 │ 23 │ interface Person { - + i Expected a type here. - + 19 │ interface Person { 20 │ : > 21 │ } │ ^ - 22 │ + 22 │ 23 │ interface Person { - + interface.graphql:24:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a field definition but instead found 'name String'. - + 23 │ interface Person { > 24 │ name String │ ^^^^^^^^^^^ 25 │ } - 26 │ - + 26 │ + i Expected a field definition here. - + 23 │ interface Person { > 24 │ name String │ ^^^^^^^^^^^ 25 │ } - 26 │ - + 26 │ + interface.graphql:27:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a definition but instead found 'deprecated'. - + 25 │ } - 26 │ + 26 │ > 27 │ interface Person deprecated { │ ^^^^^^^^^^ 28 │ name: String 29 │ } - + i Expected a definition here. - + 25 │ } - 26 │ + 26 │ > 27 │ interface Person deprecated { │ ^^^^^^^^^^ 28 │ name: String 29 │ } - + interface.graphql:31:20 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a name but instead found '{'. - + 29 │ } - 30 │ + 30 │ > 31 │ interface Person @ { │ ^ 32 │ name: String 33 │ } - + i Expected a name here. - + 29 │ } - 30 │ + 30 │ > 31 │ interface Person @ { │ ^ 32 │ name: String 33 │ } - + interface.graphql:36:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `{` but instead found `:` - + 35 │ interface Person @ > 36 │ name: String │ ^ 37 │ } - 38 │ - + 38 │ + i Remove : - + interface.graphql:39:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a definition but instead found 'implement Character @'. - + 37 │ } - 38 │ + 38 │ > 39 │ interface Person implement Character @ { │ ^^^^^^^^^^^^^^^^^^^^^ 40 │ name: String 41 │ } - + i Expected a definition here. - + 37 │ } - 38 │ + 38 │ > 39 │ interface Person implement Character @ { │ ^^^^^^^^^^^^^^^^^^^^^ 40 │ name: String 41 │ } - + interface.graphql:43:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a definition but instead found 'inter Person'. - + 41 │ } - 42 │ + 42 │ > 43 │ inter Person │ ^^^^^^^^^^^^ - 44 │ + 44 │ 45 │ interface Person implemets Character - + i Expected a definition here. - + 41 │ } - 42 │ + 42 │ > 43 │ inter Person │ ^^^^^^^^^^^^ - 44 │ + 44 │ 45 │ interface Person implemets Character - + interface.graphql:45:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a definition but instead found 'implemets Character'. - + 43 │ inter Person - 44 │ + 44 │ > 45 │ interface Person implemets Character │ ^^^^^^^^^^^^^^^^^^^ - 46 │ + 46 │ 47 │ interface Person implements & - + i Expected a definition here. - + 43 │ inter Person - 44 │ + 44 │ > 45 │ interface Person implemets Character │ ^^^^^^^^^^^^^^^^^^^ - 46 │ + 46 │ 47 │ interface Person implements & - + interface.graphql:49:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `&` but instead found `Person` - + 47 │ interface Person implements & - 48 │ + 48 │ > 49 │ interface Person @ │ ^^^^^^ - 50 │ + 50 │ 51 │ interface Person implents Character @ - + i Remove Person - + interface.graphql:51:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a definition but instead found 'Person implents Character @'. - + 49 │ interface Person @ - 50 │ + 50 │ > 51 │ interface Person implents Character @ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 52 │ + 52 │ 53 │ interface Person implements Character & Character1 & @deprecated - + i Expected a definition here. - + 49 │ interface Person @ - 50 │ + 50 │ > 51 │ interface Person implents Character @ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 52 │ + 52 │ 53 │ interface Person implements Character & Character1 & @deprecated - + interface.graphql:53:54 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a named type but instead found '@'. - + 51 │ interface Person implents Character @ - 52 │ + 52 │ > 53 │ interface Person implements Character & Character1 & @deprecated │ ^ - 54 │ + 54 │ 55 │ interface Person { - + i Expected a named type here. - + 51 │ interface Person implents Character @ - 52 │ + 52 │ > 53 │ interface Person implements Character & Character1 & @deprecated │ ^ - 54 │ + 54 │ 55 │ interface Person { - + interface.graphql:56:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a type but instead found ')'. - + 55 │ interface Person { > 56 │ name(start_with:): String │ ^ 57 │ "filder by age age: Int @deprecated 58 │ picture(: Int = 0): Url - + i Expected a type here. - + 55 │ interface Person { > 56 │ name(start_with:): String │ ^ 57 │ "filder by age age: Int @deprecated 58 │ picture(: Int = 0): Url - + interface.graphql:57:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Missing closing quote - + 55 │ interface Person { 56 │ name(start_with:): String > 57 │ "filder by age age: Int @deprecated │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 58 │ picture(: Int = 0): Url 59 │ height("filter by height" greater_than: @deprecated): Int - + interface.graphql:58:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a name but instead found ':'. - + 56 │ name(start_with:): String 57 │ "filder by age age: Int @deprecated > 58 │ picture(: Int = 0): Url │ ^ 59 │ height("filter by height" greater_than: @deprecated): Int 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int - + i Expected a name here. - + 56 │ name(start_with:): String 57 │ "filder by age age: Int @deprecated > 58 │ picture(: Int = 0): Url │ ^ 59 │ height("filter by height" greater_than: @deprecated): Int 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int - + interface.graphql:59:43 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a type but instead found '@'. - + 57 │ "filder by age age: Int @deprecated 58 │ picture(: Int = 0): Url > 59 │ height("filter by height" greater_than: @deprecated): Int │ ^ 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int 61 │ name(start_with String): String - + i Expected a type here. - + 57 │ "filder by age age: Int @deprecated 58 │ picture(: Int = 0): Url > 59 │ height("filter by height" greater_than: @deprecated): Int │ ^ 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int 61 │ name(start_with String): String - + interface.graphql:60:49 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a value but instead found '@'. - + 58 │ picture(: Int = 0): Url 59 │ height("filter by height" greater_than: @deprecated): Int > 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int │ ^ 61 │ name(start_with String): String 62 │ } - + i Expected a value here. - + 58 │ picture(: Int = 0): Url 59 │ height("filter by height" greater_than: @deprecated): Int > 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int │ ^ 61 │ name(start_with String): String 62 │ } - + interface.graphql:61:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `:` but instead found `String` - + 59 │ height("filter by height" greater_than: @deprecated): Int 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int > 61 │ name(start_with String): String │ ^^^^^^ 62 │ } - 63 │ - + 63 │ + i Remove String - + ``` diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/object.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/object.graphql.snap index 029d9561d386..e1c1f7be3887 100644 --- a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/object.graphql.snap +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/object.graphql.snap @@ -428,10 +428,8 @@ GraphqlRoot { }, implements: GraphqlImplementsInterfaces { implements_token: IMPLEMENTS_KW@413..424 "implements" [] [Whitespace(" ")], - amp_token: missing (optional), + amp_token: AMP@424..425 "&" [] [], interfaces: GraphqlImplementsInterfaceList [ - missing element, - AMP@424..425 "&" [] [], GraphqlNamedType { name: GraphqlName { value_token: GRAPHQL_NAME@425..432 "type" [Newline("\n"), Newline("\n")] [Whitespace(" ")], @@ -961,15 +959,13 @@ GraphqlRoot { 0: GRAPHQL_NAME@406..413 "Person" [] [Whitespace(" ")] 3: GRAPHQL_IMPLEMENTS_INTERFACES@413..439 0: IMPLEMENTS_KW@413..424 "implements" [] [Whitespace(" ")] - 1: (empty) - 2: GRAPHQL_IMPLEMENTS_INTERFACE_LIST@424..439 - 0: (empty) - 1: AMP@424..425 "&" [] [] - 2: GRAPHQL_NAMED_TYPE@425..432 + 1: AMP@424..425 "&" [] [] + 2: GRAPHQL_IMPLEMENTS_INTERFACE_LIST@425..439 + 0: GRAPHQL_NAMED_TYPE@425..432 0: GRAPHQL_NAME@425..432 0: GRAPHQL_NAME@425..432 "type" [Newline("\n"), Newline("\n")] [Whitespace(" ")] - 3: (empty) - 4: GRAPHQL_NAMED_TYPE@432..439 + 1: (empty) + 2: GRAPHQL_NAMED_TYPE@432..439 0: GRAPHQL_NAME@432..439 0: GRAPHQL_NAME@432..439 "Person" [] [Whitespace(" ")] 4: GRAPHQL_DIRECTIVE_LIST@439..447 @@ -1159,427 +1155,427 @@ GraphqlRoot { object.graphql:2:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `{` but instead found `name` - + 1 │ type Person > 2 │ name: String │ ^^^^ 3 │ } - 4 │ - + 4 │ + i Remove name - + object.graphql:8:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a field definition but instead found 'type Person'. - + 6 │ name: String - 7 │ + 7 │ > 8 │ type Person │ ^^^^^^^^^^^ 9 │ name: String - 10 │ - + 10 │ + i Expected a field definition here. - + 6 │ name: String - 7 │ + 7 │ > 8 │ type Person │ ^^^^^^^^^^^ 9 │ name: String - 10 │ - + 10 │ + object.graphql:11:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a field definition but instead found 'type Person'. - + 9 │ name: String - 10 │ + 10 │ > 11 │ type Person { │ ^^^^^^^^^^^ 12 │ name: 13 │ } - + i Expected a field definition here. - + 9 │ name: String - 10 │ + 10 │ > 11 │ type Person { │ ^^^^^^^^^^^ 12 │ name: 13 │ } - + object.graphql:11:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `}` but instead found `{` - + 9 │ name: String - 10 │ + 10 │ > 11 │ type Person { │ ^ 12 │ name: 13 │ } - + i Remove { - + object.graphql:13:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a name but instead found '}'. - + 11 │ type Person { 12 │ name: > 13 │ } │ ^ - 14 │ + 14 │ 15 │ type Person { - + i Expected a name here. - + 11 │ type Person { 12 │ name: > 13 │ } │ ^ - 14 │ + 14 │ 15 │ type Person { - + object.graphql:16:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a name but instead found ':'. - + 15 │ type Person { > 16 │ : String │ ^ 17 │ } - 18 │ - + 18 │ + i Expected a name here. - + 15 │ type Person { > 16 │ : String │ ^ 17 │ } - 18 │ - + 18 │ + object.graphql:20:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a name but instead found ':'. - + 19 │ type Person { > 20 │ : │ ^ 21 │ } - 22 │ - + 22 │ + i Expected a name here. - + 19 │ type Person { > 20 │ : │ ^ 21 │ } - 22 │ - + 22 │ + object.graphql:21:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a type but instead found '}'. - + 19 │ type Person { 20 │ : > 21 │ } │ ^ - 22 │ + 22 │ 23 │ type Person { - + i Expected a type here. - + 19 │ type Person { 20 │ : > 21 │ } │ ^ - 22 │ + 22 │ 23 │ type Person { - + object.graphql:24:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a field definition but instead found 'name String'. - + 23 │ type Person { > 24 │ name String │ ^^^^^^^^^^^ 25 │ } - 26 │ - + 26 │ + i Expected a field definition here. - + 23 │ type Person { > 24 │ name String │ ^^^^^^^^^^^ 25 │ } - 26 │ - + 26 │ + object.graphql:27:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a definition but instead found 'deprecated'. - + 25 │ } - 26 │ + 26 │ > 27 │ type Person deprecated { │ ^^^^^^^^^^ 28 │ name: String 29 │ } - + i Expected a definition here. - + 25 │ } - 26 │ + 26 │ > 27 │ type Person deprecated { │ ^^^^^^^^^^ 28 │ name: String 29 │ } - + object.graphql:31:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a name but instead found '{'. - + 29 │ } - 30 │ + 30 │ > 31 │ type Person @ { │ ^ 32 │ name: String 33 │ } - + i Expected a name here. - + 29 │ } - 30 │ + 30 │ > 31 │ type Person @ { │ ^ 32 │ name: String 33 │ } - + object.graphql:36:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `{` but instead found `:` - + 35 │ type Person @ > 36 │ name: String │ ^ 37 │ } - 38 │ - + 38 │ + i Remove : - + object.graphql:39:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a definition but instead found 'implement Character @'. - + 37 │ } - 38 │ + 38 │ > 39 │ type Person implement Character @ { │ ^^^^^^^^^^^^^^^^^^^^^ 40 │ name: String 41 │ } - + i Expected a definition here. - + 37 │ } - 38 │ + 38 │ > 39 │ type Person implement Character @ { │ ^^^^^^^^^^^^^^^^^^^^^ 40 │ name: String 41 │ } - + object.graphql:43:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a definition but instead found 'typ Person'. - + 41 │ } - 42 │ + 42 │ > 43 │ typ Person │ ^^^^^^^^^^ - 44 │ + 44 │ 45 │ type Person implemets Character - + i Expected a definition here. - + 41 │ } - 42 │ + 42 │ > 43 │ typ Person │ ^^^^^^^^^^ - 44 │ + 44 │ 45 │ type Person implemets Character - + object.graphql:45:13 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a definition but instead found 'implemets Character'. - + 43 │ typ Person - 44 │ + 44 │ > 45 │ type Person implemets Character │ ^^^^^^^^^^^^^^^^^^^ - 46 │ + 46 │ 47 │ type Person implements & - + i Expected a definition here. - + 43 │ typ Person - 44 │ + 44 │ > 45 │ type Person implemets Character │ ^^^^^^^^^^^^^^^^^^^ - 46 │ + 46 │ 47 │ type Person implements & - + object.graphql:49:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `&` but instead found `Person` - + 47 │ type Person implements & - 48 │ + 48 │ > 49 │ type Person @ │ ^^^^^^ - 50 │ + 50 │ 51 │ type Person implents Character @ - + i Remove Person - + object.graphql:51:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a definition but instead found 'Person implents Character @'. - + 49 │ type Person @ - 50 │ + 50 │ > 51 │ type Person implents Character @ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 52 │ + 52 │ 53 │ type Person implements Character & Character1 & @deprecated - + i Expected a definition here. - + 49 │ type Person @ - 50 │ + 50 │ > 51 │ type Person implents Character @ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 52 │ + 52 │ 53 │ type Person implements Character & Character1 & @deprecated - + object.graphql:53:49 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a named type but instead found '@'. - + 51 │ type Person implents Character @ - 52 │ + 52 │ > 53 │ type Person implements Character & Character1 & @deprecated │ ^ - 54 │ + 54 │ 55 │ type Person { - + i Expected a named type here. - + 51 │ type Person implents Character @ - 52 │ + 52 │ > 53 │ type Person implements Character & Character1 & @deprecated │ ^ - 54 │ + 54 │ 55 │ type Person { - + object.graphql:56:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a type but instead found ')'. - + 55 │ type Person { > 56 │ name(start_with:): String │ ^ 57 │ "filder by age age: Int @deprecated 58 │ picture(: Int = 0): Url - + i Expected a type here. - + 55 │ type Person { > 56 │ name(start_with:): String │ ^ 57 │ "filder by age age: Int @deprecated 58 │ picture(: Int = 0): Url - + object.graphql:57:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Missing closing quote - + 55 │ type Person { 56 │ name(start_with:): String > 57 │ "filder by age age: Int @deprecated │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 58 │ picture(: Int = 0): Url 59 │ height("filter by height" greater_than: @deprecated): Int - + object.graphql:58:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a name but instead found ':'. - + 56 │ name(start_with:): String 57 │ "filder by age age: Int @deprecated > 58 │ picture(: Int = 0): Url │ ^ 59 │ height("filter by height" greater_than: @deprecated): Int 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int - + i Expected a name here. - + 56 │ name(start_with:): String 57 │ "filder by age age: Int @deprecated > 58 │ picture(: Int = 0): Url │ ^ 59 │ height("filter by height" greater_than: @deprecated): Int 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int - + object.graphql:59:43 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a type but instead found '@'. - + 57 │ "filder by age age: Int @deprecated 58 │ picture(: Int = 0): Url > 59 │ height("filter by height" greater_than: @deprecated): Int │ ^ 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int 61 │ name(start_with String): String - + i Expected a type here. - + 57 │ "filder by age age: Int @deprecated 58 │ picture(: Int = 0): Url > 59 │ height("filter by height" greater_than: @deprecated): Int │ ^ 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int 61 │ name(start_with String): String - + object.graphql:60:49 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a value but instead found '@'. - + 58 │ picture(: Int = 0): Url 59 │ height("filter by height" greater_than: @deprecated): Int > 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int │ ^ 61 │ name(start_with String): String 62 │ } - + i Expected a value here. - + 58 │ picture(: Int = 0): Url 59 │ height("filter by height" greater_than: @deprecated): Int > 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int │ ^ 61 │ name(start_with String): String 62 │ } - + object.graphql:61:19 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `:` but instead found `String` - + 59 │ height("filter by height" greater_than: @deprecated): Int 60 │ weight("filter by weight" greater_than: Int = @deprecated): Int > 61 │ name(start_with String): String │ ^^^^^^ 62 │ } - 63 │ - + 63 │ + i Remove String - + ``` diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/union.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/union.graphql.snap index f54dc88ec2fb..4bb23ded6b05 100644 --- a/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/union.graphql.snap +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/union.graphql.snap @@ -67,10 +67,8 @@ GraphqlRoot { directives: GraphqlDirectiveList [], union_members: GraphqlUnionMemberTypes { eq_token: missing (required), - bitwise_or_token: missing (optional), + bitwise_or_token: PIPE@48..52 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")], members: GraphqlUnionMemberTypeList [ - missing element, - PIPE@48..52 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")], GraphqlNamedType { name: GraphqlName { value_token: GRAPHQL_NAME@52..57 "Photo" [] [], @@ -94,10 +92,8 @@ GraphqlRoot { directives: GraphqlDirectiveList [], union_members: GraphqlUnionMemberTypes { eq_token: EQ@88..89 "=" [] [], - bitwise_or_token: missing (optional), + bitwise_or_token: PIPE@89..92 "|" [Newline("\n"), Whitespace("\t")] [], members: GraphqlUnionMemberTypeList [ - missing element, - PIPE@89..92 "|" [Newline("\n"), Whitespace("\t")] [], missing element, PIPE@92..96 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")], GraphqlNamedType { @@ -117,10 +113,8 @@ GraphqlRoot { directives: GraphqlDirectiveList [], union_members: GraphqlUnionMemberTypes { eq_token: EQ@123..124 "=" [] [], - bitwise_or_token: missing (optional), + bitwise_or_token: PIPE@124..128 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")], members: GraphqlUnionMemberTypeList [ - missing element, - PIPE@124..128 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")], GraphqlNamedType { name: GraphqlName { value_token: GRAPHQL_NAME@128..133 "Photo" [] [], @@ -192,12 +186,8 @@ GraphqlRoot { directives: GraphqlDirectiveList [], union_members: GraphqlUnionMemberTypes { eq_token: EQ@239..241 "=" [] [Whitespace(" ")], - bitwise_or_token: missing (optional), - members: GraphqlUnionMemberTypeList [ - missing element, - PIPE@241..242 "|" [] [], - missing element, - ], + bitwise_or_token: PIPE@241..242 "|" [] [], + members: GraphqlUnionMemberTypeList [], }, }, GraphqlUnionTypeDefinition { @@ -253,15 +243,13 @@ GraphqlRoot { 3: GRAPHQL_DIRECTIVE_LIST@48..48 4: GRAPHQL_UNION_MEMBER_TYPES@48..67 0: (empty) - 1: (empty) - 2: GRAPHQL_UNION_MEMBER_TYPE_LIST@48..67 - 0: (empty) - 1: PIPE@48..52 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] - 2: GRAPHQL_NAMED_TYPE@52..57 + 1: PIPE@48..52 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] + 2: GRAPHQL_UNION_MEMBER_TYPE_LIST@52..67 + 0: GRAPHQL_NAMED_TYPE@52..57 0: GRAPHQL_NAME@52..57 0: GRAPHQL_NAME@52..57 "Photo" [] [] - 3: PIPE@57..61 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] - 4: GRAPHQL_NAMED_TYPE@61..67 + 1: PIPE@57..61 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] + 2: GRAPHQL_NAMED_TYPE@61..67 0: GRAPHQL_NAME@61..67 0: GRAPHQL_NAME@61..67 "Person" [] [] 2: GRAPHQL_UNION_TYPE_DEFINITION@67..102 @@ -272,13 +260,11 @@ GraphqlRoot { 3: GRAPHQL_DIRECTIVE_LIST@88..88 4: GRAPHQL_UNION_MEMBER_TYPES@88..102 0: EQ@88..89 "=" [] [] - 1: (empty) - 2: GRAPHQL_UNION_MEMBER_TYPE_LIST@89..102 + 1: PIPE@89..92 "|" [Newline("\n"), Whitespace("\t")] [] + 2: GRAPHQL_UNION_MEMBER_TYPE_LIST@92..102 0: (empty) - 1: PIPE@89..92 "|" [Newline("\n"), Whitespace("\t")] [] - 2: (empty) - 3: PIPE@92..96 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] - 4: GRAPHQL_NAMED_TYPE@96..102 + 1: PIPE@92..96 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] + 2: GRAPHQL_NAMED_TYPE@96..102 0: GRAPHQL_NAME@96..102 0: GRAPHQL_NAME@96..102 "Person" [] [] 3: GRAPHQL_UNION_TYPE_DEFINITION@102..152 @@ -289,19 +275,17 @@ GraphqlRoot { 3: GRAPHQL_DIRECTIVE_LIST@123..123 4: GRAPHQL_UNION_MEMBER_TYPES@123..152 0: EQ@123..124 "=" [] [] - 1: (empty) - 2: GRAPHQL_UNION_MEMBER_TYPE_LIST@124..152 - 0: (empty) - 1: PIPE@124..128 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] - 2: GRAPHQL_NAMED_TYPE@128..133 + 1: PIPE@124..128 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] + 2: GRAPHQL_UNION_MEMBER_TYPE_LIST@128..152 + 0: GRAPHQL_NAMED_TYPE@128..133 0: GRAPHQL_NAME@128..133 0: GRAPHQL_NAME@128..133 "Photo" [] [] - 3: (empty) - 4: GRAPHQL_NAMED_TYPE@133..143 + 1: (empty) + 2: GRAPHQL_NAMED_TYPE@133..143 0: GRAPHQL_NAME@133..143 0: GRAPHQL_NAME@133..143 "Person" [Newline("\n"), Whitespace("\t ")] [] - 5: PIPE@143..147 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] - 6: GRAPHQL_NAMED_TYPE@147..152 + 3: PIPE@143..147 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] + 4: GRAPHQL_NAMED_TYPE@147..152 0: GRAPHQL_NAME@147..152 0: GRAPHQL_NAME@147..152 "union" [] [] 4: GRAPHQL_UNION_TYPE_DEFINITION@152..196 @@ -342,11 +326,8 @@ GraphqlRoot { 3: GRAPHQL_DIRECTIVE_LIST@239..239 4: GRAPHQL_UNION_MEMBER_TYPES@239..242 0: EQ@239..241 "=" [] [Whitespace(" ")] - 1: (empty) - 2: GRAPHQL_UNION_MEMBER_TYPE_LIST@241..242 - 0: (empty) - 1: PIPE@241..242 "|" [] [] - 2: (empty) + 1: PIPE@241..242 "|" [] [] + 2: GRAPHQL_UNION_MEMBER_TYPE_LIST@242..242 7: GRAPHQL_UNION_TYPE_DEFINITION@242..266 0: (empty) 1: UNION_KW@242..250 "union" [Newline("\n"), Newline("\n")] [Whitespace(" ")] @@ -371,149 +352,149 @@ GraphqlRoot { union.graphql:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a named type but instead found 'union'. - + 1 │ union SearchResult = Photo | - 2 │ + 2 │ > 3 │ union SearchResult │ ^^^^^ 4 │ | Photo 5 │ | Person - + i Expected a named type here. - + 1 │ union SearchResult = Photo | - 2 │ + 2 │ > 3 │ union SearchResult │ ^^^^^ 4 │ | Photo 5 │ | Person - + union.graphql:4:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `=` but instead found `|` - + 3 │ union SearchResult > 4 │ | Photo │ ^ 5 │ | Person - 6 │ - + 6 │ + i Remove | - + union.graphql:13:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `|` but instead found `Person` - + 11 │ union SearchResult = 12 │ | Photo > 13 │ Person │ ^^^^^^ 14 │ | union - 15 │ - + 15 │ + i Remove Person - + union.graphql:18:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × expected `=` but instead found `SearchResult` - + 16 │ union SearchResult @ - 17 │ + 17 │ > 18 │ union SearchResult | │ ^^^^^^^^^^^^ - 19 │ + 19 │ 20 │ union SearchResult = - + i Remove SearchResult - + union.graphql:20:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a named type but instead found 'union'. - + 18 │ union SearchResult | - 19 │ + 19 │ > 20 │ union SearchResult = │ ^^^^^ - 21 │ + 21 │ 22 │ union SearchResult = | - + i Expected a named type here. - + 18 │ union SearchResult | - 19 │ + 19 │ > 20 │ union SearchResult = │ ^^^^^ - 21 │ + 21 │ 22 │ union SearchResult = | - + union.graphql:22:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a named type but instead found 'union'. - + 20 │ union SearchResult = - 21 │ + 21 │ > 22 │ union SearchResult = | │ ^^^^^ - 23 │ + 23 │ 24 │ union SearchResult @ = - + i Expected a named type here. - + 20 │ union SearchResult = - 21 │ + 21 │ > 22 │ union SearchResult = | │ ^^^^^ - 23 │ + 23 │ 24 │ union SearchResult @ = - + union.graphql:24:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a named type but instead found 'union'. - + 22 │ union SearchResult = | - 23 │ + 23 │ > 24 │ union SearchResult @ = │ ^^^^^ - 25 │ - + 25 │ + i Expected a named type here. - + 22 │ union SearchResult = | - 23 │ + 23 │ > 24 │ union SearchResult @ = │ ^^^^^ - 25 │ - + 25 │ + union.graphql:24:22 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a name but instead found '='. - + 22 │ union SearchResult = | - 23 │ + 23 │ > 24 │ union SearchResult @ = │ ^ - 25 │ - + 25 │ + i Expected a name here. - + 22 │ union SearchResult = | - 23 │ + 23 │ > 24 │ union SearchResult @ = │ ^ - 25 │ - + 25 │ + union.graphql:25:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ × Expected a named type but instead found the end of the file. - + 24 │ union SearchResult @ = - > 25 │ - │ - + > 25 │ + │ + i Expected a named type here. - + 24 │ union SearchResult @ = - > 25 │ - │ - + > 25 │ + │ + ``` diff --git a/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/union.graphql.snap b/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/union.graphql.snap index 0095114e8d14..8d6232bb96a7 100644 --- a/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/union.graphql.snap +++ b/crates/biome_graphql_parser/tests/graphql_test_suite/ok/definitions/union.graphql.snap @@ -59,10 +59,8 @@ GraphqlRoot { directives: GraphqlDirectiveList [], union_members: GraphqlUnionMemberTypes { eq_token: EQ@56..57 "=" [] [], - bitwise_or_token: missing (optional), + bitwise_or_token: PIPE@57..61 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")], members: GraphqlUnionMemberTypeList [ - missing element, - PIPE@57..61 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")], GraphqlNamedType { name: GraphqlName { value_token: GRAPHQL_NAME@61..66 "Photo" [] [], @@ -194,19 +192,17 @@ GraphqlRoot { 3: GRAPHQL_DIRECTIVE_LIST@56..56 4: GRAPHQL_UNION_MEMBER_TYPES@56..85 0: EQ@56..57 "=" [] [] - 1: (empty) - 2: GRAPHQL_UNION_MEMBER_TYPE_LIST@57..85 - 0: (empty) - 1: PIPE@57..61 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] - 2: GRAPHQL_NAMED_TYPE@61..66 + 1: PIPE@57..61 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] + 2: GRAPHQL_UNION_MEMBER_TYPE_LIST@61..85 + 0: GRAPHQL_NAMED_TYPE@61..66 0: GRAPHQL_NAME@61..66 0: GRAPHQL_NAME@61..66 "Photo" [] [] - 3: PIPE@66..70 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] - 4: GRAPHQL_NAMED_TYPE@70..76 + 1: PIPE@66..70 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] + 2: GRAPHQL_NAMED_TYPE@70..76 0: GRAPHQL_NAME@70..76 0: GRAPHQL_NAME@70..76 "Person" [] [] - 5: PIPE@76..80 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] - 6: GRAPHQL_NAMED_TYPE@80..85 + 3: PIPE@76..80 "|" [Newline("\n"), Whitespace("\t")] [Whitespace(" ")] + 4: GRAPHQL_NAMED_TYPE@80..85 0: GRAPHQL_NAME@80..85 0: GRAPHQL_NAME@80..85 "union" [] [] 2: GRAPHQL_UNION_TYPE_DEFINITION@85..114 diff --git a/crates/biome_graphql_syntax/src/file_source.rs b/crates/biome_graphql_syntax/src/file_source.rs index 84e3b7d539b3..d6a67acb7c11 100644 --- a/crates/biome_graphql_syntax/src/file_source.rs +++ b/crates/biome_graphql_syntax/src/file_source.rs @@ -8,7 +8,7 @@ use std::path::Path; )] pub struct GraphqlFileSource { #[allow(unused)] - variant: CssVariant, + variant: GraphqlVariant, } /// The style of GraphQL contained in the file. @@ -16,7 +16,7 @@ pub struct GraphqlFileSource { #[derive( Debug, Clone, Default, Copy, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize, )] -enum CssVariant { +enum GraphqlVariant { #[default] Standard, } @@ -24,7 +24,7 @@ enum CssVariant { impl GraphqlFileSource { pub fn graphql() -> Self { Self { - variant: CssVariant::Standard, + variant: GraphqlVariant::Standard, } } diff --git a/crates/biome_parser/src/parse_lists.rs b/crates/biome_parser/src/parse_lists.rs index c6b0ed49023d..7ed59b873081 100644 --- a/crates/biome_parser/src/parse_lists.rs +++ b/crates/biome_parser/src/parse_lists.rs @@ -127,11 +127,6 @@ pub trait ParseSeparatedList { false } - /// `true` if the list allows for an optional leading separator - fn allow_leading_seperating_element(&self) -> bool { - false - } - /// Method called at each iteration of the loop and checks if the expected /// separator is present. /// @@ -154,9 +149,6 @@ pub trait ParseSeparatedList { || (!p.at( as Parser>::Kind::EOF) && !self.is_at_list_end(p)) { if first { - if self.allow_leading_seperating_element() { - p.eat(self.separating_element_kind()); - } first = false; } else { self.expect_separator(p);