Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gqlfmt

gqlfmt formats your GraphQL files.

Install

go install github.com/gqlgo/gqlfmt@latest

Usage

  • Help
$ gqlfmt --help
usage: gqlfmt [flags] [path ...]
  -d    display diffs instead of rewriting files
  -l    list files whose formatting differs from gqlfmt's
  -v    verbose logging
  -w    write result to (source) file instead of stdout
  • to stdout
$ cat *.graphql # display unformatted files
query A1 {
     id
   test
}

query A2 {
      id
      test
}
query B1 {
     id
 hello
}

query B2 {
      id



      test
}
query C1 {
        id
}
$ gqlfmt *.graphql
query A1 {
        id
        test
}
query A2 {
        id
        test
}
query B1 {
        id
        hello
}
query B2 {
        id
        test
}
query C1 {
        id
}
  • Over write GraphQL files
$ gqlfmt -w *.graphql
  • List files whose formatting differs from gqlfmt's
$ gqlfmt -l *.graphql
a.graphql
b.graphql
  • Display diffs
$ gqlfmt -d *.graphql
diff -u a.graphql.orig a.graphql
--- a.graphql.orig      2021-04-06 14:26:26.000000000 +0900
+++ a.graphql   2021-04-06 14:26:26.000000000 +0900
@@ -1,9 +1,8 @@
 query A1 {
-     id
-   test
+       id
+       test
 }
-
 query A2 {
-      id
-      test
+       id
+       test
 }
diff -u b.graphql.orig b.graphql
--- b.graphql.orig      2021-04-06 14:26:26.000000000 +0900
+++ b.graphql   2021-04-06 14:26:26.000000000 +0900
@@ -1,12 +1,8 @@
 query B1 {
-     id
- hello
+       id
+       hello
 }
-
 query B2 {
-      id
-
-
-
-      test
+       id
+       test
 }
  • from stdin
$ cat a.graphql | gqlfmt -d
diff -u stdin.go.orig stdin.go
--- stdin.go.orig       2021-04-06 15:03:59.000000000 +0900
+++ stdin.go    2021-04-06 15:03:59.000000000 +0900
@@ -1,9 +1,8 @@
 query A1 {
-     id
-   test
+       id
+       test
 }
-
 query A2 {
-      id
-      test
+       id
+       test
 }

About

gqlfmt formats your GraphQL files. like gofmt.

Resources

Stars

17 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages