Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/legal-mugs-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": minor
---

Added support for `.graphqls` files. Biome can now format and lint GraphQL files that have the extension `.graphqls`
40 changes: 40 additions & 0 deletions crates/biome_cli/tests/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ const APPLY_BRACKET_SAME_LINE_AFTER: &str = r#"<Foo
reallyLongAttributeName2={anotherLongValue}>
Hi
</Foo>;
"#;

const SPACING_GRAPHQLS_SANITY_BEFORE: &str = r#" scalar Time
scalar UUID


type User {
id: UUID!
name: String!
updatedAt: Time!
}




"#;

const APPLY_ATTRIBUTE_POSITION_BEFORE: &str = r#"<Foo className={style} reallyLongAttributeName1={longComplexValue}
Expand Down Expand Up @@ -3364,6 +3379,31 @@ fn should_error_if_unchanged_files_only_with_changed_flag() {
));
}

#[test]
fn can_format_graphphs_files() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let file_path = Utf8Path::new("file.graphqls");
fs.insert(file_path.into(), SPACING_GRAPHQLS_SANITY_BEFORE.as_bytes());

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["format", "--write", file_path.as_str()].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"can_format_graphphs_files",
fs,
console,
result,
));
}

#[test]
fn applies_custom_bracket_spacing_for_graphql() {
let fs = MemoryFileSystem::default();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `file.graphqls`

```graphqls
scalar Time
scalar UUID

type User {
id: UUID!
name: String!
updatedAt: Time!
}

```

# Emitted Messages

```block
Formatted 1 file in <TIME>. Fixed 1 file.
```
7 changes: 5 additions & 2 deletions crates/biome_graphql_syntax/src/file_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ impl GraphqlFileSource {
}

/// Try to return the GraphQL file source corresponding to this file extension
/// See the difference between .graphql and .graphqls files here:
/// https://www.apollographql.com/docs/kotlin/essentials/file-types#sdl-schemas-graphqls
/// https://graphql.com/learn/schema/#inspecting-the-schema
pub fn try_from_extension(extension: &str) -> Result<Self, FileSourceError> {
// We assume the file extension is normalized to lowercase
match extension {
"graphql" | "gql" => Ok(Self::default()),
"graphqls" | "graphql" | "gql" => Ok(Self::default()),
_ => Err(FileSourceError::UnknownExtension),
}
}
Expand All @@ -52,7 +55,7 @@ impl GraphqlFileSource {
/// [VS Code spec]: https://code.visualstudio.com/docs/languages/identifiers
pub fn try_from_language_id(language_id: &str) -> Result<Self, FileSourceError> {
match language_id {
"graphql" | "gql" => Ok(Self::default()),
"graphqls" | "graphql" | "gql" => Ok(Self::default()),
_ => Err(FileSourceError::UnknownLanguageId),
}
}
Expand Down
Loading