diff --git a/.gitattributes b/.gitattributes index 67faf1894f5d..705d78e4fdb0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -27,6 +27,8 @@ pnpm-lock.yaml linguist-generated=true text=auto eol=lf /crates/biome_js_analyze/tests/specs/**/*.snap linguist-language=Markdown /crates/biome_css_formatter/tests/**/*.css.prettier-snap linguist-language=CSS /crates/biome_css_formatter/tests/**/*.css.snap linguist-language=Markdown +/crates/biome_graphql_formatter/tests/**/*.css.prettier-snap linguist-language=GraphQL +/crates/biome_graphql_formatter/tests/**/*.css.snap linguist-language=Markdown /crates/biome_js_formatter/tests/**/*.ts.prettier-snap linguist-language=TypeScript /crates/biome_js_formatter/tests/**/*.js.prettier-snap linguist-language=JavaScript /crates/biome_js_formatter/tests/**/*.ts.snap linguist-language=Markdown diff --git a/.gitignore b/.gitignore index 7fe36aae799c..6ea6416d8c6e 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ Profile-*.json dhat-heap.json /crates/biome_css_formatter/report.* +/crates/biome_graphql_formatter/report.* /crates/biome_js_formatter/report.* /crates/biome_json_formatter/report.* /crates/biome_json_formatter/report_incompatible.* @@ -27,3 +28,4 @@ dhat-heap.json !/crates/biome_js_formatter/tests/specs/prettier/**/* !/crates/biome_json_formatter/tests/specs/prettier/**/* !/crates/biome_css_formatter/tests/specs/prettier/**/* +!/crates/biome_graphql_formatter/tests/specs/prettier/**/* diff --git a/Cargo.lock b/Cargo.lock index a4219b5cdbc3..e4db1d03645b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -493,6 +493,26 @@ dependencies = [ "biome_rowan", ] +[[package]] +name = "biome_graphql_formatter" +version = "0.1.0" +dependencies = [ + "biome_configuration", + "biome_diagnostics", + "biome_formatter", + "biome_formatter_test", + "biome_graphql_parser", + "biome_graphql_syntax", + "biome_parser", + "biome_rowan", + "biome_service", + "biome_suppression", + "countme", + "serde", + "serde_json", + "tests_macros", +] + [[package]] name = "biome_graphql_parser" version = "0.1.0" @@ -959,6 +979,7 @@ dependencies = [ "biome_formatter", "biome_fs", "biome_graphql_analyze", + "biome_graphql_formatter", "biome_graphql_parser", "biome_graphql_syntax", "biome_grit_patterns", diff --git a/Cargo.toml b/Cargo.toml index 790520bb7eb7..d2c91969c3b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -107,6 +107,7 @@ biome_formatter = { version = "0.5.7", path = "./crates/biome_forma biome_fs = { version = "0.5.7", path = "./crates/biome_fs" } biome_graphql_analyze = { version = "0.0.1", path = "./crates/biome_graphql_analyze" } biome_graphql_factory = { version = "0.1.0", path = "./crates/biome_graphql_factory" } +biome_graphql_formatter = { version = "0.1.0", path = "./crates/biome_graphql_formatter" } biome_graphql_parser = { version = "0.1.0", path = "./crates/biome_graphql_parser" } biome_graphql_syntax = { version = "0.1.0", path = "./crates/biome_graphql_syntax" } biome_grit_factory = { version = "0.5.7", path = "./crates/biome_grit_factory" } diff --git a/crates/biome_cli/src/commands/rage.rs b/crates/biome_cli/src/commands/rage.rs index b6a004f3a13c..a7d7fdfbf016 100644 --- a/crates/biome_cli/src/commands/rage.rs +++ b/crates/biome_cli/src/commands/rage.rs @@ -265,6 +265,18 @@ impl Display for RageConfiguration<'_, '_> { {KeyValuePair("Line width", markup!({DebugDisplayOption(css_formatter_configuration.line_width)}))} {KeyValuePair("Quote style", markup!({DebugDisplay(css_formatter_configuration.quote_style)}))} ).fmt(fmt)?; + + let graphql_formatter_configuration = + configuration.get_graphql_formatter_configuration(); + markup! ( + {Section("GraphQL Formatter")} + {KeyValuePair("Enabled", markup!({DebugDisplay(graphql_formatter_configuration.enabled)}))} + {KeyValuePair("Indent style", markup!({DebugDisplayOption(graphql_formatter_configuration.indent_style)}))} + {KeyValuePair("Indent width", markup!({DebugDisplayOption(graphql_formatter_configuration.indent_width)}))} + {KeyValuePair("Line ending", markup!({DebugDisplayOption(graphql_formatter_configuration.line_ending)}))} + {KeyValuePair("Line width", markup!({DebugDisplayOption(graphql_formatter_configuration.line_width)}))} + {KeyValuePair("Quote style", markup!({DebugDisplay(graphql_formatter_configuration.quote_style)}))} + ).fmt(fmt)?; } // Print linter configuration if --linter option is true diff --git a/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap b/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap index 012b4a91e7e4..7747e22472b1 100644 --- a/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap +++ b/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap @@ -91,6 +91,15 @@ The configuration that is contained inside the file `biome.json` --css-formatter-quote-style= The type of quotes used in CSS code. Defaults to double. --css-linter-enabled= Control the linter for CSS (and its super languages) files. + --graphql-formatter-enabled= Control the formatter for GraphQL files. + --graphql-formatter-indent-style= The indent style applied to GraphQL files. + --graphql-formatter-indent-width=NUMBER The size of the indentation applied to GraphQL files. + Default to 2. + --graphql-formatter-line-ending= The type of line ending applied to GraphQL files. + --graphql-formatter-line-width=NUMBER What's the max width of a line applied to GraphQL files. + Defaults to 80. + --graphql-formatter-quote-style= The type of quotes used in GraphQL code. Defaults + to double. Global options applied to all commands --colors= Set the formatting mode for markup: "off" prints everything as plain text, diff --git a/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap b/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap index 14707f7ccfc4..9751fcc0f32c 100644 --- a/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap +++ b/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap @@ -93,6 +93,15 @@ The configuration that is contained inside the file `biome.json` --css-formatter-quote-style= The type of quotes used in CSS code. Defaults to double. --css-linter-enabled= Control the linter for CSS (and its super languages) files. + --graphql-formatter-enabled= Control the formatter for GraphQL files. + --graphql-formatter-indent-style= The indent style applied to GraphQL files. + --graphql-formatter-indent-width=NUMBER The size of the indentation applied to GraphQL files. + Default to 2. + --graphql-formatter-line-ending= The type of line ending applied to GraphQL files. + --graphql-formatter-line-width=NUMBER What's the max width of a line applied to GraphQL files. + Defaults to 80. + --graphql-formatter-quote-style= The type of quotes used in GraphQL code. Defaults + to double. Global options applied to all commands --colors= Set the formatting mode for markup: "off" prints everything as plain text, diff --git a/crates/biome_cli/tests/snapshots/main_commands_rage/with_formatter_configuration.snap b/crates/biome_cli/tests/snapshots/main_commands_rage/with_formatter_configuration.snap index 7b31d264dd53..25c937f296ae 100644 --- a/crates/biome_cli/tests/snapshots/main_commands_rage/with_formatter_configuration.snap +++ b/crates/biome_cli/tests/snapshots/main_commands_rage/with_formatter_configuration.snap @@ -117,6 +117,14 @@ CSS Formatter: Line width: unset Quote style: Double +GraphQL Formatter: + Enabled: false + Indent style: unset + Indent width: unset + Line ending: unset + Line width: unset + Quote style: Double + Server: Version: 0.0.0 Name: biome_lsp diff --git a/crates/biome_configuration/src/graphql.rs b/crates/biome_configuration/src/graphql.rs new file mode 100644 index 000000000000..1ba3eae3571b --- /dev/null +++ b/crates/biome_configuration/src/graphql.rs @@ -0,0 +1,84 @@ +use crate::PlainIndentStyle; +use biome_deserialize_macros::{Deserializable, Merge, Partial}; +use biome_formatter::{IndentWidth, LineEnding, LineWidth, QuoteStyle}; +use bpaf::Bpaf; +use serde::{Deserialize, Serialize}; + +/// Options applied to GraphQL files +#[derive(Clone, Default, Debug, Deserialize, Eq, Partial, PartialEq, Serialize)] +#[partial(derive(Bpaf, Clone, Deserializable, Eq, Merge, PartialEq))] +#[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))] +#[partial(serde(rename_all = "camelCase", default, deny_unknown_fields))] +pub struct GraphqlConfiguration { + /// GraphQL formatter options + #[partial(type, bpaf(external(partial_graphql_formatter), optional))] + pub formatter: GraphqlFormatter, +} + +/// Options that changes how the GraphQL formatter behaves +#[derive(Clone, Debug, Default, Deserialize, Eq, Partial, PartialEq, Serialize)] +#[partial(derive(Bpaf, Clone, Deserializable, Eq, Merge, PartialEq))] +#[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))] +#[partial(serde(rename_all = "camelCase", default, deny_unknown_fields))] +pub struct GraphqlFormatter { + /// Control the formatter for GraphQL files. + #[partial(bpaf(long("graphql-formatter-enabled"), argument("true|false"), optional))] + pub enabled: bool, + + /// The indent style applied to GraphQL files. + #[partial(bpaf( + long("graphql-formatter-indent-style"), + argument("tab|space"), + optional + ))] + pub indent_style: Option, + + /// The size of the indentation applied to GraphQL files. Default to 2. + #[partial(bpaf(long("graphql-formatter-indent-width"), argument("NUMBER"), optional))] + pub indent_width: Option, + + /// The type of line ending applied to GraphQL files. + #[partial(bpaf( + long("graphql-formatter-line-ending"), + argument("lf|crlf|cr"), + optional + ))] + pub line_ending: Option, + + /// What's the max width of a line applied to GraphQL files. Defaults to 80. + #[partial(bpaf(long("graphql-formatter-line-width"), argument("NUMBER"), optional))] + pub line_width: Option, + + /// The type of quotes used in GraphQL code. Defaults to double. + #[partial(bpaf( + long("graphql-formatter-quote-style"), + argument("double|single"), + optional + ))] + pub quote_style: QuoteStyle, +} + +impl PartialGraphqlFormatter { + pub fn get_formatter_configuration(&self) -> GraphqlFormatter { + GraphqlFormatter { + enabled: self.enabled.unwrap_or_default(), + indent_style: self.indent_style, + indent_width: self.indent_width, + line_ending: self.line_ending, + line_width: self.line_width, + quote_style: self.quote_style.unwrap_or_default(), + } + } +} + +#[test] +fn default_graphql() { + let graphql_configuration = GraphqlFormatter::default(); + + assert!(!graphql_configuration.enabled); + assert_eq!(graphql_configuration.indent_style, None); + assert_eq!(graphql_configuration.indent_width, None); + assert_eq!(graphql_configuration.line_ending, None); + assert_eq!(graphql_configuration.line_width, None); + assert_eq!(graphql_configuration.quote_style, QuoteStyle::Double); +} diff --git a/crates/biome_configuration/src/lib.rs b/crates/biome_configuration/src/lib.rs index d39023285b5d..3f00684014c1 100644 --- a/crates/biome_configuration/src/lib.rs +++ b/crates/biome_configuration/src/lib.rs @@ -7,6 +7,7 @@ pub mod diagnostics; pub mod editorconfig; pub mod formatter; pub mod generated; +pub mod graphql; pub mod javascript; pub mod json; pub mod linter; @@ -33,6 +34,10 @@ pub use formatter::{ partial_formatter_configuration, FormatterConfiguration, PartialFormatterConfiguration, PlainIndentStyle, }; +pub use graphql::{ + partial_graphql_configuration, GraphqlConfiguration, GraphqlFormatter, + PartialGraphqlConfiguration, PartialGraphqlFormatter, +}; pub use javascript::{ partial_javascript_configuration, JavascriptConfiguration, JavascriptFormatter, PartialJavascriptConfiguration, PartialJavascriptFormatter, @@ -106,6 +111,10 @@ pub struct Configuration { #[partial(type, bpaf(external(partial_css_configuration), optional))] pub css: CssConfiguration, + /// Specific configuration for the GraphQL language + #[partial(type, bpaf(external(partial_graphql_configuration), optional))] + pub graphql: GraphqlConfiguration, + /// A list of paths to other JSON files, used to extends the current configuration. #[partial(bpaf(hide))] pub extends: StringSet, @@ -218,6 +227,18 @@ impl PartialConfiguration { .unwrap_or_default() } + pub fn get_graphql_formatter_configuration(&self) -> GraphqlFormatter { + self.graphql + .as_ref() + .map(|f| { + f.formatter + .as_ref() + .map(|f| f.get_formatter_configuration()) + .unwrap_or_default() + }) + .unwrap_or_default() + } + pub fn is_linter_disabled(&self) -> bool { self.linter.as_ref().map_or(false, |f| f.is_disabled()) } 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 e5f734eb1580..0b3dd89994d6 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, @@ -207,7 +207,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/Cargo.toml b/crates/biome_graphql_formatter/Cargo.toml new file mode 100644 index 000000000000..a436fcde4ff9 --- /dev/null +++ b/crates/biome_graphql_formatter/Cargo.toml @@ -0,0 +1,38 @@ +[package] +authors.workspace = true +categories.workspace = true +description = "Biome's GraphQL formatter" +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +name = "biome_graphql_formatter" +repository.workspace = true +version = "0.1.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +biome_diagnostics = { workspace = true } +biome_formatter = { workspace = true } +biome_graphql_syntax = { workspace = true } +biome_rowan = { workspace = true } +biome_suppression = { workspace = true } + +[dev-dependencies] +biome_configuration = { path = "../biome_configuration" } +biome_formatter_test = { path = "../biome_formatter_test" } +biome_graphql_parser = { path = "../biome_graphql_parser" } +biome_parser = { path = "../biome_parser" } +biome_service = { path = "../biome_service" } +countme = { workspace = true, features = ["enable"] } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } +tests_macros = { path = "../tests_macros" } + +# cargo-workspaces metadata +[package.metadata.workspaces] +independent = true + +[lints] +workspace = true diff --git a/crates/biome_graphql_formatter/README.md b/crates/biome_graphql_formatter/README.md new file mode 100644 index 000000000000..a1e4340e15c0 --- /dev/null +++ b/crates/biome_graphql_formatter/README.md @@ -0,0 +1,19 @@ +

+ Biome - Toolchain of the web +

+ +
+ +[![Discord chat][discord-badge]][discord-url] +[![cargo version][cargo-badge]][cargo-url] + +[discord-badge]: https://badgen.net/discord/online-members/BypW39g6Yc?icon=discord&label=discord&color=green +[discord-url]: https://discord.gg/BypW39g6Yc +[cargo-badge]: https://badgen.net/crates/v/biome_graphql_formatter?&color=green +[cargo-url]: https://crates.io/crates/biome_graphql_formatter/ + +
+ +# `biome_graphql_formatter` + +Biome's GraphQL formatter implementation. Follow the [documentation](https://docs.rs/biome_graphql_formatter/). diff --git a/crates/biome_graphql_formatter/src/comments.rs b/crates/biome_graphql_formatter/src/comments.rs new file mode 100644 index 000000000000..8ec441d46da4 --- /dev/null +++ b/crates/biome_graphql_formatter/src/comments.rs @@ -0,0 +1,76 @@ +use crate::prelude::*; +use biome_formatter::comments::{ + is_doc_comment, CommentKind, CommentStyle, Comments, SourceComment, +}; +use biome_formatter::formatter::Formatter; +use biome_formatter::{write, FormatResult, FormatRule}; +use biome_graphql_syntax::{GraphqlLanguage, TextLen}; +use biome_rowan::SyntaxTriviaPieceComments; + +pub type GraphqlComments = Comments; + +#[derive(Default)] +pub struct FormatGraphqlLeadingComment; + +impl FormatRule> for FormatGraphqlLeadingComment { + type Context = GraphqlFormatContext; + + fn fmt( + &self, + comment: &SourceComment, + f: &mut Formatter, + ) -> FormatResult<()> { + if is_doc_comment(comment.piece()) { + let mut source_offset = comment.piece().text_range().start(); + + let mut lines = comment.piece().text().lines(); + + // SAFETY: Safe, `is_doc_comment` only returns `true` for multiline comments + let first_line = lines.next().unwrap(); + write!(f, [dynamic_text(first_line.trim_end(), source_offset)])?; + + source_offset += first_line.text_len(); + + // Indent the remaining lines by one space so that all `*` are aligned. + write!( + f, + [align( + 1, + &format_once(|f| { + for line in lines { + write!( + f, + [hard_line_break(), dynamic_text(line.trim(), source_offset)] + )?; + + source_offset += line.text_len(); + } + + Ok(()) + }) + )] + ) + } else { + write!(f, [comment.piece().as_piece()]) + } + } +} + +#[derive(Eq, PartialEq, Copy, Clone, Debug, Default)] +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")) + false + } + + fn get_comment_kind(_comment: &SyntaxTriviaPieceComments) -> CommentKind { + CommentKind::Line + } +} diff --git a/crates/biome_graphql_formatter/src/context.rs b/crates/biome_graphql_formatter/src/context.rs new file mode 100644 index 000000000000..94840b5fa9f2 --- /dev/null +++ b/crates/biome_graphql_formatter/src/context.rs @@ -0,0 +1,166 @@ +use crate::GraphqlCommentStyle; +use biome_formatter::{prelude::*, AttributePosition, IndentWidth, QuoteStyle}; +use biome_formatter::{ + CstFormatContext, FormatContext, FormatOptions, IndentStyle, LineEnding, LineWidth, + TransformSourceMap, +}; + +use crate::comments::{FormatGraphqlLeadingComment, GraphqlComments}; +use biome_graphql_syntax::{GraphqlFileSource, GraphqlLanguage}; +use std::fmt; +use std::rc::Rc; + +#[derive(Debug)] +pub struct GraphqlFormatContext { + options: GraphqlFormatOptions, + /// The comments of the nodes and tokens in the program. + comments: Rc, + source_map: Option, +} + +impl GraphqlFormatContext { + pub fn new(options: GraphqlFormatOptions, comments: GraphqlComments) -> Self { + Self { + options, + comments: Rc::new(comments), + source_map: None, + } + } + + pub fn with_source_map(mut self, source_map: Option) -> Self { + self.source_map = source_map; + self + } +} + +impl FormatContext for GraphqlFormatContext { + type Options = GraphqlFormatOptions; + + fn options(&self) -> &Self::Options { + &self.options + } + + fn source_map(&self) -> Option<&TransformSourceMap> { + None + } +} + +impl CstFormatContext for GraphqlFormatContext { + type Language = GraphqlLanguage; + type Style = GraphqlCommentStyle; + type CommentRule = FormatGraphqlLeadingComment; + + fn comments(&self) -> &GraphqlComments { + &self.comments + } +} + +#[derive(Debug, Default, Clone, PartialEq)] +pub struct GraphqlFormatOptions { + indent_style: IndentStyle, + indent_width: IndentWidth, + line_ending: LineEnding, + line_width: LineWidth, + quote_style: QuoteStyle, + attribute_position: AttributePosition, + _file_source: GraphqlFileSource, +} + +impl GraphqlFormatOptions { + pub fn new(file_source: GraphqlFileSource) -> Self { + Self { + _file_source: file_source, + indent_style: IndentStyle::default(), + indent_width: IndentWidth::default(), + line_ending: LineEnding::default(), + line_width: LineWidth::default(), + quote_style: QuoteStyle::default(), + attribute_position: AttributePosition::default(), + } + } + + pub fn with_indent_style(mut self, indent_style: IndentStyle) -> Self { + self.indent_style = indent_style; + self + } + + pub fn with_indent_width(mut self, indent_width: IndentWidth) -> Self { + self.indent_width = indent_width; + self + } + + pub fn with_line_ending(mut self, line_ending: LineEnding) -> Self { + self.line_ending = line_ending; + self + } + + pub fn with_line_width(mut self, line_width: LineWidth) -> Self { + self.line_width = line_width; + self + } + + pub fn with_quote_style(mut self, quote_style: QuoteStyle) -> Self { + self.quote_style = quote_style; + self + } + + pub fn set_indent_style(&mut self, indent_style: IndentStyle) { + self.indent_style = indent_style; + } + + pub fn set_indent_width(&mut self, indent_width: IndentWidth) { + self.indent_width = indent_width; + } + + pub fn set_line_ending(&mut self, line_ending: LineEnding) { + self.line_ending = line_ending; + } + + pub fn set_line_width(&mut self, line_width: LineWidth) { + self.line_width = line_width; + } + + pub fn set_quote_style(&mut self, quote_style: QuoteStyle) { + self.quote_style = quote_style; + } + + pub fn quote_style(&self) -> QuoteStyle { + self.quote_style + } +} + +impl FormatOptions for GraphqlFormatOptions { + fn indent_style(&self) -> IndentStyle { + self.indent_style + } + + fn indent_width(&self) -> IndentWidth { + self.indent_width + } + + fn line_ending(&self) -> LineEnding { + self.line_ending + } + + fn line_width(&self) -> LineWidth { + self.line_width + } + + fn as_print_options(&self) -> PrinterOptions { + PrinterOptions::from(self) + } + + fn attribute_position(&self) -> AttributePosition { + self.attribute_position + } +} + +impl fmt::Display for GraphqlFormatOptions { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + writeln!(f, "Indent style: {}", self.indent_style)?; + writeln!(f, "Indent width: {}", self.indent_width.value())?; + writeln!(f, "Line ending: {}", self.line_ending)?; + writeln!(f, "Line width: {}", self.line_width.value())?; + writeln!(f, "Quote style: {}", self.quote_style) + } +} diff --git a/crates/biome_graphql_formatter/src/cst.rs b/crates/biome_graphql_formatter/src/cst.rs new file mode 100644 index 000000000000..cc542e5c5b41 --- /dev/null +++ b/crates/biome_graphql_formatter/src/cst.rs @@ -0,0 +1,30 @@ +use crate::prelude::*; +use biome_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatResult}; +use biome_graphql_syntax::{map_syntax_node, GraphqlSyntaxNode}; + +#[derive(Debug, Copy, Clone, Default)] +pub struct FormatGraphqlSyntaxNode; + +impl FormatRule for FormatGraphqlSyntaxNode { + type Context = GraphqlFormatContext; + + fn fmt(&self, node: &GraphqlSyntaxNode, f: &mut GraphqlFormatter) -> FormatResult<()> { + map_syntax_node!(node.clone(), node => node.format().fmt(f)) + } +} + +impl AsFormat for GraphqlSyntaxNode { + type Format<'a> = FormatRefWithRule<'a, GraphqlSyntaxNode, FormatGraphqlSyntaxNode>; + + fn format(&self) -> Self::Format<'_> { + FormatRefWithRule::new(self, FormatGraphqlSyntaxNode) + } +} + +impl IntoFormat for GraphqlSyntaxNode { + type Format = FormatOwnedWithRule; + + fn into_format(self) -> Self::Format { + FormatOwnedWithRule::new(self, FormatGraphqlSyntaxNode) + } +} diff --git a/crates/biome_graphql_formatter/src/generated.rs b/crates/biome_graphql_formatter/src/generated.rs new file mode 100644 index 000000000000..ddc4e9d20ffb --- /dev/null +++ b/crates/biome_graphql_formatter/src/generated.rs @@ -0,0 +1,2839 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::{ + AsFormat, FormatBogusNodeRule, FormatNodeRule, GraphqlFormatContext, GraphqlFormatter, + IntoFormat, +}; +use biome_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule}; +impl FormatRule + for crate::graphql::auxiliary::alias::FormatGraphqlAlias +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlAlias, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlAlias { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlAlias, + crate::graphql::auxiliary::alias::FormatGraphqlAlias, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::alias::FormatGraphqlAlias::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlAlias { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlAlias, + crate::graphql::auxiliary::alias::FormatGraphqlAlias, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::alias::FormatGraphqlAlias::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::argument::FormatGraphqlArgument +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlArgument, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlArgument { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlArgument, + crate::graphql::auxiliary::argument::FormatGraphqlArgument, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::argument::FormatGraphqlArgument::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlArgument { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlArgument, + crate::graphql::auxiliary::argument::FormatGraphqlArgument, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::argument::FormatGraphqlArgument::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::arguments::FormatGraphqlArguments +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlArguments, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlArguments { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlArguments, + crate::graphql::auxiliary::arguments::FormatGraphqlArguments, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::arguments::FormatGraphqlArguments::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlArguments { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlArguments, + crate::graphql::auxiliary::arguments::FormatGraphqlArguments, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::arguments::FormatGraphqlArguments::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::arguments_definition::FormatGraphqlArgumentsDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlArgumentsDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlArgumentsDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlArgumentsDefinition, + crate::graphql::definitions::arguments_definition::FormatGraphqlArgumentsDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: arguments_definition :: FormatGraphqlArgumentsDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlArgumentsDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlArgumentsDefinition, + crate::graphql::definitions::arguments_definition::FormatGraphqlArgumentsDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: arguments_definition :: FormatGraphqlArgumentsDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::value::boolean_value::FormatGraphqlBooleanValue +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlBooleanValue, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlBooleanValue { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlBooleanValue, + crate::graphql::value::boolean_value::FormatGraphqlBooleanValue, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::value::boolean_value::FormatGraphqlBooleanValue::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlBooleanValue { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlBooleanValue, + crate::graphql::value::boolean_value::FormatGraphqlBooleanValue, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::value::boolean_value::FormatGraphqlBooleanValue::default(), + ) + } +} +impl FormatRule + for crate::graphql::value::default_value::FormatGraphqlDefaultValue +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlDefaultValue, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlDefaultValue { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlDefaultValue, + crate::graphql::value::default_value::FormatGraphqlDefaultValue, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::value::default_value::FormatGraphqlDefaultValue::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlDefaultValue { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlDefaultValue, + crate::graphql::value::default_value::FormatGraphqlDefaultValue, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::value::default_value::FormatGraphqlDefaultValue::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::description::FormatGraphqlDescription +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlDescription, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlDescription { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlDescription, + crate::graphql::auxiliary::description::FormatGraphqlDescription, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::description::FormatGraphqlDescription::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlDescription { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlDescription, + crate::graphql::auxiliary::description::FormatGraphqlDescription, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::description::FormatGraphqlDescription::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::directive::FormatGraphqlDirective +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlDirective, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlDirective { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlDirective, + crate::graphql::auxiliary::directive::FormatGraphqlDirective, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::directive::FormatGraphqlDirective::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlDirective { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlDirective, + crate::graphql::auxiliary::directive::FormatGraphqlDirective, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::directive::FormatGraphqlDirective::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::directive_definition::FormatGraphqlDirectiveDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlDirectiveDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlDirectiveDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlDirectiveDefinition, + crate::graphql::definitions::directive_definition::FormatGraphqlDirectiveDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: directive_definition :: FormatGraphqlDirectiveDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlDirectiveDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlDirectiveDefinition, + crate::graphql::definitions::directive_definition::FormatGraphqlDirectiveDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: directive_definition :: FormatGraphqlDirectiveDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::auxiliary::directive_location::FormatGraphqlDirectiveLocation +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlDirectiveLocation, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlDirectiveLocation { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlDirectiveLocation, + crate::graphql::auxiliary::directive_location::FormatGraphqlDirectiveLocation, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::directive_location::FormatGraphqlDirectiveLocation::default( + ), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlDirectiveLocation { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlDirectiveLocation, + crate::graphql::auxiliary::directive_location::FormatGraphqlDirectiveLocation, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::directive_location::FormatGraphqlDirectiveLocation::default( + ), + ) + } +} +impl FormatRule + for crate::graphql::definitions::enum_type_definition::FormatGraphqlEnumTypeDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlEnumTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlEnumTypeDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlEnumTypeDefinition, + crate::graphql::definitions::enum_type_definition::FormatGraphqlEnumTypeDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: enum_type_definition :: FormatGraphqlEnumTypeDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlEnumTypeDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlEnumTypeDefinition, + crate::graphql::definitions::enum_type_definition::FormatGraphqlEnumTypeDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: enum_type_definition :: FormatGraphqlEnumTypeDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::extensions::enum_type_extension::FormatGraphqlEnumTypeExtension +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlEnumTypeExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlEnumTypeExtension { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlEnumTypeExtension, + crate::graphql::extensions::enum_type_extension::FormatGraphqlEnumTypeExtension, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: extensions :: enum_type_extension :: FormatGraphqlEnumTypeExtension :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlEnumTypeExtension { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlEnumTypeExtension, + crate::graphql::extensions::enum_type_extension::FormatGraphqlEnumTypeExtension, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: extensions :: enum_type_extension :: FormatGraphqlEnumTypeExtension :: default ()) + } +} +impl FormatRule + for crate::graphql::value::enum_value::FormatGraphqlEnumValue +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlEnumValue, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlEnumValue { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlEnumValue, + crate::graphql::value::enum_value::FormatGraphqlEnumValue, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::value::enum_value::FormatGraphqlEnumValue::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlEnumValue { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlEnumValue, + crate::graphql::value::enum_value::FormatGraphqlEnumValue, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::value::enum_value::FormatGraphqlEnumValue::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::enum_value_definition::FormatGraphqlEnumValueDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlEnumValueDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlEnumValueDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlEnumValueDefinition, + crate::graphql::definitions::enum_value_definition::FormatGraphqlEnumValueDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: enum_value_definition :: FormatGraphqlEnumValueDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlEnumValueDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlEnumValueDefinition, + crate::graphql::definitions::enum_value_definition::FormatGraphqlEnumValueDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: enum_value_definition :: FormatGraphqlEnumValueDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::definitions::enum_values_definition::FormatGraphqlEnumValuesDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlEnumValuesDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlEnumValuesDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlEnumValuesDefinition, + crate::graphql::definitions::enum_values_definition::FormatGraphqlEnumValuesDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: enum_values_definition :: FormatGraphqlEnumValuesDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlEnumValuesDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlEnumValuesDefinition, + crate::graphql::definitions::enum_values_definition::FormatGraphqlEnumValuesDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: enum_values_definition :: FormatGraphqlEnumValuesDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::auxiliary::field::FormatGraphqlField +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlField, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlField { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlField, + crate::graphql::auxiliary::field::FormatGraphqlField, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::field::FormatGraphqlField::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlField { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlField, + crate::graphql::auxiliary::field::FormatGraphqlField, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::field::FormatGraphqlField::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::field_definition::FormatGraphqlFieldDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlFieldDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlFieldDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlFieldDefinition, + crate::graphql::definitions::field_definition::FormatGraphqlFieldDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::definitions::field_definition::FormatGraphqlFieldDefinition::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlFieldDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlFieldDefinition, + crate::graphql::definitions::field_definition::FormatGraphqlFieldDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::definitions::field_definition::FormatGraphqlFieldDefinition::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::fields_definition::FormatGraphqlFieldsDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlFieldsDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlFieldsDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlFieldsDefinition, + crate::graphql::definitions::fields_definition::FormatGraphqlFieldsDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::definitions::fields_definition::FormatGraphqlFieldsDefinition::default( + ), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlFieldsDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlFieldsDefinition, + crate::graphql::definitions::fields_definition::FormatGraphqlFieldsDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::definitions::fields_definition::FormatGraphqlFieldsDefinition::default( + ), + ) + } +} +impl FormatRule + for crate::graphql::value::float_value::FormatGraphqlFloatValue +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlFloatValue, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlFloatValue { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlFloatValue, + crate::graphql::value::float_value::FormatGraphqlFloatValue, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::value::float_value::FormatGraphqlFloatValue::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlFloatValue { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlFloatValue, + crate::graphql::value::float_value::FormatGraphqlFloatValue, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::value::float_value::FormatGraphqlFloatValue::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::fragment_definition::FormatGraphqlFragmentDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlFragmentDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlFragmentDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlFragmentDefinition, + crate::graphql::definitions::fragment_definition::FormatGraphqlFragmentDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: fragment_definition :: FormatGraphqlFragmentDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlFragmentDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlFragmentDefinition, + crate::graphql::definitions::fragment_definition::FormatGraphqlFragmentDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: fragment_definition :: FormatGraphqlFragmentDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::auxiliary::fragment_spread::FormatGraphqlFragmentSpread +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlFragmentSpread, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlFragmentSpread { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlFragmentSpread, + crate::graphql::auxiliary::fragment_spread::FormatGraphqlFragmentSpread, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::fragment_spread::FormatGraphqlFragmentSpread::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlFragmentSpread { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlFragmentSpread, + crate::graphql::auxiliary::fragment_spread::FormatGraphqlFragmentSpread, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::fragment_spread::FormatGraphqlFragmentSpread::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::implements_interfaces::FormatGraphqlImplementsInterfaces +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlImplementsInterfaces, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlImplementsInterfaces { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlImplementsInterfaces, + crate::graphql::auxiliary::implements_interfaces::FormatGraphqlImplementsInterfaces, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: auxiliary :: implements_interfaces :: FormatGraphqlImplementsInterfaces :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlImplementsInterfaces { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlImplementsInterfaces, + crate::graphql::auxiliary::implements_interfaces::FormatGraphqlImplementsInterfaces, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: auxiliary :: implements_interfaces :: FormatGraphqlImplementsInterfaces :: default ()) + } +} +impl FormatRule + for crate::graphql::auxiliary::inline_fragment::FormatGraphqlInlineFragment +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlInlineFragment, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlInlineFragment { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlInlineFragment, + crate::graphql::auxiliary::inline_fragment::FormatGraphqlInlineFragment, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::inline_fragment::FormatGraphqlInlineFragment::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlInlineFragment { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlInlineFragment, + crate::graphql::auxiliary::inline_fragment::FormatGraphqlInlineFragment, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::inline_fragment::FormatGraphqlInlineFragment::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::input_fields_definition::FormatGraphqlInputFieldsDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlInputFieldsDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlInputFieldsDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlInputFieldsDefinition, + crate::graphql::definitions::input_fields_definition::FormatGraphqlInputFieldsDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: input_fields_definition :: FormatGraphqlInputFieldsDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlInputFieldsDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlInputFieldsDefinition, + crate::graphql::definitions::input_fields_definition::FormatGraphqlInputFieldsDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: input_fields_definition :: FormatGraphqlInputFieldsDefinition :: default ()) + } +} +impl FormatRule < biome_graphql_syntax :: GraphqlInputObjectTypeDefinition > for crate :: graphql :: definitions :: input_object_type_definition :: FormatGraphqlInputObjectTypeDefinition { type Context = GraphqlFormatContext ; # [inline (always)] fn fmt (& self , node : & biome_graphql_syntax :: GraphqlInputObjectTypeDefinition , f : & mut GraphqlFormatter) -> FormatResult < () > { FormatNodeRule :: < biome_graphql_syntax :: GraphqlInputObjectTypeDefinition > :: fmt (self , node , f) } } +impl AsFormat for biome_graphql_syntax::GraphqlInputObjectTypeDefinition { + type Format < 'a > = FormatRefWithRule < 'a , biome_graphql_syntax :: GraphqlInputObjectTypeDefinition , crate :: graphql :: definitions :: input_object_type_definition :: FormatGraphqlInputObjectTypeDefinition > ; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: input_object_type_definition :: FormatGraphqlInputObjectTypeDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlInputObjectTypeDefinition { + type Format = FormatOwnedWithRule < biome_graphql_syntax :: GraphqlInputObjectTypeDefinition , crate :: graphql :: definitions :: input_object_type_definition :: FormatGraphqlInputObjectTypeDefinition > ; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: input_object_type_definition :: FormatGraphqlInputObjectTypeDefinition :: default ()) + } +} +impl FormatRule < biome_graphql_syntax :: GraphqlInputObjectTypeExtension > for crate :: graphql :: extensions :: input_object_type_extension :: FormatGraphqlInputObjectTypeExtension { type Context = GraphqlFormatContext ; # [inline (always)] fn fmt (& self , node : & biome_graphql_syntax :: GraphqlInputObjectTypeExtension , f : & mut GraphqlFormatter) -> FormatResult < () > { FormatNodeRule :: < biome_graphql_syntax :: GraphqlInputObjectTypeExtension > :: fmt (self , node , f) } } +impl AsFormat for biome_graphql_syntax::GraphqlInputObjectTypeExtension { + type Format < 'a > = FormatRefWithRule < 'a , biome_graphql_syntax :: GraphqlInputObjectTypeExtension , crate :: graphql :: extensions :: input_object_type_extension :: FormatGraphqlInputObjectTypeExtension > ; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: extensions :: input_object_type_extension :: FormatGraphqlInputObjectTypeExtension :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlInputObjectTypeExtension { + type Format = FormatOwnedWithRule < biome_graphql_syntax :: GraphqlInputObjectTypeExtension , crate :: graphql :: extensions :: input_object_type_extension :: FormatGraphqlInputObjectTypeExtension > ; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: extensions :: input_object_type_extension :: FormatGraphqlInputObjectTypeExtension :: default ()) + } +} +impl FormatRule + for crate::graphql::definitions::input_value_definition::FormatGraphqlInputValueDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlInputValueDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlInputValueDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlInputValueDefinition, + crate::graphql::definitions::input_value_definition::FormatGraphqlInputValueDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: input_value_definition :: FormatGraphqlInputValueDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlInputValueDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlInputValueDefinition, + crate::graphql::definitions::input_value_definition::FormatGraphqlInputValueDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: input_value_definition :: FormatGraphqlInputValueDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::value::int_value::FormatGraphqlIntValue +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlIntValue, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlIntValue { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlIntValue, + crate::graphql::value::int_value::FormatGraphqlIntValue, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::value::int_value::FormatGraphqlIntValue::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlIntValue { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlIntValue, + crate::graphql::value::int_value::FormatGraphqlIntValue, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::value::int_value::FormatGraphqlIntValue::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::interface_type_definition::FormatGraphqlInterfaceTypeDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlInterfaceTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlInterfaceTypeDefinition { + type Format < 'a > = FormatRefWithRule < 'a , biome_graphql_syntax :: GraphqlInterfaceTypeDefinition , crate :: graphql :: definitions :: interface_type_definition :: FormatGraphqlInterfaceTypeDefinition > ; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: interface_type_definition :: FormatGraphqlInterfaceTypeDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlInterfaceTypeDefinition { + type Format = FormatOwnedWithRule < biome_graphql_syntax :: GraphqlInterfaceTypeDefinition , crate :: graphql :: definitions :: interface_type_definition :: FormatGraphqlInterfaceTypeDefinition > ; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: interface_type_definition :: FormatGraphqlInterfaceTypeDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::extensions::interface_type_extension::FormatGraphqlInterfaceTypeExtension +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlInterfaceTypeExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlInterfaceTypeExtension { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlInterfaceTypeExtension, + crate::graphql::extensions::interface_type_extension::FormatGraphqlInterfaceTypeExtension, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: extensions :: interface_type_extension :: FormatGraphqlInterfaceTypeExtension :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlInterfaceTypeExtension { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlInterfaceTypeExtension, + crate::graphql::extensions::interface_type_extension::FormatGraphqlInterfaceTypeExtension, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: extensions :: interface_type_extension :: FormatGraphqlInterfaceTypeExtension :: default ()) + } +} +impl FormatRule + for crate::graphql::auxiliary::list_type::FormatGraphqlListType +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlListType, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlListType { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlListType, + crate::graphql::auxiliary::list_type::FormatGraphqlListType, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::list_type::FormatGraphqlListType::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlListType { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlListType, + crate::graphql::auxiliary::list_type::FormatGraphqlListType, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::list_type::FormatGraphqlListType::default(), + ) + } +} +impl FormatRule + for crate::graphql::value::list_value::FormatGraphqlListValue +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlListValue, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlListValue { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlListValue, + crate::graphql::value::list_value::FormatGraphqlListValue, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::value::list_value::FormatGraphqlListValue::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlListValue { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlListValue, + crate::graphql::value::list_value::FormatGraphqlListValue, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::value::list_value::FormatGraphqlListValue::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::name::FormatGraphqlName +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlName, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlName { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlName, + crate::graphql::auxiliary::name::FormatGraphqlName, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::name::FormatGraphqlName::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlName { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlName, + crate::graphql::auxiliary::name::FormatGraphqlName, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::name::FormatGraphqlName::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::named_type::FormatGraphqlNamedType +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlNamedType, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlNamedType { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlNamedType, + crate::graphql::auxiliary::named_type::FormatGraphqlNamedType, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::named_type::FormatGraphqlNamedType::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlNamedType { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlNamedType, + crate::graphql::auxiliary::named_type::FormatGraphqlNamedType, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::named_type::FormatGraphqlNamedType::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::non_null_type::FormatGraphqlNonNullType +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlNonNullType, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlNonNullType { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlNonNullType, + crate::graphql::auxiliary::non_null_type::FormatGraphqlNonNullType, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::non_null_type::FormatGraphqlNonNullType::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlNonNullType { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlNonNullType, + crate::graphql::auxiliary::non_null_type::FormatGraphqlNonNullType, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::non_null_type::FormatGraphqlNonNullType::default(), + ) + } +} +impl FormatRule + for crate::graphql::value::null_value::FormatGraphqlNullValue +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlNullValue, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlNullValue { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlNullValue, + crate::graphql::value::null_value::FormatGraphqlNullValue, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::value::null_value::FormatGraphqlNullValue::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlNullValue { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlNullValue, + crate::graphql::value::null_value::FormatGraphqlNullValue, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::value::null_value::FormatGraphqlNullValue::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::object_field::FormatGraphqlObjectField +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlObjectField, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlObjectField { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlObjectField, + crate::graphql::auxiliary::object_field::FormatGraphqlObjectField, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::object_field::FormatGraphqlObjectField::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlObjectField { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlObjectField, + crate::graphql::auxiliary::object_field::FormatGraphqlObjectField, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::object_field::FormatGraphqlObjectField::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::object_type_definition::FormatGraphqlObjectTypeDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlObjectTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlObjectTypeDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlObjectTypeDefinition, + crate::graphql::definitions::object_type_definition::FormatGraphqlObjectTypeDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: object_type_definition :: FormatGraphqlObjectTypeDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlObjectTypeDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlObjectTypeDefinition, + crate::graphql::definitions::object_type_definition::FormatGraphqlObjectTypeDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: object_type_definition :: FormatGraphqlObjectTypeDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::extensions::object_type_extension::FormatGraphqlObjectTypeExtension +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlObjectTypeExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlObjectTypeExtension { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlObjectTypeExtension, + crate::graphql::extensions::object_type_extension::FormatGraphqlObjectTypeExtension, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: extensions :: object_type_extension :: FormatGraphqlObjectTypeExtension :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlObjectTypeExtension { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlObjectTypeExtension, + crate::graphql::extensions::object_type_extension::FormatGraphqlObjectTypeExtension, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: extensions :: object_type_extension :: FormatGraphqlObjectTypeExtension :: default ()) + } +} +impl FormatRule + for crate::graphql::value::object_value::FormatGraphqlObjectValue +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlObjectValue, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlObjectValue { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlObjectValue, + crate::graphql::value::object_value::FormatGraphqlObjectValue, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::value::object_value::FormatGraphqlObjectValue::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlObjectValue { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlObjectValue, + crate::graphql::value::object_value::FormatGraphqlObjectValue, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::value::object_value::FormatGraphqlObjectValue::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::operation_definition::FormatGraphqlOperationDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlOperationDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlOperationDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlOperationDefinition, + crate::graphql::definitions::operation_definition::FormatGraphqlOperationDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: operation_definition :: FormatGraphqlOperationDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlOperationDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlOperationDefinition, + crate::graphql::definitions::operation_definition::FormatGraphqlOperationDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: operation_definition :: FormatGraphqlOperationDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::auxiliary::operation_type::FormatGraphqlOperationType +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlOperationType, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlOperationType { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlOperationType, + crate::graphql::auxiliary::operation_type::FormatGraphqlOperationType, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::operation_type::FormatGraphqlOperationType::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlOperationType { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlOperationType, + crate::graphql::auxiliary::operation_type::FormatGraphqlOperationType, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::operation_type::FormatGraphqlOperationType::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::root::FormatGraphqlRoot +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlRoot, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlRoot { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlRoot, + crate::graphql::auxiliary::root::FormatGraphqlRoot, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::root::FormatGraphqlRoot::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlRoot { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlRoot, + crate::graphql::auxiliary::root::FormatGraphqlRoot, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::root::FormatGraphqlRoot::default(), + ) + } +} +impl FormatRule < biome_graphql_syntax :: GraphqlRootOperationTypeDefinition > for crate :: graphql :: definitions :: root_operation_type_definition :: FormatGraphqlRootOperationTypeDefinition { type Context = GraphqlFormatContext ; # [inline (always)] fn fmt (& self , node : & biome_graphql_syntax :: GraphqlRootOperationTypeDefinition , f : & mut GraphqlFormatter) -> FormatResult < () > { FormatNodeRule :: < biome_graphql_syntax :: GraphqlRootOperationTypeDefinition > :: fmt (self , node , f) } } +impl AsFormat for biome_graphql_syntax::GraphqlRootOperationTypeDefinition { + type Format < 'a > = FormatRefWithRule < 'a , biome_graphql_syntax :: GraphqlRootOperationTypeDefinition , crate :: graphql :: definitions :: root_operation_type_definition :: FormatGraphqlRootOperationTypeDefinition > ; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: root_operation_type_definition :: FormatGraphqlRootOperationTypeDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlRootOperationTypeDefinition { + type Format = FormatOwnedWithRule < biome_graphql_syntax :: GraphqlRootOperationTypeDefinition , crate :: graphql :: definitions :: root_operation_type_definition :: FormatGraphqlRootOperationTypeDefinition > ; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: root_operation_type_definition :: FormatGraphqlRootOperationTypeDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::auxiliary::root_operation_types::FormatGraphqlRootOperationTypes +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlRootOperationTypes, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlRootOperationTypes { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlRootOperationTypes, + crate::graphql::auxiliary::root_operation_types::FormatGraphqlRootOperationTypes, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: auxiliary :: root_operation_types :: FormatGraphqlRootOperationTypes :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlRootOperationTypes { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlRootOperationTypes, + crate::graphql::auxiliary::root_operation_types::FormatGraphqlRootOperationTypes, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: auxiliary :: root_operation_types :: FormatGraphqlRootOperationTypes :: default ()) + } +} +impl FormatRule + for crate::graphql::definitions::scalar_type_definition::FormatGraphqlScalarTypeDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlScalarTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlScalarTypeDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlScalarTypeDefinition, + crate::graphql::definitions::scalar_type_definition::FormatGraphqlScalarTypeDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: scalar_type_definition :: FormatGraphqlScalarTypeDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlScalarTypeDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlScalarTypeDefinition, + crate::graphql::definitions::scalar_type_definition::FormatGraphqlScalarTypeDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: scalar_type_definition :: FormatGraphqlScalarTypeDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::extensions::scalar_type_extension::FormatGraphqlScalarTypeExtension +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlScalarTypeExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlScalarTypeExtension { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlScalarTypeExtension, + crate::graphql::extensions::scalar_type_extension::FormatGraphqlScalarTypeExtension, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: extensions :: scalar_type_extension :: FormatGraphqlScalarTypeExtension :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlScalarTypeExtension { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlScalarTypeExtension, + crate::graphql::extensions::scalar_type_extension::FormatGraphqlScalarTypeExtension, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: extensions :: scalar_type_extension :: FormatGraphqlScalarTypeExtension :: default ()) + } +} +impl FormatRule + for crate::graphql::definitions::schema_definition::FormatGraphqlSchemaDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlSchemaDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlSchemaDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlSchemaDefinition, + crate::graphql::definitions::schema_definition::FormatGraphqlSchemaDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::definitions::schema_definition::FormatGraphqlSchemaDefinition::default( + ), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlSchemaDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlSchemaDefinition, + crate::graphql::definitions::schema_definition::FormatGraphqlSchemaDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::definitions::schema_definition::FormatGraphqlSchemaDefinition::default( + ), + ) + } +} +impl FormatRule + for crate::graphql::extensions::schema_extension::FormatGraphqlSchemaExtension +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlSchemaExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlSchemaExtension { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlSchemaExtension, + crate::graphql::extensions::schema_extension::FormatGraphqlSchemaExtension, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::extensions::schema_extension::FormatGraphqlSchemaExtension::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlSchemaExtension { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlSchemaExtension, + crate::graphql::extensions::schema_extension::FormatGraphqlSchemaExtension, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::extensions::schema_extension::FormatGraphqlSchemaExtension::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::selection_set::FormatGraphqlSelectionSet +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlSelectionSet, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlSelectionSet { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlSelectionSet, + crate::graphql::auxiliary::selection_set::FormatGraphqlSelectionSet, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::selection_set::FormatGraphqlSelectionSet::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlSelectionSet { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlSelectionSet, + crate::graphql::auxiliary::selection_set::FormatGraphqlSelectionSet, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::selection_set::FormatGraphqlSelectionSet::default(), + ) + } +} +impl FormatRule + for crate::graphql::value::string_value::FormatGraphqlStringValue +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlStringValue, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlStringValue { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlStringValue, + crate::graphql::value::string_value::FormatGraphqlStringValue, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::value::string_value::FormatGraphqlStringValue::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlStringValue { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlStringValue, + crate::graphql::value::string_value::FormatGraphqlStringValue, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::value::string_value::FormatGraphqlStringValue::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::type_condition::FormatGraphqlTypeCondition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlTypeCondition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlTypeCondition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlTypeCondition, + crate::graphql::auxiliary::type_condition::FormatGraphqlTypeCondition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::type_condition::FormatGraphqlTypeCondition::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlTypeCondition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlTypeCondition, + crate::graphql::auxiliary::type_condition::FormatGraphqlTypeCondition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::type_condition::FormatGraphqlTypeCondition::default(), + ) + } +} +impl FormatRule + for crate::graphql::auxiliary::union_member_types::FormatGraphqlUnionMemberTypes +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlUnionMemberTypes, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlUnionMemberTypes { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlUnionMemberTypes, + crate::graphql::auxiliary::union_member_types::FormatGraphqlUnionMemberTypes, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::union_member_types::FormatGraphqlUnionMemberTypes::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlUnionMemberTypes { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlUnionMemberTypes, + crate::graphql::auxiliary::union_member_types::FormatGraphqlUnionMemberTypes, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::union_member_types::FormatGraphqlUnionMemberTypes::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::union_type_definition::FormatGraphqlUnionTypeDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlUnionTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlUnionTypeDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlUnionTypeDefinition, + crate::graphql::definitions::union_type_definition::FormatGraphqlUnionTypeDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: union_type_definition :: FormatGraphqlUnionTypeDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlUnionTypeDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlUnionTypeDefinition, + crate::graphql::definitions::union_type_definition::FormatGraphqlUnionTypeDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: union_type_definition :: FormatGraphqlUnionTypeDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::extensions::union_type_extension::FormatGraphqlUnionTypeExtension +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlUnionTypeExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlUnionTypeExtension { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlUnionTypeExtension, + crate::graphql::extensions::union_type_extension::FormatGraphqlUnionTypeExtension, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: extensions :: union_type_extension :: FormatGraphqlUnionTypeExtension :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlUnionTypeExtension { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlUnionTypeExtension, + crate::graphql::extensions::union_type_extension::FormatGraphqlUnionTypeExtension, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: extensions :: union_type_extension :: FormatGraphqlUnionTypeExtension :: default ()) + } +} +impl FormatRule + for crate::graphql::auxiliary::variable::FormatGraphqlVariable +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlVariable, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlVariable { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlVariable, + crate::graphql::auxiliary::variable::FormatGraphqlVariable, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::auxiliary::variable::FormatGraphqlVariable::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlVariable { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlVariable, + crate::graphql::auxiliary::variable::FormatGraphqlVariable, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::auxiliary::variable::FormatGraphqlVariable::default(), + ) + } +} +impl FormatRule + for crate::graphql::definitions::variable_definition::FormatGraphqlVariableDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlVariableDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlVariableDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlVariableDefinition, + crate::graphql::definitions::variable_definition::FormatGraphqlVariableDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: definitions :: variable_definition :: FormatGraphqlVariableDefinition :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlVariableDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlVariableDefinition, + crate::graphql::definitions::variable_definition::FormatGraphqlVariableDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: definitions :: variable_definition :: FormatGraphqlVariableDefinition :: default ()) + } +} +impl FormatRule + for crate::graphql::auxiliary::variable_definitions::FormatGraphqlVariableDefinitions +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlVariableDefinitions, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlVariableDefinitions { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlVariableDefinitions, + crate::graphql::auxiliary::variable_definitions::FormatGraphqlVariableDefinitions, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: auxiliary :: variable_definitions :: FormatGraphqlVariableDefinitions :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlVariableDefinitions { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlVariableDefinitions, + crate::graphql::auxiliary::variable_definitions::FormatGraphqlVariableDefinitions, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: auxiliary :: variable_definitions :: FormatGraphqlVariableDefinitions :: default ()) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlArgumentDefinitionList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlArgumentDefinitionList, + crate::graphql::lists::argument_definition_list::FormatGraphqlArgumentDefinitionList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: lists :: argument_definition_list :: FormatGraphqlArgumentDefinitionList :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlArgumentDefinitionList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlArgumentDefinitionList, + crate::graphql::lists::argument_definition_list::FormatGraphqlArgumentDefinitionList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: lists :: argument_definition_list :: FormatGraphqlArgumentDefinitionList :: default ()) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlArgumentList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlArgumentList, + crate::graphql::lists::argument_list::FormatGraphqlArgumentList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::lists::argument_list::FormatGraphqlArgumentList::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlArgumentList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlArgumentList, + crate::graphql::lists::argument_list::FormatGraphqlArgumentList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::lists::argument_list::FormatGraphqlArgumentList::default(), + ) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlDefinitionList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlDefinitionList, + crate::graphql::lists::definition_list::FormatGraphqlDefinitionList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::lists::definition_list::FormatGraphqlDefinitionList::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlDefinitionList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlDefinitionList, + crate::graphql::lists::definition_list::FormatGraphqlDefinitionList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::lists::definition_list::FormatGraphqlDefinitionList::default(), + ) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlDirectiveList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlDirectiveList, + crate::graphql::lists::directive_list::FormatGraphqlDirectiveList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::lists::directive_list::FormatGraphqlDirectiveList::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlDirectiveList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlDirectiveList, + crate::graphql::lists::directive_list::FormatGraphqlDirectiveList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::lists::directive_list::FormatGraphqlDirectiveList::default(), + ) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlDirectiveLocationList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlDirectiveLocationList, + crate::graphql::lists::directive_location_list::FormatGraphqlDirectiveLocationList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: lists :: directive_location_list :: FormatGraphqlDirectiveLocationList :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlDirectiveLocationList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlDirectiveLocationList, + crate::graphql::lists::directive_location_list::FormatGraphqlDirectiveLocationList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: lists :: directive_location_list :: FormatGraphqlDirectiveLocationList :: default ()) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlEnumValueList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlEnumValueList, + crate::graphql::lists::enum_value_list::FormatGraphqlEnumValueList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::lists::enum_value_list::FormatGraphqlEnumValueList::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlEnumValueList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlEnumValueList, + crate::graphql::lists::enum_value_list::FormatGraphqlEnumValueList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::lists::enum_value_list::FormatGraphqlEnumValueList::default(), + ) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlFieldDefinitionList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlFieldDefinitionList, + crate::graphql::lists::field_definition_list::FormatGraphqlFieldDefinitionList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::lists::field_definition_list::FormatGraphqlFieldDefinitionList::default( + ), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlFieldDefinitionList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlFieldDefinitionList, + crate::graphql::lists::field_definition_list::FormatGraphqlFieldDefinitionList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::lists::field_definition_list::FormatGraphqlFieldDefinitionList::default( + ), + ) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlImplementsInterfaceList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlImplementsInterfaceList, + crate::graphql::lists::implements_interface_list::FormatGraphqlImplementsInterfaceList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: lists :: implements_interface_list :: FormatGraphqlImplementsInterfaceList :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlImplementsInterfaceList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlImplementsInterfaceList, + crate::graphql::lists::implements_interface_list::FormatGraphqlImplementsInterfaceList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: lists :: implements_interface_list :: FormatGraphqlImplementsInterfaceList :: default ()) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlInputFieldList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlInputFieldList, + crate::graphql::lists::input_field_list::FormatGraphqlInputFieldList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::lists::input_field_list::FormatGraphqlInputFieldList::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlInputFieldList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlInputFieldList, + crate::graphql::lists::input_field_list::FormatGraphqlInputFieldList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::lists::input_field_list::FormatGraphqlInputFieldList::default(), + ) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlListValueElementList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlListValueElementList, + crate::graphql::lists::list_value_element_list::FormatGraphqlListValueElementList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: lists :: list_value_element_list :: FormatGraphqlListValueElementList :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlListValueElementList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlListValueElementList, + crate::graphql::lists::list_value_element_list::FormatGraphqlListValueElementList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: lists :: list_value_element_list :: FormatGraphqlListValueElementList :: default ()) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlObjectValueMemberList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlObjectValueMemberList, + crate::graphql::lists::object_value_member_list::FormatGraphqlObjectValueMemberList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: lists :: object_value_member_list :: FormatGraphqlObjectValueMemberList :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlObjectValueMemberList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlObjectValueMemberList, + crate::graphql::lists::object_value_member_list::FormatGraphqlObjectValueMemberList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: lists :: object_value_member_list :: FormatGraphqlObjectValueMemberList :: default ()) + } +} +impl AsFormat + for biome_graphql_syntax::GraphqlRootOperationTypeDefinitionList +{ + type Format < 'a > = FormatRefWithRule < 'a , biome_graphql_syntax :: GraphqlRootOperationTypeDefinitionList , crate :: graphql :: lists :: root_operation_type_definition_list :: FormatGraphqlRootOperationTypeDefinitionList > ; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: lists :: root_operation_type_definition_list :: FormatGraphqlRootOperationTypeDefinitionList :: default ()) + } +} +impl IntoFormat + for biome_graphql_syntax::GraphqlRootOperationTypeDefinitionList +{ + type Format = FormatOwnedWithRule < biome_graphql_syntax :: GraphqlRootOperationTypeDefinitionList , crate :: graphql :: lists :: root_operation_type_definition_list :: FormatGraphqlRootOperationTypeDefinitionList > ; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: lists :: root_operation_type_definition_list :: FormatGraphqlRootOperationTypeDefinitionList :: default ()) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlSelectionList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlSelectionList, + crate::graphql::lists::selection_list::FormatGraphqlSelectionList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::lists::selection_list::FormatGraphqlSelectionList::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlSelectionList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlSelectionList, + crate::graphql::lists::selection_list::FormatGraphqlSelectionList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::lists::selection_list::FormatGraphqlSelectionList::default(), + ) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlUnionMemberTypeList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlUnionMemberTypeList, + crate::graphql::lists::union_member_type_list::FormatGraphqlUnionMemberTypeList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: lists :: union_member_type_list :: FormatGraphqlUnionMemberTypeList :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlUnionMemberTypeList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlUnionMemberTypeList, + crate::graphql::lists::union_member_type_list::FormatGraphqlUnionMemberTypeList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: lists :: union_member_type_list :: FormatGraphqlUnionMemberTypeList :: default ()) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlVariableDefinitionList { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlVariableDefinitionList, + crate::graphql::lists::variable_definition_list::FormatGraphqlVariableDefinitionList, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule :: new (self , crate :: graphql :: lists :: variable_definition_list :: FormatGraphqlVariableDefinitionList :: default ()) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlVariableDefinitionList { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlVariableDefinitionList, + crate::graphql::lists::variable_definition_list::FormatGraphqlVariableDefinitionList, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule :: new (self , crate :: graphql :: lists :: variable_definition_list :: FormatGraphqlVariableDefinitionList :: default ()) + } +} +impl FormatRule + for crate::graphql::bogus::bogus::FormatGraphqlBogus +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlBogus, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatBogusNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlBogus { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlBogus, + crate::graphql::bogus::bogus::FormatGraphqlBogus, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::bogus::bogus::FormatGraphqlBogus::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlBogus { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlBogus, + crate::graphql::bogus::bogus::FormatGraphqlBogus, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::bogus::bogus::FormatGraphqlBogus::default(), + ) + } +} +impl FormatRule + for crate::graphql::bogus::bogus_definition::FormatGraphqlBogusDefinition +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlBogusDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatBogusNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlBogusDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlBogusDefinition, + crate::graphql::bogus::bogus_definition::FormatGraphqlBogusDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::bogus::bogus_definition::FormatGraphqlBogusDefinition::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlBogusDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlBogusDefinition, + crate::graphql::bogus::bogus_definition::FormatGraphqlBogusDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::bogus::bogus_definition::FormatGraphqlBogusDefinition::default(), + ) + } +} +impl FormatRule + for crate::graphql::bogus::bogus_selection::FormatGraphqlBogusSelection +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlBogusSelection, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatBogusNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlBogusSelection { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlBogusSelection, + crate::graphql::bogus::bogus_selection::FormatGraphqlBogusSelection, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::bogus::bogus_selection::FormatGraphqlBogusSelection::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlBogusSelection { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlBogusSelection, + crate::graphql::bogus::bogus_selection::FormatGraphqlBogusSelection, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::bogus::bogus_selection::FormatGraphqlBogusSelection::default(), + ) + } +} +impl FormatRule + for crate::graphql::bogus::bogus_type::FormatGraphqlBogusType +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlBogusType, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatBogusNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlBogusType { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlBogusType, + crate::graphql::bogus::bogus_type::FormatGraphqlBogusType, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::bogus::bogus_type::FormatGraphqlBogusType::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlBogusType { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlBogusType, + crate::graphql::bogus::bogus_type::FormatGraphqlBogusType, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::bogus::bogus_type::FormatGraphqlBogusType::default(), + ) + } +} +impl FormatRule + for crate::graphql::bogus::bogus_value::FormatGraphqlBogusValue +{ + type Context = GraphqlFormatContext; + #[inline(always)] + fn fmt( + &self, + node: &biome_graphql_syntax::GraphqlBogusValue, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + FormatBogusNodeRule::::fmt(self, node, f) + } +} +impl AsFormat for biome_graphql_syntax::GraphqlBogusValue { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::GraphqlBogusValue, + crate::graphql::bogus::bogus_value::FormatGraphqlBogusValue, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::bogus::bogus_value::FormatGraphqlBogusValue::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::GraphqlBogusValue { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::GraphqlBogusValue, + crate::graphql::bogus::bogus_value::FormatGraphqlBogusValue, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::bogus::bogus_value::FormatGraphqlBogusValue::default(), + ) + } +} +impl AsFormat for biome_graphql_syntax::AnyGraphqlDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::AnyGraphqlDefinition, + crate::graphql::any::definition::FormatAnyGraphqlDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::any::definition::FormatAnyGraphqlDefinition::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::AnyGraphqlDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::AnyGraphqlDefinition, + crate::graphql::any::definition::FormatAnyGraphqlDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::any::definition::FormatAnyGraphqlDefinition::default(), + ) + } +} +impl AsFormat for biome_graphql_syntax::AnyGraphqlOperationDefinition { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::AnyGraphqlOperationDefinition, + crate::graphql::any::operation_definition::FormatAnyGraphqlOperationDefinition, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::any::operation_definition::FormatAnyGraphqlOperationDefinition::default( + ), + ) + } +} +impl IntoFormat for biome_graphql_syntax::AnyGraphqlOperationDefinition { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::AnyGraphqlOperationDefinition, + crate::graphql::any::operation_definition::FormatAnyGraphqlOperationDefinition, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::any::operation_definition::FormatAnyGraphqlOperationDefinition::default( + ), + ) + } +} +impl AsFormat for biome_graphql_syntax::AnyGraphqlPrimitiveType { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::AnyGraphqlPrimitiveType, + crate::graphql::any::primitive_type::FormatAnyGraphqlPrimitiveType, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::any::primitive_type::FormatAnyGraphqlPrimitiveType::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::AnyGraphqlPrimitiveType { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::AnyGraphqlPrimitiveType, + crate::graphql::any::primitive_type::FormatAnyGraphqlPrimitiveType, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::any::primitive_type::FormatAnyGraphqlPrimitiveType::default(), + ) + } +} +impl AsFormat for biome_graphql_syntax::AnyGraphqlSelection { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::AnyGraphqlSelection, + crate::graphql::any::selection::FormatAnyGraphqlSelection, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::any::selection::FormatAnyGraphqlSelection::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::AnyGraphqlSelection { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::AnyGraphqlSelection, + crate::graphql::any::selection::FormatAnyGraphqlSelection, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::any::selection::FormatAnyGraphqlSelection::default(), + ) + } +} +impl AsFormat for biome_graphql_syntax::AnyGraphqlType { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::AnyGraphqlType, + crate::graphql::any::ts_type::FormatAnyGraphqlType, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::any::ts_type::FormatAnyGraphqlType::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::AnyGraphqlType { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::AnyGraphqlType, + crate::graphql::any::ts_type::FormatAnyGraphqlType, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::any::ts_type::FormatAnyGraphqlType::default(), + ) + } +} +impl AsFormat for biome_graphql_syntax::AnyGraphqlValue { + type Format<'a> = FormatRefWithRule< + 'a, + biome_graphql_syntax::AnyGraphqlValue, + crate::graphql::any::value::FormatAnyGraphqlValue, + >; + fn format(&self) -> Self::Format<'_> { + #![allow(clippy::default_constructed_unit_structs)] + FormatRefWithRule::new( + self, + crate::graphql::any::value::FormatAnyGraphqlValue::default(), + ) + } +} +impl IntoFormat for biome_graphql_syntax::AnyGraphqlValue { + type Format = FormatOwnedWithRule< + biome_graphql_syntax::AnyGraphqlValue, + crate::graphql::any::value::FormatAnyGraphqlValue, + >; + fn into_format(self) -> Self::Format { + #![allow(clippy::default_constructed_unit_structs)] + FormatOwnedWithRule::new( + self, + crate::graphql::any::value::FormatAnyGraphqlValue::default(), + ) + } +} diff --git a/crates/biome_graphql_formatter/src/graphql/any/definition.rs b/crates/biome_graphql_formatter/src/graphql/any/definition.rs new file mode 100644 index 000000000000..afe18112b588 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/any/definition.rs @@ -0,0 +1,31 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_graphql_syntax::AnyGraphqlDefinition; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGraphqlDefinition; +impl FormatRule for FormatAnyGraphqlDefinition { + type Context = GraphqlFormatContext; + fn fmt(&self, node: &AnyGraphqlDefinition, f: &mut GraphqlFormatter) -> FormatResult<()> { + match node { + AnyGraphqlDefinition::AnyGraphqlOperationDefinition(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlBogusDefinition(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlDirectiveDefinition(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlEnumTypeDefinition(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlEnumTypeExtension(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlFragmentDefinition(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlInputObjectTypeDefinition(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlInputObjectTypeExtension(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlInterfaceTypeDefinition(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlInterfaceTypeExtension(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlObjectTypeDefinition(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlObjectTypeExtension(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlScalarTypeDefinition(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlScalarTypeExtension(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlSchemaDefinition(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlSchemaExtension(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlUnionTypeDefinition(node) => node.format().fmt(f), + AnyGraphqlDefinition::GraphqlUnionTypeExtension(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_graphql_formatter/src/graphql/any/mod.rs b/crates/biome_graphql_formatter/src/graphql/any/mod.rs new file mode 100644 index 000000000000..8091277781ff --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/any/mod.rs @@ -0,0 +1,8 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod definition; +pub(crate) mod operation_definition; +pub(crate) mod primitive_type; +pub(crate) mod selection; +pub(crate) mod ts_type; +pub(crate) mod value; diff --git a/crates/biome_graphql_formatter/src/graphql/any/operation_definition.rs b/crates/biome_graphql_formatter/src/graphql/any/operation_definition.rs new file mode 100644 index 000000000000..ef5de0525ec9 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/any/operation_definition.rs @@ -0,0 +1,19 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_graphql_syntax::AnyGraphqlOperationDefinition; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGraphqlOperationDefinition; +impl FormatRule for FormatAnyGraphqlOperationDefinition { + type Context = GraphqlFormatContext; + fn fmt( + &self, + node: &AnyGraphqlOperationDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + match node { + AnyGraphqlOperationDefinition::GraphqlOperationDefinition(node) => node.format().fmt(f), + AnyGraphqlOperationDefinition::GraphqlSelectionSet(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_graphql_formatter/src/graphql/any/primitive_type.rs b/crates/biome_graphql_formatter/src/graphql/any/primitive_type.rs new file mode 100644 index 000000000000..b3fe02ea20b4 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/any/primitive_type.rs @@ -0,0 +1,15 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_graphql_syntax::AnyGraphqlPrimitiveType; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGraphqlPrimitiveType; +impl FormatRule for FormatAnyGraphqlPrimitiveType { + type Context = GraphqlFormatContext; + fn fmt(&self, node: &AnyGraphqlPrimitiveType, f: &mut GraphqlFormatter) -> FormatResult<()> { + match node { + AnyGraphqlPrimitiveType::GraphqlListType(node) => node.format().fmt(f), + AnyGraphqlPrimitiveType::GraphqlNamedType(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_graphql_formatter/src/graphql/any/selection.rs b/crates/biome_graphql_formatter/src/graphql/any/selection.rs new file mode 100644 index 000000000000..cc1c8a5f5bbd --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/any/selection.rs @@ -0,0 +1,17 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_graphql_syntax::AnyGraphqlSelection; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGraphqlSelection; +impl FormatRule for FormatAnyGraphqlSelection { + type Context = GraphqlFormatContext; + fn fmt(&self, node: &AnyGraphqlSelection, f: &mut GraphqlFormatter) -> FormatResult<()> { + match node { + AnyGraphqlSelection::GraphqlBogusSelection(node) => node.format().fmt(f), + AnyGraphqlSelection::GraphqlField(node) => node.format().fmt(f), + AnyGraphqlSelection::GraphqlFragmentSpread(node) => node.format().fmt(f), + AnyGraphqlSelection::GraphqlInlineFragment(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_graphql_formatter/src/graphql/any/ts_type.rs b/crates/biome_graphql_formatter/src/graphql/any/ts_type.rs new file mode 100644 index 000000000000..52f213eaca1c --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/any/ts_type.rs @@ -0,0 +1,16 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_graphql_syntax::AnyGraphqlType; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGraphqlType; +impl FormatRule for FormatAnyGraphqlType { + type Context = GraphqlFormatContext; + fn fmt(&self, node: &AnyGraphqlType, f: &mut GraphqlFormatter) -> FormatResult<()> { + match node { + AnyGraphqlType::AnyGraphqlPrimitiveType(node) => node.format().fmt(f), + AnyGraphqlType::GraphqlBogusType(node) => node.format().fmt(f), + AnyGraphqlType::GraphqlNonNullType(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_graphql_formatter/src/graphql/any/value.rs b/crates/biome_graphql_formatter/src/graphql/any/value.rs new file mode 100644 index 000000000000..f4ec2bf3bb71 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/any/value.rs @@ -0,0 +1,23 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +use crate::prelude::*; +use biome_graphql_syntax::AnyGraphqlValue; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatAnyGraphqlValue; +impl FormatRule for FormatAnyGraphqlValue { + type Context = GraphqlFormatContext; + fn fmt(&self, node: &AnyGraphqlValue, f: &mut GraphqlFormatter) -> FormatResult<()> { + match node { + AnyGraphqlValue::GraphqlBogusValue(node) => node.format().fmt(f), + AnyGraphqlValue::GraphqlBooleanValue(node) => node.format().fmt(f), + AnyGraphqlValue::GraphqlEnumValue(node) => node.format().fmt(f), + AnyGraphqlValue::GraphqlFloatValue(node) => node.format().fmt(f), + AnyGraphqlValue::GraphqlIntValue(node) => node.format().fmt(f), + AnyGraphqlValue::GraphqlListValue(node) => node.format().fmt(f), + AnyGraphqlValue::GraphqlNullValue(node) => node.format().fmt(f), + AnyGraphqlValue::GraphqlObjectValue(node) => node.format().fmt(f), + AnyGraphqlValue::GraphqlStringValue(node) => node.format().fmt(f), + AnyGraphqlValue::GraphqlVariable(node) => node.format().fmt(f), + } + } +} diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/alias.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/alias.rs new file mode 100644 index 000000000000..56262c3904e1 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/alias.rs @@ -0,0 +1,12 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..96bc31689e6a --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/argument.rs @@ -0,0 +1,20 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..054a5c5c06ac --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/arguments.rs @@ -0,0 +1,24 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..8ce04cd712b4 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/description.rs @@ -0,0 +1,15 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..41029f0c4e75 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/directive.rs @@ -0,0 +1,17 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..160d3d5b86e1 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/directive_location.rs @@ -0,0 +1,17 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlDirectiveLocation, GraphqlDirectiveLocationFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlDirectiveLocation; +impl FormatNodeRule for FormatGraphqlDirectiveLocation { + fn fmt_fields( + &self, + node: &GraphqlDirectiveLocation, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..55924ef3c4ff --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/field.rs @@ -0,0 +1,33 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..40f5256f6d4c --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/fragment_spread.rs @@ -0,0 +1,24 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlFragmentSpread, GraphqlFragmentSpreadFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlFragmentSpread; +impl FormatNodeRule for FormatGraphqlFragmentSpread { + fn fmt_fields( + &self, + node: &GraphqlFragmentSpread, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..534abca6573b --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/implements_interfaces.rs @@ -0,0 +1,28 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlImplementsInterfaces, GraphqlImplementsInterfacesFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlImplementsInterfaces; +impl FormatNodeRule for FormatGraphqlImplementsInterfaces { + fn fmt_fields( + &self, + node: &GraphqlImplementsInterfaces, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..67c2df61706e --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/inline_fragment.rs @@ -0,0 +1,28 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlInlineFragment, GraphqlInlineFragmentFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlInlineFragment; +impl FormatNodeRule for FormatGraphqlInlineFragment { + fn fmt_fields( + &self, + node: &GraphqlInlineFragment, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..95e45d31c05f --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/list_type.rs @@ -0,0 +1,24 @@ +use crate::prelude::*; +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<()> { + 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/mod.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/mod.rs new file mode 100644 index 000000000000..7d676ff180a4 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/mod.rs @@ -0,0 +1,25 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod alias; +pub(crate) mod argument; +pub(crate) mod arguments; +pub(crate) mod description; +pub(crate) mod directive; +pub(crate) mod directive_location; +pub(crate) mod field; +pub(crate) mod fragment_spread; +pub(crate) mod implements_interfaces; +pub(crate) mod inline_fragment; +pub(crate) mod list_type; +pub(crate) mod name; +pub(crate) mod named_type; +pub(crate) mod non_null_type; +pub(crate) mod object_field; +pub(crate) mod operation_type; +pub(crate) mod root; +pub(crate) mod root_operation_types; +pub(crate) mod selection_set; +pub(crate) mod type_condition; +pub(crate) mod union_member_types; +pub(crate) mod variable; +pub(crate) mod variable_definitions; diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/name.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/name.rs new file mode 100644 index 000000000000..f217dbcca876 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/name.rs @@ -0,0 +1,13 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..a88658d49356 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/named_type.rs @@ -0,0 +1,13 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..9b52d7132b58 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/non_null_type.rs @@ -0,0 +1,12 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..cd16bacaf2cd --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/object_field.rs @@ -0,0 +1,20 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..4e2ec1b51364 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/operation_type.rs @@ -0,0 +1,17 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlOperationType, GraphqlOperationTypeFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlOperationType; +impl FormatNodeRule for FormatGraphqlOperationType { + fn fmt_fields( + &self, + node: &GraphqlOperationType, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + let GraphqlOperationTypeFields { value_token } = node.as_fields(); + + write![f, [value_token.format(),]] + } +} diff --git a/crates/biome_graphql_formatter/src/graphql/auxiliary/root.rs b/crates/biome_graphql_formatter/src/graphql/auxiliary/root.rs new file mode 100644 index 000000000000..bfb13dc2f8b7 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/root.rs @@ -0,0 +1,25 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlRoot, GraphqlRootFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlRoot; +impl FormatNodeRule for FormatGraphqlRoot { + fn fmt_fields(&self, node: &GraphqlRoot, f: &mut GraphqlFormatter) -> FormatResult<()> { + let GraphqlRootFields { + bom_token, + definitions, + eof_token, + } = node.as_fields(); + + write!( + f, + [ + bom_token.format(), + definitions.format(), + hard_line_break(), + format_removed(&eof_token?), + ] + ) + } +} 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 new file mode 100644 index 000000000000..9550eca48aa8 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/root_operation_types.rs @@ -0,0 +1,28 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlRootOperationTypes, GraphqlRootOperationTypesFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlRootOperationTypes; +impl FormatNodeRule for FormatGraphqlRootOperationTypes { + fn fmt_fields( + &self, + node: &GraphqlRootOperationTypes, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..038425cfc104 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/selection_set.rs @@ -0,0 +1,24 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..d61edd088760 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/type_condition.rs @@ -0,0 +1,16 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlTypeCondition, GraphqlTypeConditionFields}; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlTypeCondition; +impl FormatNodeRule for FormatGraphqlTypeCondition { + fn fmt_fields( + &self, + node: &GraphqlTypeCondition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..305af92cacff --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/union_member_types.rs @@ -0,0 +1,65 @@ +use crate::prelude::*; +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 { + fn fmt_fields( + &self, + node: &GraphqlUnionMemberTypes, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..f196332807da --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/variable.rs @@ -0,0 +1,13 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..a118db881e88 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/auxiliary/variable_definitions.rs @@ -0,0 +1,28 @@ +use crate::prelude::*; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlVariableDefinitions, GraphqlVariableDefinitionsFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlVariableDefinitions; +impl FormatNodeRule for FormatGraphqlVariableDefinitions { + fn fmt_fields( + &self, + node: &GraphqlVariableDefinitions, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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/bogus/bogus.rs b/crates/biome_graphql_formatter/src/graphql/bogus/bogus.rs new file mode 100644 index 000000000000..215f9abe91bc --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/bogus/bogus.rs @@ -0,0 +1,5 @@ +use crate::FormatBogusNodeRule; +use biome_graphql_syntax::GraphqlBogus; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlBogus; +impl FormatBogusNodeRule for FormatGraphqlBogus {} diff --git a/crates/biome_graphql_formatter/src/graphql/bogus/bogus_definition.rs b/crates/biome_graphql_formatter/src/graphql/bogus/bogus_definition.rs new file mode 100644 index 000000000000..08f9a9101eee --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/bogus/bogus_definition.rs @@ -0,0 +1,5 @@ +use crate::FormatBogusNodeRule; +use biome_graphql_syntax::GraphqlBogusDefinition; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlBogusDefinition; +impl FormatBogusNodeRule for FormatGraphqlBogusDefinition {} diff --git a/crates/biome_graphql_formatter/src/graphql/bogus/bogus_selection.rs b/crates/biome_graphql_formatter/src/graphql/bogus/bogus_selection.rs new file mode 100644 index 000000000000..974c1b00c741 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/bogus/bogus_selection.rs @@ -0,0 +1,5 @@ +use crate::FormatBogusNodeRule; +use biome_graphql_syntax::GraphqlBogusSelection; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlBogusSelection; +impl FormatBogusNodeRule for FormatGraphqlBogusSelection {} diff --git a/crates/biome_graphql_formatter/src/graphql/bogus/bogus_type.rs b/crates/biome_graphql_formatter/src/graphql/bogus/bogus_type.rs new file mode 100644 index 000000000000..d9bbb0da2d5c --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/bogus/bogus_type.rs @@ -0,0 +1,5 @@ +use crate::FormatBogusNodeRule; +use biome_graphql_syntax::GraphqlBogusType; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlBogusType; +impl FormatBogusNodeRule for FormatGraphqlBogusType {} diff --git a/crates/biome_graphql_formatter/src/graphql/bogus/bogus_value.rs b/crates/biome_graphql_formatter/src/graphql/bogus/bogus_value.rs new file mode 100644 index 000000000000..1562c902fc05 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/bogus/bogus_value.rs @@ -0,0 +1,5 @@ +use crate::FormatBogusNodeRule; +use biome_graphql_syntax::GraphqlBogusValue; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlBogusValue; +impl FormatBogusNodeRule for FormatGraphqlBogusValue {} diff --git a/crates/biome_graphql_formatter/src/graphql/bogus/mod.rs b/crates/biome_graphql_formatter/src/graphql/bogus/mod.rs new file mode 100644 index 000000000000..a8b36e499a79 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/bogus/mod.rs @@ -0,0 +1,8 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +#[allow(clippy::module_inception)] +pub(crate) mod bogus; +pub(crate) mod bogus_definition; +pub(crate) mod bogus_selection; +pub(crate) mod bogus_type; +pub(crate) mod bogus_value; diff --git a/crates/biome_graphql_formatter/src/graphql/definitions/arguments_definition.rs b/crates/biome_graphql_formatter/src/graphql/definitions/arguments_definition.rs new file mode 100644 index 000000000000..3e72801709c7 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/arguments_definition.rs @@ -0,0 +1,28 @@ +use crate::prelude::*; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlArgumentsDefinition, GraphqlArgumentsDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlArgumentsDefinition; +impl FormatNodeRule for FormatGraphqlArgumentsDefinition { + fn fmt_fields( + &self, + node: &GraphqlArgumentsDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..6c91e388fd99 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/directive_definition.rs @@ -0,0 +1,50 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlDirectiveDefinition, GraphqlDirectiveDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlDirectiveDefinition; +impl FormatNodeRule for FormatGraphqlDirectiveDefinition { + fn fmt_fields( + &self, + node: &GraphqlDirectiveDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..f335573b44ae --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/enum_type_definition.rs @@ -0,0 +1,37 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlEnumTypeDefinition, GraphqlEnumTypeDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlEnumTypeDefinition; +impl FormatNodeRule for FormatGraphqlEnumTypeDefinition { + fn fmt_fields( + &self, + node: &GraphqlEnumTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..d6580d7e6c81 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/enum_value_definition.rs @@ -0,0 +1,25 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlEnumValueDefinition, GraphqlEnumValueDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlEnumValueDefinition; +impl FormatNodeRule for FormatGraphqlEnumValueDefinition { + fn fmt_fields( + &self, + node: &GraphqlEnumValueDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..74b5a93b3174 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/enum_values_definition.rs @@ -0,0 +1,28 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlEnumValuesDefinition, GraphqlEnumValuesDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlEnumValuesDefinition; +impl FormatNodeRule for FormatGraphqlEnumValuesDefinition { + fn fmt_fields( + &self, + node: &GraphqlEnumValuesDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..fe0a9041c421 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/field_definition.rs @@ -0,0 +1,38 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlFieldDefinition, GraphqlFieldDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlFieldDefinition; +impl FormatNodeRule for FormatGraphqlFieldDefinition { + fn fmt_fields( + &self, + node: &GraphqlFieldDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..5718b9a24969 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/fields_definition.rs @@ -0,0 +1,28 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlFieldsDefinition, GraphqlFieldsDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlFieldsDefinition; +impl FormatNodeRule for FormatGraphqlFieldsDefinition { + fn fmt_fields( + &self, + node: &GraphqlFieldsDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..f214469c90db --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/fragment_definition.rs @@ -0,0 +1,35 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlFragmentDefinition, GraphqlFragmentDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlFragmentDefinition; +impl FormatNodeRule for FormatGraphqlFragmentDefinition { + fn fmt_fields( + &self, + node: &GraphqlFragmentDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..22a75b68b8d6 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/input_fields_definition.rs @@ -0,0 +1,28 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlInputFieldsDefinition, GraphqlInputFieldsDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlInputFieldsDefinition; +impl FormatNodeRule for FormatGraphqlInputFieldsDefinition { + fn fmt_fields( + &self, + node: &GraphqlInputFieldsDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..13d68e4432bd --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/input_object_type_definition.rs @@ -0,0 +1,37 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{ + GraphqlInputObjectTypeDefinition, GraphqlInputObjectTypeDefinitionFields, +}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlInputObjectTypeDefinition; +impl FormatNodeRule for FormatGraphqlInputObjectTypeDefinition { + fn fmt_fields( + &self, + node: &GraphqlInputObjectTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..4beea9c7cfc4 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/input_value_definition.rs @@ -0,0 +1,36 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlInputValueDefinition, GraphqlInputValueDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlInputValueDefinition; +impl FormatNodeRule for FormatGraphqlInputValueDefinition { + fn fmt_fields( + &self, + node: &GraphqlInputValueDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..c81a23955319 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/interface_type_definition.rs @@ -0,0 +1,40 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlInterfaceTypeDefinition, GraphqlInterfaceTypeDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlInterfaceTypeDefinition; +impl FormatNodeRule for FormatGraphqlInterfaceTypeDefinition { + fn fmt_fields( + &self, + node: &GraphqlInterfaceTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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/mod.rs b/crates/biome_graphql_formatter/src/graphql/definitions/mod.rs new file mode 100644 index 000000000000..e360344d5666 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/mod.rs @@ -0,0 +1,21 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod arguments_definition; +pub(crate) mod directive_definition; +pub(crate) mod enum_type_definition; +pub(crate) mod enum_value_definition; +pub(crate) mod enum_values_definition; +pub(crate) mod field_definition; +pub(crate) mod fields_definition; +pub(crate) mod fragment_definition; +pub(crate) mod input_fields_definition; +pub(crate) mod input_object_type_definition; +pub(crate) mod input_value_definition; +pub(crate) mod interface_type_definition; +pub(crate) mod object_type_definition; +pub(crate) mod operation_definition; +pub(crate) mod root_operation_type_definition; +pub(crate) mod scalar_type_definition; +pub(crate) mod schema_definition; +pub(crate) mod union_type_definition; +pub(crate) mod variable_definition; 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 new file mode 100644 index 000000000000..5fb802a89394 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/object_type_definition.rs @@ -0,0 +1,38 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlObjectTypeDefinition, GraphqlObjectTypeDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlObjectTypeDefinition; +impl FormatNodeRule for FormatGraphqlObjectTypeDefinition { + fn fmt_fields( + &self, + node: &GraphqlObjectTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..dee658fa3f4f --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/operation_definition.rs @@ -0,0 +1,41 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlOperationDefinition, GraphqlOperationDefinitionFields}; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlOperationDefinition; +impl FormatNodeRule for FormatGraphqlOperationDefinition { + fn fmt_fields( + &self, + node: &GraphqlOperationDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..0d0d1b97550d --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/root_operation_type_definition.rs @@ -0,0 +1,33 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{ + GraphqlRootOperationTypeDefinition, GraphqlRootOperationTypeDefinitionFields, +}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlRootOperationTypeDefinition; +impl FormatNodeRule + for FormatGraphqlRootOperationTypeDefinition +{ + fn fmt_fields( + &self, + node: &GraphqlRootOperationTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..c78cfe4350ec --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/scalar_type_definition.rs @@ -0,0 +1,34 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlScalarTypeDefinition, GraphqlScalarTypeDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlScalarTypeDefinition; +impl FormatNodeRule for FormatGraphqlScalarTypeDefinition { + fn fmt_fields( + &self, + node: &GraphqlScalarTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..d4791d292082 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/schema_definition.rs @@ -0,0 +1,34 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlSchemaDefinition, GraphqlSchemaDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlSchemaDefinition; +impl FormatNodeRule for FormatGraphqlSchemaDefinition { + fn fmt_fields( + &self, + node: &GraphqlSchemaDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..016f9a536ab5 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/union_type_definition.rs @@ -0,0 +1,40 @@ +use crate::prelude::*; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlUnionTypeDefinition, GraphqlUnionTypeDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlUnionTypeDefinition; +impl FormatNodeRule for FormatGraphqlUnionTypeDefinition { + fn fmt_fields( + &self, + node: &GraphqlUnionTypeDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..0cc34f8b6498 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/definitions/variable_definition.rs @@ -0,0 +1,33 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlVariableDefinition, GraphqlVariableDefinitionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlVariableDefinition; +impl FormatNodeRule for FormatGraphqlVariableDefinition { + fn fmt_fields( + &self, + node: &GraphqlVariableDefinition, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..ad44ad67349d --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/extensions/enum_type_extension.rs @@ -0,0 +1,35 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlEnumTypeExtension, GraphqlEnumTypeExtensionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlEnumTypeExtension; +impl FormatNodeRule for FormatGraphqlEnumTypeExtension { + fn fmt_fields( + &self, + node: &GraphqlEnumTypeExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..37acc13f73fa --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/extensions/input_object_type_extension.rs @@ -0,0 +1,37 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{ + GraphqlInputObjectTypeExtension, GraphqlInputObjectTypeExtensionFields, +}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlInputObjectTypeExtension; +impl FormatNodeRule for FormatGraphqlInputObjectTypeExtension { + fn fmt_fields( + &self, + node: &GraphqlInputObjectTypeExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..e01e18d94a27 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/extensions/interface_type_extension.rs @@ -0,0 +1,45 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlInterfaceTypeExtension, GraphqlInterfaceTypeExtensionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlInterfaceTypeExtension; +impl FormatNodeRule for FormatGraphqlInterfaceTypeExtension { + fn fmt_fields( + &self, + node: &GraphqlInterfaceTypeExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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/mod.rs b/crates/biome_graphql_formatter/src/graphql/extensions/mod.rs new file mode 100644 index 000000000000..eecbac14164b --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/extensions/mod.rs @@ -0,0 +1,9 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod enum_type_extension; +pub(crate) mod input_object_type_extension; +pub(crate) mod interface_type_extension; +pub(crate) mod object_type_extension; +pub(crate) mod scalar_type_extension; +pub(crate) mod schema_extension; +pub(crate) mod union_type_extension; 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 new file mode 100644 index 000000000000..0545520f9c90 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/extensions/object_type_extension.rs @@ -0,0 +1,45 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlObjectTypeExtension, GraphqlObjectTypeExtensionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlObjectTypeExtension; +impl FormatNodeRule for FormatGraphqlObjectTypeExtension { + fn fmt_fields( + &self, + node: &GraphqlObjectTypeExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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(), + ] + ]?; + + 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/scalar_type_extension.rs b/crates/biome_graphql_formatter/src/graphql/extensions/scalar_type_extension.rs new file mode 100644 index 000000000000..4adcb63b3b64 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/extensions/scalar_type_extension.rs @@ -0,0 +1,32 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlScalarTypeExtension, GraphqlScalarTypeExtensionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlScalarTypeExtension; +impl FormatNodeRule for FormatGraphqlScalarTypeExtension { + fn fmt_fields( + &self, + node: &GraphqlScalarTypeExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..92b0947a4585 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/extensions/schema_extension.rs @@ -0,0 +1,36 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::{GraphqlSchemaExtension, GraphqlSchemaExtensionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlSchemaExtension; +impl FormatNodeRule for FormatGraphqlSchemaExtension { + fn fmt_fields( + &self, + node: &GraphqlSchemaExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..1bdfa42eaea7 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/extensions/union_type_extension.rs @@ -0,0 +1,34 @@ +use crate::prelude::*; +use biome_formatter::{format_args, write}; +use biome_graphql_syntax::{GraphqlUnionTypeExtension, GraphqlUnionTypeExtensionFields}; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlUnionTypeExtension; +impl FormatNodeRule for FormatGraphqlUnionTypeExtension { + fn fmt_fields( + &self, + node: &GraphqlUnionTypeExtension, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..4f3b68372355 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/argument_definition_list.rs @@ -0,0 +1,34 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::GraphqlArgumentDefinitionList; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlArgumentDefinitionList; +impl FormatRule for FormatGraphqlArgumentDefinitionList { + type Context = GraphqlFormatContext; + fn fmt( + &self, + node: &GraphqlArgumentDefinitionList, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..0b8f4a53833a --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/argument_list.rs @@ -0,0 +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<()> { + 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 new file mode 100644 index 000000000000..939893841700 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/definition_list.rs @@ -0,0 +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<()> { + 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 new file mode 100644 index 000000000000..8fc894acb8dc --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/directive_list.rs @@ -0,0 +1,36 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..374ed863294e --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/directive_location_list.rs @@ -0,0 +1,31 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::GraphqlDirectiveLocationList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlDirectiveLocationList; +impl FormatRule for FormatGraphqlDirectiveLocationList { + type Context = GraphqlFormatContext; + fn fmt( + &self, + node: &GraphqlDirectiveLocationList, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..5dbaef3beb81 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/enum_value_list.rs @@ -0,0 +1,19 @@ +use crate::prelude::*; +use biome_graphql_syntax::GraphqlEnumValueList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlEnumValueList; +impl FormatRule for FormatGraphqlEnumValueList { + type Context = GraphqlFormatContext; + fn fmt(&self, node: &GraphqlEnumValueList, f: &mut GraphqlFormatter) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..c4b39845aa14 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/field_definition_list.rs @@ -0,0 +1,19 @@ +use crate::prelude::*; +use biome_graphql_syntax::GraphqlFieldDefinitionList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlFieldDefinitionList; +impl FormatRule for FormatGraphqlFieldDefinitionList { + type Context = GraphqlFormatContext; + fn fmt(&self, node: &GraphqlFieldDefinitionList, f: &mut GraphqlFormatter) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..fdb761da8a65 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/implements_interface_list.rs @@ -0,0 +1,32 @@ +use crate::prelude::*; +use biome_formatter::write; +use biome_graphql_syntax::GraphqlImplementsInterfaceList; + +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlImplementsInterfaceList; +impl FormatRule for FormatGraphqlImplementsInterfaceList { + type Context = GraphqlFormatContext; + fn fmt( + &self, + node: &GraphqlImplementsInterfaceList, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..030588effca1 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/input_field_list.rs @@ -0,0 +1,19 @@ +use crate::prelude::*; +use biome_graphql_syntax::GraphqlInputFieldList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlInputFieldList; +impl FormatRule for FormatGraphqlInputFieldList { + type Context = GraphqlFormatContext; + fn fmt(&self, node: &GraphqlInputFieldList, f: &mut GraphqlFormatter) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..8b755bf70ed1 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/list_value_element_list.rs @@ -0,0 +1,21 @@ +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 { + type Context = GraphqlFormatContext; + fn fmt( + &self, + node: &GraphqlListValueElementList, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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/mod.rs b/crates/biome_graphql_formatter/src/graphql/lists/mod.rs new file mode 100644 index 000000000000..1f80b836a7e2 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/mod.rs @@ -0,0 +1,17 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod argument_definition_list; +pub(crate) mod argument_list; +pub(crate) mod definition_list; +pub(crate) mod directive_list; +pub(crate) mod directive_location_list; +pub(crate) mod enum_value_list; +pub(crate) mod field_definition_list; +pub(crate) mod implements_interface_list; +pub(crate) mod input_field_list; +pub(crate) mod list_value_element_list; +pub(crate) mod object_value_member_list; +pub(crate) mod root_operation_type_definition_list; +pub(crate) mod selection_list; +pub(crate) mod union_member_type_list; +pub(crate) mod variable_definition_list; 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 new file mode 100644 index 000000000000..65cd07862589 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/object_value_member_list.rs @@ -0,0 +1,21 @@ +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 { + type Context = GraphqlFormatContext; + fn fmt( + &self, + node: &GraphqlObjectValueMemberList, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..adb39694f2d9 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/root_operation_type_definition_list.rs @@ -0,0 +1,25 @@ +use crate::prelude::*; +use biome_graphql_syntax::GraphqlRootOperationTypeDefinitionList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlRootOperationTypeDefinitionList; +impl FormatRule + for FormatGraphqlRootOperationTypeDefinitionList +{ + type Context = GraphqlFormatContext; + fn fmt( + &self, + node: &GraphqlRootOperationTypeDefinitionList, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..c88e27036b97 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/selection_list.rs @@ -0,0 +1,19 @@ +use crate::prelude::*; +use biome_graphql_syntax::GraphqlSelectionList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlSelectionList; +impl FormatRule for FormatGraphqlSelectionList { + type Context = GraphqlFormatContext; + fn fmt(&self, node: &GraphqlSelectionList, f: &mut GraphqlFormatter) -> FormatResult<()> { + 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 new file mode 100644 index 000000000000..826bf48f96b9 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/union_member_type_list.rs @@ -0,0 +1,48 @@ +use crate::prelude::*; +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 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()])?; + + if let Some(token) = separator { + if self.last { + write!(f, [format_removed(token)])?; + } else { + write![f, [soft_line_break_or_space(), token.format()]]?; + } + } + + 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 new file mode 100644 index 000000000000..11feccd7a1e2 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/lists/variable_definition_list.rs @@ -0,0 +1,20 @@ +use crate::prelude::*; +use biome_formatter::format_args; +use biome_graphql_syntax::GraphqlVariableDefinitionList; +#[derive(Debug, Clone, Default)] +pub(crate) struct FormatGraphqlVariableDefinitionList; +impl FormatRule for FormatGraphqlVariableDefinitionList { + type Context = GraphqlFormatContext; + fn fmt( + &self, + node: &GraphqlVariableDefinitionList, + f: &mut GraphqlFormatter, + ) -> FormatResult<()> { + 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/mod.rs b/crates/biome_graphql_formatter/src/graphql/mod.rs new file mode 100644 index 000000000000..637e01086af5 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/mod.rs @@ -0,0 +1,9 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod any; +pub(crate) mod auxiliary; +pub(crate) mod bogus; +pub(crate) mod definitions; +pub(crate) mod extensions; +pub(crate) mod lists; +pub(crate) mod value; diff --git a/crates/biome_graphql_formatter/src/graphql/value/boolean_value.rs b/crates/biome_graphql_formatter/src/graphql/value/boolean_value.rs new file mode 100644 index 000000000000..fc1791d9018d --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/value/boolean_value.rs @@ -0,0 +1,12 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..470fc4e1047d --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/value/default_value.rs @@ -0,0 +1,13 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..316ac2d56b1a --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/value/enum_value.rs @@ -0,0 +1,12 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..1f20194c08c8 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/value/float_value.rs @@ -0,0 +1,15 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..005dd58f4c0a --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/value/int_value.rs @@ -0,0 +1,15 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..474d87d12938 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/value/list_value.rs @@ -0,0 +1,24 @@ +use crate::prelude::*; +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<()> { + 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/mod.rs b/crates/biome_graphql_formatter/src/graphql/value/mod.rs new file mode 100644 index 000000000000..786e57cf9246 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/value/mod.rs @@ -0,0 +1,11 @@ +//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file. + +pub(crate) mod boolean_value; +pub(crate) mod default_value; +pub(crate) mod enum_value; +pub(crate) mod float_value; +pub(crate) mod int_value; +pub(crate) mod list_value; +pub(crate) mod null_value; +pub(crate) mod object_value; +pub(crate) mod string_value; diff --git a/crates/biome_graphql_formatter/src/graphql/value/null_value.rs b/crates/biome_graphql_formatter/src/graphql/value/null_value.rs new file mode 100644 index 000000000000..e830c3f60086 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/value/null_value.rs @@ -0,0 +1,13 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..fdb85bceb2f0 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/value/object_value.rs @@ -0,0 +1,24 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..1a357d286254 --- /dev/null +++ b/crates/biome_graphql_formatter/src/graphql/value/string_value.rs @@ -0,0 +1,14 @@ +use crate::prelude::*; +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<()> { + 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 new file mode 100644 index 000000000000..bc6d9577f41d --- /dev/null +++ b/crates/biome_graphql_formatter/src/lib.rs @@ -0,0 +1,339 @@ +mod comments; +pub mod context; +mod cst; +mod generated; +mod graphql; +mod prelude; + +use crate::comments::GraphqlCommentStyle; +pub(crate) use crate::context::GraphqlFormatContext; +use crate::context::GraphqlFormatOptions; +use crate::cst::FormatGraphqlSyntaxNode; +use biome_formatter::comments::Comments; +use biome_formatter::prelude::*; +use biome_formatter::{ + write, CstFormatContext, FormatContext, FormatLanguage, FormatOwnedWithRule, FormatRefWithRule, + FormatToken, TransformSourceMap, +}; +use biome_formatter::{Formatted, Printed}; +use biome_graphql_syntax::{GraphqlLanguage, GraphqlSyntaxNode, GraphqlSyntaxToken}; +use biome_rowan::{AstNode, SyntaxNode, TextRange}; + +/// Used to get an object that knows how to format this object. +pub(crate) trait AsFormat { + type Format<'a>: biome_formatter::Format + where + Self: 'a; + + /// Returns an object that is able to format this object. + fn format(&self) -> Self::Format<'_>; +} + +/// Implement [AsFormat] for references to types that implement [AsFormat]. +impl AsFormat for &T +where + T: AsFormat, +{ + type Format<'a> = T::Format<'a> where Self: 'a; + + fn format(&self) -> Self::Format<'_> { + AsFormat::format(&**self) + } +} + +/// Implement [AsFormat] for [SyntaxResult] where `T` implements [AsFormat]. +/// +/// Useful to format mandatory AST fields without having to unwrap the value first. +impl AsFormat for biome_rowan::SyntaxResult +where + T: AsFormat, +{ + type Format<'a> = biome_rowan::SyntaxResult> where Self: 'a; + + fn format(&self) -> Self::Format<'_> { + match self { + Ok(value) => Ok(value.format()), + Err(err) => Err(*err), + } + } +} + +/// Implement [AsFormat] for [Option] when `T` implements [AsFormat] +/// +/// Allows to call format on optional AST fields without having to unwrap the field first. +impl AsFormat for Option +where + T: AsFormat, +{ + type Format<'a> = Option> where Self: 'a; + + fn format(&self) -> Self::Format<'_> { + self.as_ref().map(|value| value.format()) + } +} + +/// Used to convert this object into an object that can be formatted. +/// +/// The difference to [AsFormat] is that this trait takes ownership of `self`. +pub(crate) trait IntoFormat { + type Format: biome_formatter::Format; + + fn into_format(self) -> Self::Format; +} + +impl IntoFormat for biome_rowan::SyntaxResult +where + T: IntoFormat, +{ + type Format = biome_rowan::SyntaxResult; + + fn into_format(self) -> Self::Format { + self.map(IntoFormat::into_format) + } +} + +/// Implement [IntoFormat] for [Option] when `T` implements [IntoFormat] +/// +/// Allows to call format on optional AST fields without having to unwrap the field first. +impl IntoFormat for Option +where + T: IntoFormat, +{ + type Format = Option; + + fn into_format(self) -> Self::Format { + self.map(IntoFormat::into_format) + } +} + +/// Formatting specific [Iterator] extensions +pub(crate) trait FormattedIterExt { + /// Converts every item to an object that knows how to format it. + fn formatted(self) -> FormattedIter + where + Self: Iterator + Sized, + Self::Item: IntoFormat, + { + FormattedIter { + inner: self, + options: std::marker::PhantomData, + } + } +} + +impl FormattedIterExt for I where I: std::iter::Iterator {} + +pub(crate) struct FormattedIter +where + Iter: Iterator, +{ + inner: Iter, + options: std::marker::PhantomData, +} + +impl std::iter::Iterator for FormattedIter +where + Iter: Iterator, + Item: IntoFormat, +{ + type Item = Item::Format; + + fn next(&mut self) -> Option { + Some(self.inner.next()?.into_format()) + } +} + +impl std::iter::FusedIterator for FormattedIter +where + Iter: std::iter::FusedIterator, + Item: IntoFormat, +{ +} + +impl std::iter::ExactSizeIterator for FormattedIter +where + Iter: Iterator + std::iter::ExactSizeIterator, + Item: IntoFormat, +{ +} + +pub(crate) type GraphqlFormatter<'buf> = Formatter<'buf, GraphqlFormatContext>; + +/// Format a [GraphqlSyntaxNode] +pub(crate) trait FormatNodeRule +where + N: AstNode, +{ + fn fmt(&self, node: &N, f: &mut GraphqlFormatter) -> FormatResult<()> { + if self.is_suppressed(node, f) { + return write!(f, [format_suppressed_node(node.syntax())]); + } + + self.fmt_leading_comments(node, f)?; + self.fmt_fields(node, f)?; + self.fmt_dangling_comments(node, f)?; + self.fmt_trailing_comments(node, f) + } + + fn fmt_fields(&self, node: &N, f: &mut GraphqlFormatter) -> FormatResult<()>; + + /// Returns `true` if the node has a suppression comment and should use the same formatting as in the source document. + fn is_suppressed(&self, node: &N, f: &GraphqlFormatter) -> bool { + f.context().comments().is_suppressed(node.syntax()) + } + + /// Formats the [leading comments](biome_formatter::comments#leading-comments) of the node. + /// + /// You may want to override this method if you want to manually handle the formatting of comments + /// inside of the `fmt_fields` method or customize the formatting of the leading comments. + fn fmt_leading_comments(&self, node: &N, f: &mut GraphqlFormatter) -> FormatResult<()> { + format_leading_comments(node.syntax()).fmt(f) + } + + /// Formats the [dangling comments](biome_formatter::comments#dangling-comments) of the node. + /// + /// You should override this method if the node handled by this rule can have dangling comments because the + /// default implementation formats the dangling comments at the end of the node, which isn't ideal but ensures that + /// no comments are dropped. + /// + /// A node can have dangling comments if all its children are tokens or if all node childrens are optional. + fn fmt_dangling_comments(&self, node: &N, f: &mut GraphqlFormatter) -> FormatResult<()> { + format_dangling_comments(node.syntax()) + .with_soft_block_indent() + .fmt(f) + } + + /// Formats the [trailing comments](biome_formatter::comments#trailing-comments) of the node. + /// + /// You may want to override this method if you want to manually handle the formatting of comments + /// inside of the `fmt_fields` method or customize the formatting of the trailing comments. + fn fmt_trailing_comments(&self, node: &N, f: &mut GraphqlFormatter) -> FormatResult<()> { + format_trailing_comments(node.syntax()).fmt(f) + } +} + +/// Rule for formatting an bogus nodes. +pub(crate) trait FormatBogusNodeRule +where + N: AstNode, +{ + fn fmt(&self, node: &N, f: &mut GraphqlFormatter) -> FormatResult<()> { + format_bogus_node(node.syntax()).fmt(f) + } +} + +/// Format implementation specific to Graphql tokens. +pub(crate) type FormatGraphqlSyntaxToken = FormatToken; + +impl AsFormat for GraphqlSyntaxToken { + type Format<'a> = FormatRefWithRule<'a, GraphqlSyntaxToken, FormatGraphqlSyntaxToken>; + + fn format(&self) -> Self::Format<'_> { + FormatRefWithRule::new(self, FormatGraphqlSyntaxToken::default()) + } +} + +impl IntoFormat for GraphqlSyntaxToken { + type Format = FormatOwnedWithRule; + + fn into_format(self) -> Self::Format { + FormatOwnedWithRule::new(self, FormatGraphqlSyntaxToken::default()) + } +} + +#[derive(Debug, Default, Clone)] +pub struct GraphqlFormatLanguage { + options: GraphqlFormatOptions, +} + +impl GraphqlFormatLanguage { + pub fn new(options: GraphqlFormatOptions) -> Self { + Self { options } + } +} + +impl FormatLanguage for GraphqlFormatLanguage { + type SyntaxLanguage = GraphqlLanguage; + type Context = GraphqlFormatContext; + type FormatRule = FormatGraphqlSyntaxNode; + + fn is_range_formatting_node(&self, _node: &SyntaxNode) -> bool { + // TODO implement range formatting + true + } + + fn options(&self) -> &::Options { + &self.options + } + + fn create_context( + self, + root: &GraphqlSyntaxNode, + source_map: Option, + ) -> Self::Context { + let comments = Comments::from_node(root, &GraphqlCommentStyle, source_map.as_ref()); + GraphqlFormatContext::new(self.options, comments).with_source_map(source_map) + } +} + +/// Formats a range within a file, supported by Biome +/// +/// This runs a simple heuristic to determine the initial indentation +/// level of the node based on the provided [GraphqlFormatOptions], which +/// must match currently the current initial of the file. Additionally, +/// because the reformatting happens only locally the resulting code +/// will be indented with the same level as the original selection, +/// even if it's a mismatch from the rest of the block the selection is in +/// +/// It returns a [Printed] result with a range corresponding to the +/// range of the input that was effectively overwritten by the formatter +pub fn format_range( + options: GraphqlFormatOptions, + root: &GraphqlSyntaxNode, + range: TextRange, +) -> FormatResult { + biome_formatter::format_range(root, range, GraphqlFormatLanguage::new(options)) +} + +/// Formats a Graphql syntax tree. +/// +/// It returns the [Formatted] document that can be printed to a string. +pub fn format_node( + options: GraphqlFormatOptions, + root: &GraphqlSyntaxNode, +) -> FormatResult> { + biome_formatter::format_node(root, GraphqlFormatLanguage::new(options)) +} + +/// Formats a single node within a file, supported by Biome. +/// +/// This runs a simple heuristic to determine the initial indentation +/// level of the node based on the provided [GraphqlFormatOptions], which +/// must match currently the current initial of the file. Additionally, +/// because the reformatting happens only locally the resulting code +/// will be indented with the same level as the original selection, +/// even if it's a mismatch from the rest of the block the selection is in +/// +/// Returns the [Printed] code. +pub fn format_sub_tree( + options: GraphqlFormatOptions, + root: &GraphqlSyntaxNode, +) -> FormatResult { + biome_formatter::format_sub_tree(root, GraphqlFormatLanguage::new(options)) +} + +#[cfg(test)] +mod tests { + use crate::context::GraphqlFormatOptions; + use crate::format_node; + use biome_graphql_parser::parse_graphql; + + #[test] + fn smoke_test() { + let src = r#"query {}"#; + let parse = parse_graphql(src); + let options = GraphqlFormatOptions::default(); + let formatted = format_node(options, &parse.syntax()).unwrap(); + assert_eq!(formatted.print().unwrap().as_code(), "query {}\n"); + } +} diff --git a/crates/biome_graphql_formatter/src/prelude.rs b/crates/biome_graphql_formatter/src/prelude.rs new file mode 100644 index 000000000000..cecf0bab06c7 --- /dev/null +++ b/crates/biome_graphql_formatter/src/prelude.rs @@ -0,0 +1,13 @@ +//! This module provides important and useful traits to help to format tokens and nodes +//! when implementing the [crate::FormatNodeRule] trait. + +#[allow(unused_imports)] +pub(crate) use crate::{ + AsFormat, FormatNodeRule, FormattedIterExt as _, GraphqlFormatContext, GraphqlFormatter, + IntoFormat, +}; +pub(crate) use biome_formatter::prelude::*; +#[allow(unused_imports)] +pub(crate) use biome_rowan::{ + AstNode as _, AstNodeList as _, AstNodeSlotMap as _, AstSeparatedList as _, +}; diff --git a/crates/biome_graphql_formatter/tests/language.rs b/crates/biome_graphql_formatter/tests/language.rs new file mode 100644 index 000000000000..c22918f81158 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/language.rs @@ -0,0 +1,54 @@ +use biome_formatter::{FormatResult, Formatted, Printed}; +use biome_formatter_test::TestFormatLanguage; +use biome_graphql_formatter::context::{GraphqlFormatContext, GraphqlFormatOptions}; +use biome_graphql_formatter::{format_node, format_range, GraphqlFormatLanguage}; +use biome_graphql_parser::parse_graphql; +use biome_graphql_syntax::{GraphqlFileSource, GraphqlLanguage}; +use biome_parser::AnyParse; +use biome_rowan::{SyntaxNode, TextRange}; +use biome_service::settings::{ServiceLanguage, Settings}; + +#[derive(Default)] +pub struct GraphqlTestFormatLanguage { + _source_type: GraphqlFileSource, +} + +impl TestFormatLanguage for GraphqlTestFormatLanguage { + type ServiceLanguage = GraphqlLanguage; + type Context = GraphqlFormatContext; + type FormatLanguage = GraphqlFormatLanguage; + + fn parse(&self, text: &str) -> AnyParse { + let parse = parse_graphql(text); + + AnyParse::new(parse.syntax().as_send().unwrap(), parse.into_diagnostics()) + } + + fn to_language_settings<'a>( + &self, + settings: &'a Settings, + ) -> &'a ::FormatterSettings { + &settings.languages.graphql.formatter + } + + fn format_node( + &self, + options: ::FormatOptions, + node: &SyntaxNode, + ) -> FormatResult> { + format_node(options, node) + } + + fn format_range( + &self, + options: ::FormatOptions, + node: &SyntaxNode, + range: TextRange, + ) -> FormatResult { + format_range(options, node, range) + } + + fn default_options(&self) -> ::FormatOptions { + GraphqlFormatOptions::default() + } +} diff --git a/crates/biome_graphql_formatter/tests/prettier_tests.rs b/crates/biome_graphql_formatter/tests/prettier_tests.rs new file mode 100644 index 000000000000..7bab51e87f49 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/prettier_tests.rs @@ -0,0 +1,28 @@ +use std::{env, path::Path}; + +use biome_formatter::{IndentStyle, IndentWidth}; +use biome_formatter_test::test_prettier_snapshot::{PrettierSnapshot, PrettierTestFile}; +use biome_graphql_formatter::context::GraphqlFormatOptions; + +mod language; + +tests_macros::gen_tests! {"tests/specs/prettier/{graphql}/**/*.{graphql}", crate::test_snapshot, ""} + +#[allow(dead_code)] +fn test_snapshot(input: &'static str, _: &str, _: &str, _: &str) { + countme::enable(true); + + let root_path = Path::new(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/specs/prettier/" + )); + + let test_file = PrettierTestFile::new(input, root_path); + let options = GraphqlFormatOptions::default() + .with_indent_style(IndentStyle::Space) + .with_indent_width(IndentWidth::default()); + let language = language::GraphqlTestFormatLanguage::default(); + let snapshot = PrettierSnapshot::new(test_file, language, options); + + snapshot.test() +} diff --git a/crates/biome_graphql_formatter/tests/quick_test.rs b/crates/biome_graphql_formatter/tests/quick_test.rs new file mode 100644 index 000000000000..ca77350018b8 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/quick_test.rs @@ -0,0 +1,56 @@ +use biome_formatter::{IndentStyle, LineWidth}; +use biome_formatter_test::check_reformat::CheckReformat; +use biome_graphql_formatter::context::GraphqlFormatOptions; +use biome_graphql_formatter::format_node; +use biome_graphql_parser::parse_graphql; + +mod language { + include!("language.rs"); +} + +#[ignore] +#[test] +// use this test check if your snippet prints as you wish, without using a snapshot +fn quick_test() { + let src = r#" +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 + +} + +"#; + let parse = parse_graphql(src); + println!("{:#?}", parse); + + let options = GraphqlFormatOptions::default() + .with_line_width(LineWidth::try_from(80).unwrap()) + .with_indent_style(IndentStyle::Space); + let doc = format_node(options.clone(), &parse.syntax()).unwrap(); + let result = doc.print().unwrap(); + + let root = &parse.syntax(); + let language = language::GraphqlTestFormatLanguage::default(); + + println!("{}", doc.into_document()); + eprintln!("{}", result.as_code()); + + CheckReformat::new(root, result.as_code(), "quick_test", &language, options).check_reformat(); +} diff --git a/crates/biome_graphql_formatter/tests/spec_test.rs b/crates/biome_graphql_formatter/tests/spec_test.rs new file mode 100644 index 000000000000..ed125c1b6a74 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/spec_test.rs @@ -0,0 +1,58 @@ +use biome_configuration::{ + PartialConfiguration, PartialGraphqlConfiguration, PartialGraphqlFormatter, +}; +use biome_formatter_test::spec::{SpecSnapshot, SpecTestFile}; +use biome_graphql_formatter::context::GraphqlFormatOptions; +use biome_service::workspace::UpdateSettingsParams; +use std::path::Path; + +mod language { + include!("language.rs"); +} + +/// [insta.rs](https://insta.rs/docs) snapshot testing +/// +/// For better development workflow, run +/// `cargo watch -i '*.new' -x 'test -p biome_graphql_formatter formatter'` +/// +/// To review and commit the snapshots, `cargo install cargo-insta`, and run +/// `cargo insta review` or `cargo insta accept` +/// +/// The input and the expected output are stored as dedicated files in the `tests/specs` directory where +/// the input file name is `{spec_name}.graphql` and the output file name is `{spec_name}.graphql.snap`. +/// +/// Specs can be grouped in directories by specifying the directory name in the spec name. Examples: +/// +/// # Examples +/// +/// * `graphql/null` -> input: `tests/specs/graphql/null.graphql`, expected output: `tests/specs/graphql/null.graphql.snap` +/// * `null` -> input: `tests/specs/null.graphql`, expected output: `tests/specs/null.graphql.snap` +pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, _file_type: &str) { + let root_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/specs/")); + let settings = UpdateSettingsParams { + configuration: PartialConfiguration { + graphql: Some(PartialGraphqlConfiguration { + formatter: Some(PartialGraphqlFormatter { + enabled: Some(true), + ..Default::default() + }), + }), + ..Default::default() + }, + vcs_base_path: None, + gitignore_matches: vec![], + workspace_directory: None, + }; + + let Some(test_file) = SpecTestFile::try_from_file(spec_input_file, root_path, Some(settings)) + else { + return; + }; + + let options = GraphqlFormatOptions::default(); + let language = language::GraphqlTestFormatLanguage::default(); + + let snapshot = SpecSnapshot::new(test_file, test_directory, language, options); + + snapshot.test() +} diff --git a/crates/biome_graphql_formatter/tests/spec_tests.rs b/crates/biome_graphql_formatter/tests/spec_tests.rs new file mode 100644 index 000000000000..7801e738c39f --- /dev/null +++ b/crates/biome_graphql_formatter/tests/spec_tests.rs @@ -0,0 +1,8 @@ +mod quick_test; +mod spec_test; + +mod formatter { + mod graphql_module { + tests_macros::gen_tests! {"tests/specs/graphql/**/*.graphql", crate::spec_test::run, ""} + } +} 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..27fa1cc09d63 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/definitions/object_extension.graphql.snap @@ -0,0 +1,81 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/definitions/object_extension.graphql +--- +# 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 +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```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 +} +``` 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 new file mode 100644 index 000000000000..7baea0ef0892 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/directive.graphql @@ -0,0 +1,58 @@ +{ + + + 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 new file mode 100644 index 000000000000..55c27d15f385 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/graphql/directive.graphql.snap @@ -0,0 +1,100 @@ +--- +source: crates/biome_formatter_test/src/snapshot_builder.rs +info: graphql/directive.graphql +--- +# Input + +```graphql +{ + + + hero + + + @deprecated + + +} + +{ + hero + + + @deprecated(reason: + + "Deprecated" + + ) + + +} + +{ + + hero + + @input + + (type: + + String) + + +} + +{ + hero + + + @deprecated( + + reason: + + "Deprecated" + + ) + @addExternalFields + + + (source: + + + "profiles" + + ) +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Indent width: 2 +Line ending: LF +Line width: 80 +Quote style: Double Quotes +----- + +```graphql +{ + 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/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/README.md b/crates/biome_graphql_formatter/tests/specs/prettier/README.md new file mode 100644 index 000000000000..be00b167af02 --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/README.md @@ -0,0 +1,32 @@ +# Prettier Test Suite + +These test snapshots were extracted from the +[prettier/prettier](https://github.com/prettier/prettier) repository + +# Usage + +These tests are run as part of the `biome_graphql_formatter` test suite but can be +explicitly called with `cargo test -p biome_graphql_formatter --test prettier_tests` + +Setting the `REPORT_PRETTIER=1` environment variable when running these tests +will emit a `report.md` file containing an exhaustive difference between the +output of `biome_graphql_formatter` and Prettier's own snapshots. +Setting the `REPORT_TYPE=json | markdown` environment variable will dictate the format of the report. +Setting the environment variable `INCOMPATIBLE_ONLY=1` will emit an `incompatible_report.md` +file containing only incompatible test cases. + + +# Updating + +Prettier is using Jest to run snapshot tests, and a node.js script is needed to +extract these snapshots into plain files for use in the Rust tests. To update +the snapshots: + +1. Clone the Prettier git repository locally +2. Remove all the directories inside + `crates/biome_graphql_formatter/tests/specs/prettier` to ensure all obsolete tests are + removed +3. Go to `crates/biome_formatter_test/src/prettier` directory +4. Install prettier ``pnpm install`` +5. Go to `crates/biome_graphql_formatter/tests/specs/prettier` directory +6. Run `node prepare_tests.js ` 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_formatter/tests/specs/prettier/prepare_tests.js b/crates/biome_graphql_formatter/tests/specs/prettier/prepare_tests.js new file mode 100644 index 000000000000..1df2ced0e1ea --- /dev/null +++ b/crates/biome_graphql_formatter/tests/specs/prettier/prepare_tests.js @@ -0,0 +1,12 @@ +const {extractPrettierTests} = require("../../../../biome_formatter_test/src/prettier/prepare_tests"); + +async function main() { + await extractPrettierTests("graphql", { + parser: "graphql", + }); +} + +main().catch((err) => { + console.error(err); + process.exit(1); +}); 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..b7990434da4d 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 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..8cfbde182780 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 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..8363404e42bb 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(" ")] 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 fa26d3df7750..d6a67acb7c11 100644 --- a/crates/biome_graphql_syntax/src/file_source.rs +++ b/crates/biome_graphql_syntax/src/file_source.rs @@ -6,9 +6,28 @@ use std::path::Path; #[derive( Debug, Clone, Default, Copy, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize, )] -pub struct GraphqlFileSource {} +pub struct GraphqlFileSource { + #[allow(unused)] + variant: GraphqlVariant, +} + +/// The style of GraphQL contained in the file. +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] +#[derive( + Debug, Clone, Default, Copy, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize, +)] +enum GraphqlVariant { + #[default] + Standard, +} impl GraphqlFileSource { + pub fn graphql() -> Self { + Self { + variant: GraphqlVariant::Standard, + } + } + /// Try to return the GraphQL file source corresponding to this file name from well-known files pub fn try_from_well_known(file_name: &str) -> Result { // TODO: to be implemented @@ -34,7 +53,7 @@ impl GraphqlFileSource { /// [VS Code spec]: https://code.visualstudio.com/docs/languages/identifiers pub fn try_from_language_id(language_id: &str) -> Result { match language_id { - "graphql" => Ok(Self::default()), + "graphql" | "gql" => Ok(Self::default()), _ => Err(FileSourceError::UnknownLanguageId(language_id.into())), } } 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); diff --git a/crates/biome_service/Cargo.toml b/crates/biome_service/Cargo.toml index a757499bc774..4ed5ded83270 100644 --- a/crates/biome_service/Cargo.toml +++ b/crates/biome_service/Cargo.toml @@ -28,6 +28,7 @@ biome_flags = { workspace = true } biome_formatter = { workspace = true, features = ["serde"] } biome_fs = { workspace = true, features = ["serde"] } biome_graphql_analyze = { workspace = true } +biome_graphql_formatter = { workspace = true } biome_graphql_parser = { workspace = true } biome_graphql_syntax = { workspace = true } biome_grit_patterns = { workspace = true } diff --git a/crates/biome_service/src/file_handlers/graphql.rs b/crates/biome_service/src/file_handlers/graphql.rs index d398fc33eedd..ff0158dd82ed 100644 --- a/crates/biome_service/src/file_handlers/graphql.rs +++ b/crates/biome_service/src/file_handlers/graphql.rs @@ -8,7 +8,7 @@ use crate::file_handlers::{ }; use crate::settings::{ FormatSettings, LanguageListSettings, LanguageSettings, LinterSettings, OverrideSettings, - ServiceLanguage, Settings, + ServiceLanguage, Settings, WorkspaceSettingsHandle, }; use crate::workspace::{ CodeAction, FixAction, FixFileMode, FixFileResult, GetSyntaxTreeResult, PullActionsResult, @@ -19,21 +19,49 @@ use biome_analyze::{ RuleCategoriesBuilder, RuleCategory, RuleError, }; use biome_diagnostics::{category, Applicability, Diagnostic, DiagnosticExt, Severity}; -use biome_formatter::SimpleFormatOptions; +use biome_formatter::{ + FormatError, IndentStyle, IndentWidth, LineEnding, LineWidth, Printed, QuoteStyle, +}; use biome_fs::BiomePath; use biome_graphql_analyze::analyze; +use biome_graphql_formatter::context::GraphqlFormatOptions; +use biome_graphql_formatter::format_node; use biome_graphql_parser::parse_graphql_with_cache; -use biome_graphql_syntax::{GraphqlLanguage, GraphqlRoot, GraphqlSyntaxNode}; +use biome_graphql_syntax::{GraphqlLanguage, GraphqlRoot, GraphqlSyntaxNode, TextRange, TextSize}; use biome_parser::AnyParse; -use biome_rowan::{AstNode, NodeCache}; +use biome_rowan::{AstNode, NodeCache, TokenAtOffset}; use std::borrow::Cow; use tracing::{debug_span, error, info, trace, trace_span}; +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] +pub struct GraphqlFormatterSettings { + pub line_ending: Option, + pub line_width: Option, + pub indent_width: Option, + pub indent_style: Option, + pub quote_style: Option, + pub enabled: Option, +} + +impl Default for GraphqlFormatterSettings { + fn default() -> Self { + Self { + enabled: Some(false), + indent_style: Default::default(), + indent_width: Default::default(), + line_ending: Default::default(), + line_width: Default::default(), + quote_style: Default::default(), + } + } +} + impl ServiceLanguage for GraphqlLanguage { - type FormatterSettings = (); + type FormatterSettings = GraphqlFormatterSettings; type LinterSettings = (); type OrganizeImportsSettings = (); - type FormatOptions = SimpleFormatOptions; + type FormatOptions = GraphqlFormatOptions; type ParserSettings = (); type EnvironmentSettings = (); @@ -42,13 +70,45 @@ impl ServiceLanguage for GraphqlLanguage { } fn resolve_format_options( - _global: Option<&FormatSettings>, - _overrides: Option<&OverrideSettings>, - _language: Option<&()>, - _path: &BiomePath, - _document_file_source: &DocumentFileSource, + global: Option<&FormatSettings>, + overrides: Option<&OverrideSettings>, + language: Option<&Self::FormatterSettings>, + path: &BiomePath, + document_file_source: &DocumentFileSource, ) -> Self::FormatOptions { - SimpleFormatOptions::default() + let indent_style = language + .and_then(|l| l.indent_style) + .or(global.and_then(|g| g.indent_style)) + .unwrap_or_default(); + let line_width = language + .and_then(|l| l.line_width) + .or(global.and_then(|g| g.line_width)) + .unwrap_or_default(); + let indent_width = language + .and_then(|l| l.indent_width) + .or(global.and_then(|g| g.indent_width)) + .unwrap_or_default(); + + let line_ending = language + .and_then(|l| l.line_ending) + .or(global.and_then(|g| g.line_ending)) + .unwrap_or_default(); + + let options = GraphqlFormatOptions::new( + document_file_source + .to_graphql_file_source() + .unwrap_or_default(), + ) + .with_indent_style(indent_style) + .with_indent_width(indent_width) + .with_line_width(line_width) + .with_line_ending(line_ending) + .with_quote_style(language.and_then(|l| l.quote_style).unwrap_or_default()); + if let Some(overrides) = overrides { + overrides.to_override_graphql_format_options(path, options) + } else { + options + } } fn resolve_analyzer_options( @@ -76,7 +136,7 @@ impl ExtensionHandler for GraphqlFileHandler { debug: DebugCapabilities { debug_syntax_tree: Some(debug_syntax_tree), debug_control_flow: None, - debug_formatter_ir: None, + debug_formatter_ir: Some(debug_formatter_ir), }, analyzer: AnalyzerCapabilities { lint: Some(lint), @@ -86,9 +146,9 @@ impl ExtensionHandler for GraphqlFileHandler { organize_imports: None, }, formatter: FormatterCapabilities { - format: None, - format_range: None, - format_on_type: None, + format: Some(format), + format_range: Some(format_range), + format_on_type: Some(format_on_type), }, } } @@ -124,6 +184,92 @@ fn debug_syntax_tree(_rome_path: &BiomePath, parse: AnyParse) -> GetSyntaxTreeRe } } +fn debug_formatter_ir( + biome_path: &BiomePath, + document_file_source: &DocumentFileSource, + parse: AnyParse, + settings: WorkspaceSettingsHandle, +) -> Result { + let options = settings.format_options::(biome_path, document_file_source); + + let tree = parse.syntax(); + let formatted = format_node(options, &tree)?; + + let root_element = formatted.into_document(); + Ok(root_element.to_string()) +} + +#[tracing::instrument(level = "debug", skip(parse))] +fn format( + biome_path: &BiomePath, + document_file_source: &DocumentFileSource, + parse: AnyParse, + settings: WorkspaceSettingsHandle, +) -> Result { + let options = settings.format_options::(biome_path, document_file_source); + + tracing::debug!("Format with the following options: \n{}", options); + + let tree = parse.syntax(); + let formatted = format_node(options, &tree)?; + + match formatted.print() { + Ok(printed) => Ok(printed), + Err(error) => Err(WorkspaceError::FormatError(error.into())), + } +} + +fn format_range( + biome_path: &BiomePath, + document_file_source: &DocumentFileSource, + parse: AnyParse, + settings: WorkspaceSettingsHandle, + range: TextRange, +) -> Result { + let options = settings.format_options::(biome_path, document_file_source); + + let tree = parse.syntax(); + let printed = biome_graphql_formatter::format_range(options, &tree, range)?; + Ok(printed) +} + +fn format_on_type( + biome_path: &BiomePath, + document_file_source: &DocumentFileSource, + parse: AnyParse, + settings: WorkspaceSettingsHandle, + offset: TextSize, +) -> Result { + let options = settings.format_options::(biome_path, document_file_source); + + let tree = parse.syntax(); + + let range = tree.text_range(); + if offset < range.start() || offset > range.end() { + return Err(WorkspaceError::FormatError(FormatError::RangeError { + input: TextRange::at(offset, TextSize::from(0)), + tree: range, + })); + } + + let token = match tree.token_at_offset(offset) { + // File is empty, do nothing + TokenAtOffset::None => panic!("empty file"), + TokenAtOffset::Single(token) => token, + // The cursor should be right after the closing character that was just typed, + // select the previous token as the correct one + TokenAtOffset::Between(token, _) => token, + }; + + let root_node = match token.parent() { + Some(node) => node, + None => panic!("found a token with no parent"), + }; + + let printed = biome_graphql_formatter::format_sub_tree(options, &root_node)?; + Ok(printed) +} + fn lint(params: LintParams) -> LintResults { debug_span!("Linting GraphQL file", path =? params.path, language =? params.language).in_scope( move || { diff --git a/crates/biome_service/src/settings.rs b/crates/biome_service/src/settings.rs index dcd3176aec83..87d457f96b0e 100644 --- a/crates/biome_service/src/settings.rs +++ b/crates/biome_service/src/settings.rs @@ -18,6 +18,7 @@ use biome_deserialize::{Merge, StringSet}; use biome_diagnostics::Category; use biome_formatter::{AttributePosition, IndentStyle, IndentWidth, LineEnding, LineWidth}; use biome_fs::BiomePath; +use biome_graphql_formatter::context::GraphqlFormatOptions; use biome_graphql_syntax::GraphqlLanguage; use biome_js_analyze::metadata; use biome_js_formatter::context::JsFormatOptions; @@ -843,6 +844,20 @@ impl OverrideSettings { options } + /// It scans the current override rules and return the formatting options that of the first override is matched + pub fn to_override_graphql_format_options( + &self, + path: &Path, + mut options: GraphqlFormatOptions, + ) -> GraphqlFormatOptions { + for pattern in self.patterns.iter() { + if pattern.include.matches_path(path) && !pattern.exclude.matches_path(path) { + pattern.apply_overrides_to_graphql_format_options(&mut options); + } + } + options + } + pub fn to_override_js_parser_options( &self, path: &Path, @@ -959,6 +974,7 @@ pub struct OverrideSettingPattern { pub(crate) cached_js_format_options: RwLock>, pub(crate) cached_json_format_options: RwLock>, pub(crate) cached_css_format_options: RwLock>, + pub(crate) cached_graphql_format_options: RwLock>, pub(crate) cached_js_parser_options: RwLock>, pub(crate) cached_json_parser_options: RwLock>, pub(crate) cached_css_parser_options: RwLock>, @@ -1086,6 +1102,39 @@ impl OverrideSettingPattern { } } + fn apply_overrides_to_graphql_format_options(&self, options: &mut GraphqlFormatOptions) { + if let Ok(readonly_cache) = self.cached_graphql_format_options.read() { + if let Some(cached_options) = readonly_cache.as_ref() { + *options = cached_options.clone(); + return; + } + } + + let graphql_formatter = &self.languages.graphql.formatter; + let formatter = &self.formatter; + + if let Some(indent_style) = graphql_formatter.indent_style.or(formatter.indent_style) { + options.set_indent_style(indent_style); + } + if let Some(indent_width) = graphql_formatter.indent_width.or(formatter.indent_width) { + options.set_indent_width(indent_width) + } + if let Some(line_ending) = graphql_formatter.line_ending.or(formatter.line_ending) { + options.set_line_ending(line_ending); + } + if let Some(line_width) = graphql_formatter.line_width.or(formatter.line_width) { + options.set_line_width(line_width); + } + if let Some(quote_style) = graphql_formatter.quote_style { + options.set_quote_style(quote_style); + } + + if let Ok(mut writeonly_cache) = self.cached_graphql_format_options.write() { + let options = options.clone(); + let _ = writeonly_cache.insert(options); + } + } + fn apply_overrides_to_js_parser_options(&self, options: &mut JsParserOptions) { if let Ok(readonly_cache) = self.cached_js_parser_options.read() { if let Some(cached_options) = readonly_cache.as_ref() { diff --git a/crates/biome_service/tests/invalid/top_level_extraneous_field.json.snap b/crates/biome_service/tests/invalid/top_level_extraneous_field.json.snap index c27b405c8921..4ed3284af370 100644 --- a/crates/biome_service/tests/invalid/top_level_extraneous_field.json.snap +++ b/crates/biome_service/tests/invalid/top_level_extraneous_field.json.snap @@ -23,8 +23,6 @@ top_level_extraneous_field.json:2:2 deserialize ━━━━━━━━━━ - javascript - json - css + - graphql - extends - overrides - - - diff --git a/knope.toml b/knope.toml index aede1a2f834b..2c9a51021347 100644 --- a/knope.toml +++ b/knope.toml @@ -196,6 +196,10 @@ versioned_files = ["crates/biome_configuration/Cargo.toml"] changelog = "crates/biome_grit_formatter/CHANGELOG.md" versioned_files = ["crates/biome_grit_formatter/Cargo.toml"] +[packages.biome_graphql_formatter] +changelog = "crates/biome_graphql_formatter/CHANGELOG.md" +versioned_files = ["crates/biome_graphql_formatter/Cargo.toml"] + [packages.biome_graphql_analyze] changelog = "crates/biome_graphql_analyze/CHANGELOG.md" versioned_files = ["crates/biome_graphql_analyze/Cargo.toml"] diff --git a/packages/@biomejs/backend-jsonrpc/src/workspace.ts b/packages/@biomejs/backend-jsonrpc/src/workspace.ts index 6ededd4be8c2..29ed03a692bb 100644 --- a/packages/@biomejs/backend-jsonrpc/src/workspace.ts +++ b/packages/@biomejs/backend-jsonrpc/src/workspace.ts @@ -47,6 +47,10 @@ export interface PartialConfiguration { * The configuration of the formatter */ formatter?: PartialFormatterConfiguration; + /** + * Specific configuration for the GraphQL language + */ + graphql?: PartialGraphqlConfiguration; /** * Specific configuration for the JavaScript language */ @@ -153,6 +157,15 @@ export interface PartialFormatterConfiguration { */ lineWidth?: LineWidth; } +/** + * Options applied to GraphQL files + */ +export interface PartialGraphqlConfiguration { + /** + * GraphQL formatter options + */ + formatter?: PartialGraphqlFormatter; +} /** * A set of options applied to the JavaScript files */ @@ -319,6 +332,35 @@ export type LineEnding = "lf" | "crlf" | "cr"; The allowed range of values is 1..=320 */ export type LineWidth = number; +/** + * Options that changes how the GraphQL formatter behaves + */ +export interface PartialGraphqlFormatter { + /** + * Control the formatter for GraphQL files. + */ + enabled?: boolean; + /** + * The indent style applied to GraphQL files. + */ + indentStyle?: PlainIndentStyle; + /** + * The size of the indentation applied to GraphQL files. Default to 2. + */ + indentWidth?: IndentWidth; + /** + * The type of line ending applied to GraphQL files. + */ + lineEnding?: LineEnding; + /** + * What's the max width of a line applied to GraphQL files. Defaults to 80. + */ + lineWidth?: LineWidth; + /** + * The type of quotes used in GraphQL code. Defaults to double. + */ + quoteStyle?: QuoteStyle; +} /** * Formatting options specific to the JavaScript files */ @@ -2189,7 +2231,9 @@ export interface JsonFileSource { export interface CssFileSource { variant: CssVariant; } -export interface GraphqlFileSource {} +export interface GraphqlFileSource { + variant: GraphqlVariant; +} export type EmbeddingKind = "Astro" | "Vue" | "Svelte" | "None"; export type Language = | "JavaScript" @@ -2211,6 +2255,10 @@ export type LanguageVersion = "ES2022" | "ESNext"; Currently, Biome only supports plain CSS, and aims to be compatible with the latest Recommendation level standards. */ export type CssVariant = "Standard"; +/** + * The style of GraphQL contained in the file. + */ +export type GraphqlVariant = "Standard"; export interface ChangeFileParams { content: string; path: BiomePath; diff --git a/packages/@biomejs/biome/configuration_schema.json b/packages/@biomejs/biome/configuration_schema.json index ecd48624c77e..06cc34c8f435 100644 --- a/packages/@biomejs/biome/configuration_schema.json +++ b/packages/@biomejs/biome/configuration_schema.json @@ -33,6 +33,13 @@ { "type": "null" } ] }, + "graphql": { + "description": "Specific configuration for the GraphQL language", + "anyOf": [ + { "$ref": "#/definitions/GraphqlConfiguration" }, + { "type": "null" } + ] + }, "javascript": { "description": "Specific configuration for the JavaScript language", "anyOf": [ @@ -1139,6 +1146,54 @@ }, "additionalProperties": false }, + "GraphqlConfiguration": { + "description": "Options applied to GraphQL files", + "type": "object", + "properties": { + "formatter": { + "description": "GraphQL formatter options", + "anyOf": [ + { "$ref": "#/definitions/GraphqlFormatter" }, + { "type": "null" } + ] + } + }, + "additionalProperties": false + }, + "GraphqlFormatter": { + "description": "Options that changes how the GraphQL formatter behaves", + "type": "object", + "properties": { + "enabled": { + "description": "Control the formatter for GraphQL files.", + "type": ["boolean", "null"] + }, + "indentStyle": { + "description": "The indent style applied to GraphQL files.", + "anyOf": [ + { "$ref": "#/definitions/PlainIndentStyle" }, + { "type": "null" } + ] + }, + "indentWidth": { + "description": "The size of the indentation applied to GraphQL files. Default to 2.", + "anyOf": [{ "$ref": "#/definitions/IndentWidth" }, { "type": "null" }] + }, + "lineEnding": { + "description": "The type of line ending applied to GraphQL files.", + "anyOf": [{ "$ref": "#/definitions/LineEnding" }, { "type": "null" }] + }, + "lineWidth": { + "description": "What's the max width of a line applied to GraphQL files. Defaults to 80.", + "anyOf": [{ "$ref": "#/definitions/LineWidth" }, { "type": "null" }] + }, + "quoteStyle": { + "description": "The type of quotes used in GraphQL code. Defaults to double.", + "anyOf": [{ "$ref": "#/definitions/QuoteStyle" }, { "type": "null" }] + } + }, + "additionalProperties": false + }, "Hook": { "type": "object", "required": ["name", "stableResult"], diff --git a/xtask/codegen/src/formatter.rs b/xtask/codegen/src/formatter.rs index 66b3c1b16671..17f7a10e33d6 100644 --- a/xtask/codegen/src/formatter.rs +++ b/xtask/codegen/src/formatter.rs @@ -557,6 +557,7 @@ enum NodeDialect { Json, Css, Grit, + Graphql, } impl NodeDialect { @@ -568,6 +569,7 @@ impl NodeDialect { NodeDialect::Json, NodeDialect::Css, NodeDialect::Grit, + NodeDialect::Graphql, ] } @@ -583,6 +585,7 @@ impl NodeDialect { NodeDialect::Json => "json", NodeDialect::Css => "css", NodeDialect::Grit => "grit", + NodeDialect::Graphql => "graphql", } } @@ -594,6 +597,7 @@ impl NodeDialect { "Json" => NodeDialect::Json, "Css" => NodeDialect::Css, "Grit" => NodeDialect::Grit, + "Graphql" => NodeDialect::Graphql, _ => { eprintln!("missing prefix {name}"); NodeDialect::Js @@ -633,6 +637,10 @@ enum NodeConcept { // GritQL Pattern, Predicate, + + // GraphQL + Definition, + Extension, } impl NodeConcept { @@ -659,6 +667,8 @@ impl NodeConcept { NodeConcept::Property => "properties", NodeConcept::Pattern => "patterns", NodeConcept::Predicate => "predicates", + NodeConcept::Definition => "definitions", + NodeConcept::Extension => "extensions", } } } @@ -789,8 +799,12 @@ fn get_node_concept( _ => NodeConcept::Auxiliary, }, - // TODO: implement formatter - LanguageKind::Graphql => NodeConcept::Auxiliary, + LanguageKind::Graphql => match name { + _ if name.contains("Extension") => NodeConcept::Extension, + _ if name.ends_with("Definition") => NodeConcept::Definition, + _ if name.ends_with("Value") => NodeConcept::Value, + _ => NodeConcept::Auxiliary, + }, LanguageKind::Grit => match name { _ if name.contains("Operation") || name.contains("Pattern") => NodeConcept::Pattern,