Skip to content

Commit

Permalink
feat: add GraphQL format support (#319) (#322)
Browse files Browse the repository at this point in the history
Prettier supports GraphQL natively. The file extensions are registered
with the formatter and a basic format test is added.
  • Loading branch information
sallustfire authored Jul 15, 2024
1 parent 5d6d166 commit ae48d99
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ Features:
New tools are being added frequently, so check this page again!

| Language | Formatter | Linter(s) |
| ---------------------- | --------------------- | ---------------- |
|------------------------| --------------------- |------------------|
| C / C++ | [clang-format] | ([#112]) |
| Cuda | [clang-format] | |
| CSS, Less, Sass | [Prettier] | |
| Go | [gofmt] or [gofumpt] | |
| GraphQL | [Prettier] | |
| HCL (Hashicorp Config) | [terraform] fmt | |
| HTML | [Prettier] | |
| JSON | [Prettier] | |
Expand Down
3 changes: 2 additions & 1 deletion docs/format.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions example/src/hello.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query
{
world(greeting:
"hello") {
... on Hello { salutation }
}
}
1 change: 1 addition & 0 deletions example/tools/format/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ format_multirun(
css = ":prettier",
cuda = "@llvm_toolchain_llvm//:bin/clang-format",
go = "@aspect_rules_lint//format:gofumpt",
graphql = ":prettier",
html = ":prettier",
# You can use standard gofmt instead of stricter gofumpt:
# go = "@go_sdk//:bin/gofmt",
Expand Down
1 change: 1 addition & 0 deletions format/private/filter.jq
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with_entries(select(.key | IN(
"Cuda",
"Markdown",
"Go",
"GraphQL",
"HCL",
"HTML",
"Java",
Expand Down
1 change: 1 addition & 0 deletions format/private/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function ls-files {
'Cuda') patterns=('*.cu' '*.cuh') ;;
'CSS') patterns=('*.css') ;;
'Go') patterns=('*.go') ;;
'GraphQL') patterns=('*.graphql' '*.gql' '*.graphqls') ;;
'HTML') patterns=('*.html' '*.hta' '*.htm' '*.html.hl' '*.inc' '*.xht' '*.xhtml') ;;
'JSON') patterns=('.all-contributorsrc' '.arcconfig' '.auto-changelog' '.c8rc' '.htmlhintrc' '.imgbotconfig' '.nycrc' '.tern-config' '.tern-project' '.watchmanconfig' 'Pipfile.lock' 'composer.lock' 'deno.lock' 'flake.lock' 'mcmod.info' '*.json' '*.4DForm' '*.4DProject' '*.avsc' '*.geojson' '*.gltf' '*.har' '*.ice' '*.JSON-tmLanguage' '*.jsonl' '*.mcmeta' '*.tfstate' '*.tfstate.backup' '*.topojson' '*.webapp' '*.webmanifest' '*.yy' '*.yyp') ;;
'Java') patterns=('*.java' '*.jav' '*.jsh') ;;
Expand Down
1 change: 1 addition & 0 deletions format/private/formatter_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ TOOLS = {
"JavaScript": "prettier",
"Markdown": "prettier",
"CSS": "prettier",
"GraphQL": "prettier",
"HTML": "prettier",
"Python": "ruff",
"Starlark": "buildifier",
Expand Down
1 change: 1 addition & 0 deletions format/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ format_multirun(
css = ":mock_prettier.sh",
cuda = ":mock_clang-format.sh",
go = ":mock_gofmt.sh",
graphql = ":mock_prettier.sh",
html = ":mock_prettier.sh",
java = ":mock_java-format.sh",
javascript = ":mock_prettier.sh",
Expand Down
7 changes: 7 additions & 0 deletions format/test/format_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ bats_load_library "bats-assert"
assert_output --partial "+ prettier --write example/src/index.html"
}

@test "should run prettier on GraphQL" {
run bazel run //format/test:format_GraphQL_with_prettier
assert_success

assert_output --partial "+ prettier --write example/src/hello.graphql"
}

@test "should run prettier on SQL" {
run bazel run //format/test:format_SQL_with_prettier
assert_success
Expand Down

0 comments on commit ae48d99

Please sign in to comment.