From 8d1bedc79983a5e89f880fb8437e2b296c545c50 Mon Sep 17 00:00:00 2001 From: Ben Kraft Date: Mon, 17 Jul 2023 04:44:41 -0700 Subject: [PATCH] Put comments behind an option in formatter (#271) * Put comments behind an option in formatter In #263, we introduced parsing of comments, as well as support for them in the formatter. In some cases this is surely useful, but in others it's just bloat. (And as I describe in Khan/genqlient#282, it may even be a problem in some cases which depended on the fact that formatting the query didn't include comments.) In this commit I introduce an option to control whether comments are formatted. I set the default to false (i.e. restoring the previous behavior if no options are set), because adding this felt to me like a breaking change, and because it seems to me like the more common usage. `WithComments()` restores the behavior added in #263. If others disagree I'm happy to keep the changed default, and instead provide `WithoutComments()`. I also added tests both ways (and for the existing `WithIndent()` option), and checked that the `comments` tests match the existing ones, and the `default` tests match those from `v2.6.3` (except for the addition of a few descriptions whose omission seem to have been a bug). Comments are still parsed in any case, as adding new struct fields is no problem; and they are still included in `Dump` since that seems obviously parallel to struct fields and is more of a debugging thing. * docs --- formatter/formatter.go | 20 +- formatter/formatter_test.go | 218 ++++++++++-------- .../{ => comments}/basic.graphql | 0 .../{ => comments}/field.graphql | 0 .../{ => comments}/fragment.graphql | 0 .../{ => comments}/variable.graphql | 0 .../FormatQueryDocument/default/basic.graphql | 7 + .../FormatQueryDocument/default/field.graphql | 3 + .../default/fragment.graphql | 18 ++ .../default/variable.graphql | 8 + .../spaceIndent/basic.graphql | 7 + .../spaceIndent/field.graphql | 3 + .../spaceIndent/fragment.graphql | 18 ++ .../spaceIndent/variable.graphql | 8 + .../{ => comments}/comment.graphql | 0 .../{ => comments}/definition.graphql | 0 .../{ => comments}/description.graphql | 0 .../{ => comments}/directive.graphql | 0 .../directive_locations.graphql | 0 .../{ => comments}/extensions.graphql | 0 .../{ => comments}/field_definition.graphql | 0 .../{ => comments}/schema.graphql | 0 .../FormatSchema/{ => comments}/swapi.graphql | 0 .../FormatSchema/default/comment.graphql | 0 .../FormatSchema/default/definition.graphql | 25 ++ .../FormatSchema/default/description.graphql | 8 + .../FormatSchema/default/directive.graphql | 2 + .../default/directive_locations.graphql | 13 ++ .../FormatSchema/default/extensions.graphql | 16 ++ .../default/field_definition.graphql | 3 + .../FormatSchema/default/schema.graphql | 41 ++++ .../FormatSchema/default/swapi.graphql | 87 +++++++ .../FormatSchema/spaceIndent/comment.graphql | 0 .../spaceIndent/definition.graphql | 25 ++ .../spaceIndent/description.graphql | 8 + .../spaceIndent/directive.graphql | 2 + .../spaceIndent/directive_locations.graphql | 13 ++ .../spaceIndent/extensions.graphql | 16 ++ .../spaceIndent/field_definition.graphql | 3 + .../FormatSchema/spaceIndent/schema.graphql | 41 ++++ .../FormatSchema/spaceIndent/swapi.graphql | 87 +++++++ .../{ => comments}/comment.graphql | 0 .../{ => comments}/definition.graphql | 0 .../{ => comments}/description.graphql | 0 .../{ => comments}/directive.graphql | 0 .../directive_locations.graphql | 0 .../{ => comments}/extensions.graphql | 0 .../{ => comments}/field_definition.graphql | 0 .../{ => comments}/schema.graphql | 0 .../{ => comments}/swapi.graphql | 0 .../default/comment.graphql | 0 .../default/definition.graphql | 25 ++ .../default/description.graphql | 8 + .../default/directive.graphql | 2 + .../default/directive_locations.graphql | 13 ++ .../default/extensions.graphql | 24 ++ .../default/field_definition.graphql | 3 + .../default/schema.graphql | 42 ++++ .../default/swapi.graphql | 92 ++++++++ .../spaceIndent/comment.graphql | 0 .../spaceIndent/definition.graphql | 25 ++ .../spaceIndent/description.graphql | 8 + .../spaceIndent/directive.graphql | 2 + .../spaceIndent/directive_locations.graphql | 13 ++ .../spaceIndent/extensions.graphql | 24 ++ .../spaceIndent/field_definition.graphql | 3 + .../spaceIndent/schema.graphql | 42 ++++ .../spaceIndent/swapi.graphql | 92 ++++++++ 68 files changed, 1018 insertions(+), 100 deletions(-) rename formatter/testdata/baseline/FormatQueryDocument/{ => comments}/basic.graphql (100%) rename formatter/testdata/baseline/FormatQueryDocument/{ => comments}/field.graphql (100%) rename formatter/testdata/baseline/FormatQueryDocument/{ => comments}/fragment.graphql (100%) rename formatter/testdata/baseline/FormatQueryDocument/{ => comments}/variable.graphql (100%) create mode 100644 formatter/testdata/baseline/FormatQueryDocument/default/basic.graphql create mode 100644 formatter/testdata/baseline/FormatQueryDocument/default/field.graphql create mode 100644 formatter/testdata/baseline/FormatQueryDocument/default/fragment.graphql create mode 100644 formatter/testdata/baseline/FormatQueryDocument/default/variable.graphql create mode 100644 formatter/testdata/baseline/FormatQueryDocument/spaceIndent/basic.graphql create mode 100644 formatter/testdata/baseline/FormatQueryDocument/spaceIndent/field.graphql create mode 100644 formatter/testdata/baseline/FormatQueryDocument/spaceIndent/fragment.graphql create mode 100644 formatter/testdata/baseline/FormatQueryDocument/spaceIndent/variable.graphql rename formatter/testdata/baseline/FormatSchema/{ => comments}/comment.graphql (100%) rename formatter/testdata/baseline/FormatSchema/{ => comments}/definition.graphql (100%) rename formatter/testdata/baseline/FormatSchema/{ => comments}/description.graphql (100%) rename formatter/testdata/baseline/FormatSchema/{ => comments}/directive.graphql (100%) rename formatter/testdata/baseline/FormatSchema/{ => comments}/directive_locations.graphql (100%) rename formatter/testdata/baseline/FormatSchema/{ => comments}/extensions.graphql (100%) rename formatter/testdata/baseline/FormatSchema/{ => comments}/field_definition.graphql (100%) rename formatter/testdata/baseline/FormatSchema/{ => comments}/schema.graphql (100%) rename formatter/testdata/baseline/FormatSchema/{ => comments}/swapi.graphql (100%) create mode 100644 formatter/testdata/baseline/FormatSchema/default/comment.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/default/definition.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/default/description.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/default/directive.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/default/directive_locations.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/default/extensions.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/default/field_definition.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/default/schema.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/default/swapi.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/spaceIndent/comment.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/spaceIndent/definition.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/spaceIndent/description.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/spaceIndent/directive.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/spaceIndent/directive_locations.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/spaceIndent/extensions.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/spaceIndent/field_definition.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/spaceIndent/schema.graphql create mode 100644 formatter/testdata/baseline/FormatSchema/spaceIndent/swapi.graphql rename formatter/testdata/baseline/FormatSchemaDocument/{ => comments}/comment.graphql (100%) rename formatter/testdata/baseline/FormatSchemaDocument/{ => comments}/definition.graphql (100%) rename formatter/testdata/baseline/FormatSchemaDocument/{ => comments}/description.graphql (100%) rename formatter/testdata/baseline/FormatSchemaDocument/{ => comments}/directive.graphql (100%) rename formatter/testdata/baseline/FormatSchemaDocument/{ => comments}/directive_locations.graphql (100%) rename formatter/testdata/baseline/FormatSchemaDocument/{ => comments}/extensions.graphql (100%) rename formatter/testdata/baseline/FormatSchemaDocument/{ => comments}/field_definition.graphql (100%) rename formatter/testdata/baseline/FormatSchemaDocument/{ => comments}/schema.graphql (100%) rename formatter/testdata/baseline/FormatSchemaDocument/{ => comments}/swapi.graphql (100%) create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/default/comment.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/default/definition.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/default/description.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/default/directive.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/default/directive_locations.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/default/extensions.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/default/field_definition.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/default/schema.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/default/swapi.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/comment.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/definition.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/description.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/directive.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/directive_locations.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/extensions.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/field_definition.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/schema.graphql create mode 100644 formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/swapi.graphql diff --git a/formatter/formatter.go b/formatter/formatter.go index bbc0e8bb..4a0eb5a2 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -18,12 +18,21 @@ type Formatter interface { //nolint:revive // Ignore "stuttering" name format.FormatterOption type FormatterOption func(*formatter) +// WithIndent uses the given string for indenting block bodies in the output, +// instead of the default, `"\t"`. func WithIndent(indent string) FormatterOption { return func(f *formatter) { f.indent = indent } } +// WithComments includes comments from the source/AST in the formatted output. +func WithComments() FormatterOption { + return func(f *formatter) { + f.emitComments = true + } +} + func NewFormatter(w io.Writer, options ...FormatterOption) Formatter { f := &formatter{ indent: "\t", @@ -38,9 +47,10 @@ func NewFormatter(w io.Writer, options ...FormatterOption) Formatter { type formatter struct { writer io.Writer - indent string - indentSize int - emitBuiltin bool + indent string + indentSize int + emitBuiltin bool + emitComments bool padNext bool lineHead bool @@ -714,7 +724,7 @@ func (f *formatter) FormatValue(value *ast.Value) { } func (f *formatter) FormatCommentGroup(group *ast.CommentGroup) { - if group == nil { + if !f.emitComments || group == nil { return } for _, comment := range group.List { @@ -723,7 +733,7 @@ func (f *formatter) FormatCommentGroup(group *ast.CommentGroup) { } func (f *formatter) FormatComment(comment *ast.Comment) { - if comment == nil { + if !f.emitComments || comment == nil { return } f.WriteString("#").WriteString(comment.Text()).WriteNewline() diff --git a/formatter/formatter_test.go b/formatter/formatter_test.go index 5113fb9a..b4573b98 100644 --- a/formatter/formatter_test.go +++ b/formatter/formatter_test.go @@ -5,6 +5,7 @@ import ( "flag" "os" "path" + "path/filepath" "testing" "unicode/utf8" @@ -17,118 +18,145 @@ import ( var update = flag.Bool("u", false, "update golden files") +var optionSets = []struct { + name string + opts []formatter.FormatterOption +}{ + {"default", nil}, + {"spaceIndent", []formatter.FormatterOption{formatter.WithIndent(" ")}}, + {"comments", []formatter.FormatterOption{formatter.WithComments()}}, +} + func TestFormatter_FormatSchema(t *testing.T) { const testSourceDir = "./testdata/source/schema" const testBaselineDir = "./testdata/baseline/FormatSchema" - executeGoldenTesting(t, &goldenConfig{ - SourceDir: testSourceDir, - BaselineFileName: func(cfg *goldenConfig, f os.DirEntry) string { - return path.Join(testBaselineDir, f.Name()) - }, - Run: func(t *testing.T, cfg *goldenConfig, f os.DirEntry) []byte { - // load stuff - schema, gqlErr := gqlparser.LoadSchema(&ast.Source{ - Name: f.Name(), - Input: mustReadFile(path.Join(testSourceDir, f.Name())), + for _, optionSet := range optionSets { + testBaselineDir := filepath.Join(testBaselineDir, optionSet.name) + opts := optionSet.opts + t.Run(optionSet.name, func(t *testing.T) { + executeGoldenTesting(t, &goldenConfig{ + SourceDir: testSourceDir, + BaselineFileName: func(cfg *goldenConfig, f os.DirEntry) string { + return path.Join(testBaselineDir, f.Name()) + }, + Run: func(t *testing.T, cfg *goldenConfig, f os.DirEntry) []byte { + // load stuff + schema, gqlErr := gqlparser.LoadSchema(&ast.Source{ + Name: f.Name(), + Input: mustReadFile(path.Join(testSourceDir, f.Name())), + }) + if gqlErr != nil { + t.Fatal(gqlErr) + } + + // exec format + var buf bytes.Buffer + formatter.NewFormatter(&buf, opts...).FormatSchema(schema) + + // validity check + _, gqlErr = gqlparser.LoadSchema(&ast.Source{ + Name: f.Name(), + Input: buf.String(), + }) + if gqlErr != nil { + t.Log(buf.String()) + t.Fatal(gqlErr) + } + + return buf.Bytes() + }, }) - if gqlErr != nil { - t.Fatal(gqlErr) - } - - // exec format - var buf bytes.Buffer - formatter.NewFormatter(&buf).FormatSchema(schema) - - // validity check - _, gqlErr = gqlparser.LoadSchema(&ast.Source{ - Name: f.Name(), - Input: buf.String(), - }) - if gqlErr != nil { - t.Log(buf.String()) - t.Fatal(gqlErr) - } - - return buf.Bytes() - }, - }) + }) + } } func TestFormatter_FormatSchemaDocument(t *testing.T) { const testSourceDir = "./testdata/source/schema" const testBaselineDir = "./testdata/baseline/FormatSchemaDocument" - executeGoldenTesting(t, &goldenConfig{ - SourceDir: testSourceDir, - BaselineFileName: func(cfg *goldenConfig, f os.DirEntry) string { - return path.Join(testBaselineDir, f.Name()) - }, - Run: func(t *testing.T, cfg *goldenConfig, f os.DirEntry) []byte { - // load stuff - doc, gqlErr := parser.ParseSchema(&ast.Source{ - Name: f.Name(), - Input: mustReadFile(path.Join(testSourceDir, f.Name())), - }) - if gqlErr != nil { - t.Fatal(gqlErr) - } - - // exec format - var buf bytes.Buffer - formatter.NewFormatter(&buf).FormatSchemaDocument(doc) - - // validity check - _, gqlErr = parser.ParseSchema(&ast.Source{ - Name: f.Name(), - Input: buf.String(), + for _, optionSet := range optionSets { + testBaselineDir := filepath.Join(testBaselineDir, optionSet.name) + opts := optionSet.opts + t.Run(optionSet.name, func(t *testing.T) { + executeGoldenTesting(t, &goldenConfig{ + SourceDir: testSourceDir, + BaselineFileName: func(cfg *goldenConfig, f os.DirEntry) string { + return path.Join(testBaselineDir, f.Name()) + }, + Run: func(t *testing.T, cfg *goldenConfig, f os.DirEntry) []byte { + // load stuff + doc, gqlErr := parser.ParseSchema(&ast.Source{ + Name: f.Name(), + Input: mustReadFile(path.Join(testSourceDir, f.Name())), + }) + if gqlErr != nil { + t.Fatal(gqlErr) + } + + // exec format + var buf bytes.Buffer + formatter.NewFormatter(&buf, opts...).FormatSchemaDocument(doc) + + // validity check + _, gqlErr = parser.ParseSchema(&ast.Source{ + Name: f.Name(), + Input: buf.String(), + }) + if gqlErr != nil { + t.Log(buf.String()) + t.Fatal(gqlErr) + } + + return buf.Bytes() + }, }) - if gqlErr != nil { - t.Log(buf.String()) - t.Fatal(gqlErr) - } - - return buf.Bytes() - }, - }) + }) + } } func TestFormatter_FormatQueryDocument(t *testing.T) { const testSourceDir = "./testdata/source/query" const testBaselineDir = "./testdata/baseline/FormatQueryDocument" - executeGoldenTesting(t, &goldenConfig{ - SourceDir: testSourceDir, - BaselineFileName: func(cfg *goldenConfig, f os.DirEntry) string { - return path.Join(testBaselineDir, f.Name()) - }, - Run: func(t *testing.T, cfg *goldenConfig, f os.DirEntry) []byte { - // load stuff - doc, gqlErr := parser.ParseQuery(&ast.Source{ - Name: f.Name(), - Input: mustReadFile(path.Join(testSourceDir, f.Name())), + for _, optionSet := range optionSets { + testBaselineDir := filepath.Join(testBaselineDir, optionSet.name) + opts := optionSet.opts + t.Run(optionSet.name, func(t *testing.T) { + executeGoldenTesting(t, &goldenConfig{ + SourceDir: testSourceDir, + BaselineFileName: func(cfg *goldenConfig, f os.DirEntry) string { + return path.Join(testBaselineDir, f.Name()) + }, + Run: func(t *testing.T, cfg *goldenConfig, f os.DirEntry) []byte { + // load stuff + doc, gqlErr := parser.ParseQuery(&ast.Source{ + Name: f.Name(), + Input: mustReadFile(path.Join(testSourceDir, f.Name())), + }) + if gqlErr != nil { + t.Fatal(gqlErr) + } + + // exec format + var buf bytes.Buffer + formatter.NewFormatter(&buf, opts...).FormatQueryDocument(doc) + + // validity check + _, gqlErr = parser.ParseQuery(&ast.Source{ + Name: f.Name(), + Input: buf.String(), + }) + if gqlErr != nil { + t.Log(buf.String()) + t.Fatal(gqlErr) + } + + return buf.Bytes() + }, }) - if gqlErr != nil { - t.Fatal(gqlErr) - } - - // exec format - var buf bytes.Buffer - formatter.NewFormatter(&buf).FormatQueryDocument(doc) - - // validity check - _, gqlErr = parser.ParseQuery(&ast.Source{ - Name: f.Name(), - Input: buf.String(), - }) - if gqlErr != nil { - t.Log(buf.String()) - t.Fatal(gqlErr) - } - - return buf.Bytes() - }, - }) + }) + } } type goldenConfig struct { @@ -178,11 +206,11 @@ func executeGoldenTesting(t *testing.T, cfg *goldenConfig) { expected, err := os.ReadFile(expectedFilePath) if os.IsNotExist(err) { - err = os.MkdirAll(path.Dir(expectedFilePath), 0755) + err = os.MkdirAll(path.Dir(expectedFilePath), 0o755) if err != nil { t.Fatal(err) } - err = os.WriteFile(expectedFilePath, result, 0444) + err = os.WriteFile(expectedFilePath, result, 0o444) if err != nil { t.Fatal(err) } diff --git a/formatter/testdata/baseline/FormatQueryDocument/basic.graphql b/formatter/testdata/baseline/FormatQueryDocument/comments/basic.graphql similarity index 100% rename from formatter/testdata/baseline/FormatQueryDocument/basic.graphql rename to formatter/testdata/baseline/FormatQueryDocument/comments/basic.graphql diff --git a/formatter/testdata/baseline/FormatQueryDocument/field.graphql b/formatter/testdata/baseline/FormatQueryDocument/comments/field.graphql similarity index 100% rename from formatter/testdata/baseline/FormatQueryDocument/field.graphql rename to formatter/testdata/baseline/FormatQueryDocument/comments/field.graphql diff --git a/formatter/testdata/baseline/FormatQueryDocument/fragment.graphql b/formatter/testdata/baseline/FormatQueryDocument/comments/fragment.graphql similarity index 100% rename from formatter/testdata/baseline/FormatQueryDocument/fragment.graphql rename to formatter/testdata/baseline/FormatQueryDocument/comments/fragment.graphql diff --git a/formatter/testdata/baseline/FormatQueryDocument/variable.graphql b/formatter/testdata/baseline/FormatQueryDocument/comments/variable.graphql similarity index 100% rename from formatter/testdata/baseline/FormatQueryDocument/variable.graphql rename to formatter/testdata/baseline/FormatQueryDocument/comments/variable.graphql diff --git a/formatter/testdata/baseline/FormatQueryDocument/default/basic.graphql b/formatter/testdata/baseline/FormatQueryDocument/default/basic.graphql new file mode 100644 index 00000000..238d422e --- /dev/null +++ b/formatter/testdata/baseline/FormatQueryDocument/default/basic.graphql @@ -0,0 +1,7 @@ +query FooBarQuery ($after: String!) { + fizzList(first: 100, after: $after) { + nodes { + id + } + } +} diff --git a/formatter/testdata/baseline/FormatQueryDocument/default/field.graphql b/formatter/testdata/baseline/FormatQueryDocument/default/field.graphql new file mode 100644 index 00000000..7614c27e --- /dev/null +++ b/formatter/testdata/baseline/FormatQueryDocument/default/field.graphql @@ -0,0 +1,3 @@ +query { + bar: foo +} diff --git a/formatter/testdata/baseline/FormatQueryDocument/default/fragment.graphql b/formatter/testdata/baseline/FormatQueryDocument/default/fragment.graphql new file mode 100644 index 00000000..6ecda709 --- /dev/null +++ b/formatter/testdata/baseline/FormatQueryDocument/default/fragment.graphql @@ -0,0 +1,18 @@ +query FooBarQuery ($after: String!) { + fizzList(first: 100, after: $after) { + nodes { + id + ... FooFragment + ... on Foo { + id + } + ... { + id + } + name + } + } +} +fragment FooFragment on Foo { + id +} diff --git a/formatter/testdata/baseline/FormatQueryDocument/default/variable.graphql b/formatter/testdata/baseline/FormatQueryDocument/default/variable.graphql new file mode 100644 index 00000000..3eeec53b --- /dev/null +++ b/formatter/testdata/baseline/FormatQueryDocument/default/variable.graphql @@ -0,0 +1,8 @@ +query ($first: Int = 30, $after: String!) { + searchCats(first: $first, after: $after) { + nodes { + id + name + } + } +} diff --git a/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/basic.graphql b/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/basic.graphql new file mode 100644 index 00000000..16025ccb --- /dev/null +++ b/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/basic.graphql @@ -0,0 +1,7 @@ +query FooBarQuery ($after: String!) { + fizzList(first: 100, after: $after) { + nodes { + id + } + } +} diff --git a/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/field.graphql b/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/field.graphql new file mode 100644 index 00000000..a085ba5d --- /dev/null +++ b/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/field.graphql @@ -0,0 +1,3 @@ +query { + bar: foo +} diff --git a/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/fragment.graphql b/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/fragment.graphql new file mode 100644 index 00000000..535fd13e --- /dev/null +++ b/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/fragment.graphql @@ -0,0 +1,18 @@ +query FooBarQuery ($after: String!) { + fizzList(first: 100, after: $after) { + nodes { + id + ... FooFragment + ... on Foo { + id + } + ... { + id + } + name + } + } +} +fragment FooFragment on Foo { + id +} diff --git a/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/variable.graphql b/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/variable.graphql new file mode 100644 index 00000000..ebdc0a47 --- /dev/null +++ b/formatter/testdata/baseline/FormatQueryDocument/spaceIndent/variable.graphql @@ -0,0 +1,8 @@ +query ($first: Int = 30, $after: String!) { + searchCats(first: $first, after: $after) { + nodes { + id + name + } + } +} diff --git a/formatter/testdata/baseline/FormatSchema/comment.graphql b/formatter/testdata/baseline/FormatSchema/comments/comment.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchema/comment.graphql rename to formatter/testdata/baseline/FormatSchema/comments/comment.graphql diff --git a/formatter/testdata/baseline/FormatSchema/definition.graphql b/formatter/testdata/baseline/FormatSchema/comments/definition.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchema/definition.graphql rename to formatter/testdata/baseline/FormatSchema/comments/definition.graphql diff --git a/formatter/testdata/baseline/FormatSchema/description.graphql b/formatter/testdata/baseline/FormatSchema/comments/description.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchema/description.graphql rename to formatter/testdata/baseline/FormatSchema/comments/description.graphql diff --git a/formatter/testdata/baseline/FormatSchema/directive.graphql b/formatter/testdata/baseline/FormatSchema/comments/directive.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchema/directive.graphql rename to formatter/testdata/baseline/FormatSchema/comments/directive.graphql diff --git a/formatter/testdata/baseline/FormatSchema/directive_locations.graphql b/formatter/testdata/baseline/FormatSchema/comments/directive_locations.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchema/directive_locations.graphql rename to formatter/testdata/baseline/FormatSchema/comments/directive_locations.graphql diff --git a/formatter/testdata/baseline/FormatSchema/extensions.graphql b/formatter/testdata/baseline/FormatSchema/comments/extensions.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchema/extensions.graphql rename to formatter/testdata/baseline/FormatSchema/comments/extensions.graphql diff --git a/formatter/testdata/baseline/FormatSchema/field_definition.graphql b/formatter/testdata/baseline/FormatSchema/comments/field_definition.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchema/field_definition.graphql rename to formatter/testdata/baseline/FormatSchema/comments/field_definition.graphql diff --git a/formatter/testdata/baseline/FormatSchema/schema.graphql b/formatter/testdata/baseline/FormatSchema/comments/schema.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchema/schema.graphql rename to formatter/testdata/baseline/FormatSchema/comments/schema.graphql diff --git a/formatter/testdata/baseline/FormatSchema/swapi.graphql b/formatter/testdata/baseline/FormatSchema/comments/swapi.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchema/swapi.graphql rename to formatter/testdata/baseline/FormatSchema/comments/swapi.graphql diff --git a/formatter/testdata/baseline/FormatSchema/default/comment.graphql b/formatter/testdata/baseline/FormatSchema/default/comment.graphql new file mode 100644 index 00000000..e69de29b diff --git a/formatter/testdata/baseline/FormatSchema/default/definition.graphql b/formatter/testdata/baseline/FormatSchema/default/definition.graphql new file mode 100644 index 00000000..4ef2b4c9 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/default/definition.graphql @@ -0,0 +1,25 @@ +"""Cat0 description""" +scalar Cat0 +type Cat1 { + name: String +} +interface Cat2 { + name: String +} +union Cat3 = Cat3_0 | Cat3_1 | Cat3_2 +type Cat3_0 { + name: String +} +type Cat3_1 { + name: String +} +type Cat3_2 { + name: String +} +enum Cat4 { + NFC + MAINECOON +} +input Cat5 { + name: String +} diff --git a/formatter/testdata/baseline/FormatSchema/default/description.graphql b/formatter/testdata/baseline/FormatSchema/default/description.graphql new file mode 100644 index 00000000..a4dca23f --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/default/description.graphql @@ -0,0 +1,8 @@ +""" +Cat is best kawaii animal in the world. +meow! +""" +type Cat { + """Shiny brillian name.""" + name: String +} diff --git a/formatter/testdata/baseline/FormatSchema/default/directive.graphql b/formatter/testdata/baseline/FormatSchema/default/directive.graphql new file mode 100644 index 00000000..c5835b0b --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/default/directive.graphql @@ -0,0 +1,2 @@ +directive @bar repeatable on FIELD | OBJECT +directive @foo on FIELD | OBJECT diff --git a/formatter/testdata/baseline/FormatSchema/default/directive_locations.graphql b/formatter/testdata/baseline/FormatSchema/default/directive_locations.graphql new file mode 100644 index 00000000..31bf49ec --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/default/directive_locations.graphql @@ -0,0 +1,13 @@ +directive @foo on OBJECT | UNION | ENUM +enum ConnectionStatus @foo { + ONLINE + OFFLINE + ERROR +} +interface Named { + name: String! +} +type Person implements Named @foo { + name: String! +} +union PersonUnion @foo = Person diff --git a/formatter/testdata/baseline/FormatSchema/default/extensions.graphql b/formatter/testdata/baseline/FormatSchema/default/extensions.graphql new file mode 100644 index 00000000..813b4d03 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/default/extensions.graphql @@ -0,0 +1,16 @@ +directive @extends on OBJECT +directive @key(fields: String!) on OBJECT | INTERFACE +directive @permission(permission: String!) on FIELD_DEFINITION +type Dog { + name: String! + owner: Person! @permission(permission: "admin") +} +type Person @key(fields: "name") { + name: String! +} +type Query @extends { + dogs: [Dog!]! +} +type Subscription { + dogEvents: [Dog!]! +} diff --git a/formatter/testdata/baseline/FormatSchema/default/field_definition.graphql b/formatter/testdata/baseline/FormatSchema/default/field_definition.graphql new file mode 100644 index 00000000..4f2a9af7 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/default/field_definition.graphql @@ -0,0 +1,3 @@ +input CatInput { + food: String = "fish & meat" +} diff --git a/formatter/testdata/baseline/FormatSchema/default/schema.graphql b/formatter/testdata/baseline/FormatSchema/default/schema.graphql new file mode 100644 index 00000000..1f6578be --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/default/schema.graphql @@ -0,0 +1,41 @@ +schema { + query: TopQuery + mutation: TopMutation + subscription: TopSubscription +} +type TopMutation { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg: String + ): Boolean +} +type TopQuery { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg: String + ): Boolean +} +type TopSubscription { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg1: String + + """noop3 foo bar""" + arg2: String + ): Boolean +} diff --git a/formatter/testdata/baseline/FormatSchema/default/swapi.graphql b/formatter/testdata/baseline/FormatSchema/default/swapi.graphql new file mode 100644 index 00000000..f2c1aea3 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/default/swapi.graphql @@ -0,0 +1,87 @@ +interface Character { + id: ID! + name: String! + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! +} +input ColorInput { + red: Int! + green: Int! + blue: Int! +} +type Droid implements Character { + id: ID! + name: String! + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! + primaryFunction: String +} +enum Episode { + NEWHOPE + EMPIRE + JEDI +} +type FriendsConnection { + totalCount: Int + edges: [FriendsEdge] + friends: [Character] + pageInfo: PageInfo! +} +type FriendsEdge { + cursor: ID! + node: Character +} +type Human implements Character { + id: ID! + name: String! + homePlanet: String + height(unit: LengthUnit = METER): Float + mass: Float + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! + starships: [Starship] +} +enum LengthUnit { + METER + FOOT +} +type Mutation { + createReview(episode: Episode, review: ReviewInput!): Review +} +type PageInfo { + startCursor: ID + endCursor: ID + hasNextPage: Boolean! +} +type Query { + hero(episode: Episode): Character + reviews(episode: Episode!): [Review] + search(text: String): [SearchResult] + character(id: ID!): Character + droid(id: ID!): Droid + human(id: ID!): Human + starship(id: ID!): Starship +} +type Review { + episode: Episode + stars: Int! + commentary: String +} +input ReviewInput { + stars: Int! + commentary: String + favorite_color: ColorInput +} +union SearchResult = Human | Droid | Starship +type Starship { + id: ID! + name: String! + length(unit: LengthUnit = METER): Float + coordinates: [[Float!]!] +} +type Subscription { + reviewAdded(episode: Episode): Review +} diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/comment.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/comment.graphql new file mode 100644 index 00000000..e69de29b diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/definition.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/definition.graphql new file mode 100644 index 00000000..3ae0afb4 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/spaceIndent/definition.graphql @@ -0,0 +1,25 @@ +"""Cat0 description""" +scalar Cat0 +type Cat1 { + name: String +} +interface Cat2 { + name: String +} +union Cat3 = Cat3_0 | Cat3_1 | Cat3_2 +type Cat3_0 { + name: String +} +type Cat3_1 { + name: String +} +type Cat3_2 { + name: String +} +enum Cat4 { + NFC + MAINECOON +} +input Cat5 { + name: String +} diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/description.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/description.graphql new file mode 100644 index 00000000..c92a66cb --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/spaceIndent/description.graphql @@ -0,0 +1,8 @@ +""" +Cat is best kawaii animal in the world. +meow! +""" +type Cat { + """Shiny brillian name.""" + name: String +} diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/directive.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/directive.graphql new file mode 100644 index 00000000..c5835b0b --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/spaceIndent/directive.graphql @@ -0,0 +1,2 @@ +directive @bar repeatable on FIELD | OBJECT +directive @foo on FIELD | OBJECT diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/directive_locations.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/directive_locations.graphql new file mode 100644 index 00000000..9e14e7d1 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/spaceIndent/directive_locations.graphql @@ -0,0 +1,13 @@ +directive @foo on OBJECT | UNION | ENUM +enum ConnectionStatus @foo { + ONLINE + OFFLINE + ERROR +} +interface Named { + name: String! +} +type Person implements Named @foo { + name: String! +} +union PersonUnion @foo = Person diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/extensions.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/extensions.graphql new file mode 100644 index 00000000..76980d23 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/spaceIndent/extensions.graphql @@ -0,0 +1,16 @@ +directive @extends on OBJECT +directive @key(fields: String!) on OBJECT | INTERFACE +directive @permission(permission: String!) on FIELD_DEFINITION +type Dog { + name: String! + owner: Person! @permission(permission: "admin") +} +type Person @key(fields: "name") { + name: String! +} +type Query @extends { + dogs: [Dog!]! +} +type Subscription { + dogEvents: [Dog!]! +} diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/field_definition.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/field_definition.graphql new file mode 100644 index 00000000..ebbcc8aa --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/spaceIndent/field_definition.graphql @@ -0,0 +1,3 @@ +input CatInput { + food: String = "fish & meat" +} diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/schema.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/schema.graphql new file mode 100644 index 00000000..672b4c81 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/spaceIndent/schema.graphql @@ -0,0 +1,41 @@ +schema { + query: TopQuery + mutation: TopMutation + subscription: TopSubscription +} +type TopMutation { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg: String + ): Boolean +} +type TopQuery { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg: String + ): Boolean +} +type TopSubscription { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg1: String + + """noop3 foo bar""" + arg2: String + ): Boolean +} diff --git a/formatter/testdata/baseline/FormatSchema/spaceIndent/swapi.graphql b/formatter/testdata/baseline/FormatSchema/spaceIndent/swapi.graphql new file mode 100644 index 00000000..19d73542 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchema/spaceIndent/swapi.graphql @@ -0,0 +1,87 @@ +interface Character { + id: ID! + name: String! + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! +} +input ColorInput { + red: Int! + green: Int! + blue: Int! +} +type Droid implements Character { + id: ID! + name: String! + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! + primaryFunction: String +} +enum Episode { + NEWHOPE + EMPIRE + JEDI +} +type FriendsConnection { + totalCount: Int + edges: [FriendsEdge] + friends: [Character] + pageInfo: PageInfo! +} +type FriendsEdge { + cursor: ID! + node: Character +} +type Human implements Character { + id: ID! + name: String! + homePlanet: String + height(unit: LengthUnit = METER): Float + mass: Float + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! + starships: [Starship] +} +enum LengthUnit { + METER + FOOT +} +type Mutation { + createReview(episode: Episode, review: ReviewInput!): Review +} +type PageInfo { + startCursor: ID + endCursor: ID + hasNextPage: Boolean! +} +type Query { + hero(episode: Episode): Character + reviews(episode: Episode!): [Review] + search(text: String): [SearchResult] + character(id: ID!): Character + droid(id: ID!): Droid + human(id: ID!): Human + starship(id: ID!): Starship +} +type Review { + episode: Episode + stars: Int! + commentary: String +} +input ReviewInput { + stars: Int! + commentary: String + favorite_color: ColorInput +} +union SearchResult = Human | Droid | Starship +type Starship { + id: ID! + name: String! + length(unit: LengthUnit = METER): Float + coordinates: [[Float!]!] +} +type Subscription { + reviewAdded(episode: Episode): Review +} diff --git a/formatter/testdata/baseline/FormatSchemaDocument/comment.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/comment.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchemaDocument/comment.graphql rename to formatter/testdata/baseline/FormatSchemaDocument/comments/comment.graphql diff --git a/formatter/testdata/baseline/FormatSchemaDocument/definition.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/definition.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchemaDocument/definition.graphql rename to formatter/testdata/baseline/FormatSchemaDocument/comments/definition.graphql diff --git a/formatter/testdata/baseline/FormatSchemaDocument/description.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/description.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchemaDocument/description.graphql rename to formatter/testdata/baseline/FormatSchemaDocument/comments/description.graphql diff --git a/formatter/testdata/baseline/FormatSchemaDocument/directive.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/directive.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchemaDocument/directive.graphql rename to formatter/testdata/baseline/FormatSchemaDocument/comments/directive.graphql diff --git a/formatter/testdata/baseline/FormatSchemaDocument/directive_locations.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/directive_locations.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchemaDocument/directive_locations.graphql rename to formatter/testdata/baseline/FormatSchemaDocument/comments/directive_locations.graphql diff --git a/formatter/testdata/baseline/FormatSchemaDocument/extensions.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/extensions.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchemaDocument/extensions.graphql rename to formatter/testdata/baseline/FormatSchemaDocument/comments/extensions.graphql diff --git a/formatter/testdata/baseline/FormatSchemaDocument/field_definition.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/field_definition.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchemaDocument/field_definition.graphql rename to formatter/testdata/baseline/FormatSchemaDocument/comments/field_definition.graphql diff --git a/formatter/testdata/baseline/FormatSchemaDocument/schema.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/schema.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchemaDocument/schema.graphql rename to formatter/testdata/baseline/FormatSchemaDocument/comments/schema.graphql diff --git a/formatter/testdata/baseline/FormatSchemaDocument/swapi.graphql b/formatter/testdata/baseline/FormatSchemaDocument/comments/swapi.graphql similarity index 100% rename from formatter/testdata/baseline/FormatSchemaDocument/swapi.graphql rename to formatter/testdata/baseline/FormatSchemaDocument/comments/swapi.graphql diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/comment.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/comment.graphql new file mode 100644 index 00000000..e69de29b diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/definition.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/definition.graphql new file mode 100644 index 00000000..8e221d9c --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/default/definition.graphql @@ -0,0 +1,25 @@ +"""Cat0 description""" +scalar Cat0 +type Cat1 { + name: String +} +interface Cat2 { + name: String +} +type Cat3_0 { + name: String +} +type Cat3_1 { + name: String +} +type Cat3_2 { + name: String +} +union Cat3 = Cat3_0 | Cat3_1 | Cat3_2 +enum Cat4 { + NFC + MAINECOON +} +input Cat5 { + name: String +} diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/description.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/description.graphql new file mode 100644 index 00000000..a4dca23f --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/default/description.graphql @@ -0,0 +1,8 @@ +""" +Cat is best kawaii animal in the world. +meow! +""" +type Cat { + """Shiny brillian name.""" + name: String +} diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/directive.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/directive.graphql new file mode 100644 index 00000000..6bbffa83 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/default/directive.graphql @@ -0,0 +1,2 @@ +directive @foo on FIELD | OBJECT +directive @bar repeatable on FIELD | OBJECT diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/directive_locations.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/directive_locations.graphql new file mode 100644 index 00000000..26bd869d --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/default/directive_locations.graphql @@ -0,0 +1,13 @@ +directive @foo on OBJECT | UNION | ENUM +interface Named { + name: String! +} +type Person implements Named @foo { + name: String! +} +enum ConnectionStatus @foo { + ONLINE + OFFLINE + ERROR +} +union PersonUnion @foo = Person diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/extensions.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/extensions.graphql new file mode 100644 index 00000000..225694f8 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/default/extensions.graphql @@ -0,0 +1,24 @@ +schema { + query: Query +} +extend schema { + subscription: Subscription +} +directive @permission(permission: String!) on FIELD_DEFINITION +directive @extends on OBJECT +directive @key(fields: String!) on OBJECT | INTERFACE +type Query @extends { + dogs: [Dog!]! +} +type Subscription { + dogEvents: [Dog!]! +} +type Dog { + name: String! +} +type Person @key(fields: "name") { + name: String! +} +extend type Dog { + owner: Person! @permission(permission: "admin") +} diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/field_definition.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/field_definition.graphql new file mode 100644 index 00000000..4f2a9af7 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/default/field_definition.graphql @@ -0,0 +1,3 @@ +input CatInput { + food: String = "fish & meat" +} diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/schema.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/schema.graphql new file mode 100644 index 00000000..a23db802 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/default/schema.graphql @@ -0,0 +1,42 @@ +"""schema description""" +schema { + query: TopQuery + mutation: TopMutation + subscription: TopSubscription +} +type TopMutation { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg: String + ): Boolean +} +type TopQuery { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg: String + ): Boolean +} +type TopSubscription { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg1: String + + """noop3 foo bar""" + arg2: String + ): Boolean +} diff --git a/formatter/testdata/baseline/FormatSchemaDocument/default/swapi.graphql b/formatter/testdata/baseline/FormatSchemaDocument/default/swapi.graphql new file mode 100644 index 00000000..357f8f57 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/default/swapi.graphql @@ -0,0 +1,92 @@ +schema { + query: Query + mutation: Mutation + subscription: Subscription +} +type Query { + hero(episode: Episode): Character + reviews(episode: Episode!): [Review] + search(text: String): [SearchResult] + character(id: ID!): Character + droid(id: ID!): Droid + human(id: ID!): Human + starship(id: ID!): Starship +} +type Mutation { + createReview(episode: Episode, review: ReviewInput!): Review +} +type Subscription { + reviewAdded(episode: Episode): Review +} +enum Episode { + NEWHOPE + EMPIRE + JEDI +} +interface Character { + id: ID! + name: String! + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! +} +enum LengthUnit { + METER + FOOT +} +type Human implements Character { + id: ID! + name: String! + homePlanet: String + height(unit: LengthUnit = METER): Float + mass: Float + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! + starships: [Starship] +} +type Droid implements Character { + id: ID! + name: String! + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! + primaryFunction: String +} +type FriendsConnection { + totalCount: Int + edges: [FriendsEdge] + friends: [Character] + pageInfo: PageInfo! +} +type FriendsEdge { + cursor: ID! + node: Character +} +type PageInfo { + startCursor: ID + endCursor: ID + hasNextPage: Boolean! +} +type Review { + episode: Episode + stars: Int! + commentary: String +} +input ReviewInput { + stars: Int! + commentary: String + favorite_color: ColorInput +} +input ColorInput { + red: Int! + green: Int! + blue: Int! +} +type Starship { + id: ID! + name: String! + length(unit: LengthUnit = METER): Float + coordinates: [[Float!]!] +} +union SearchResult = Human | Droid | Starship diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/comment.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/comment.graphql new file mode 100644 index 00000000..e69de29b diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/definition.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/definition.graphql new file mode 100644 index 00000000..3dbb9400 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/definition.graphql @@ -0,0 +1,25 @@ +"""Cat0 description""" +scalar Cat0 +type Cat1 { + name: String +} +interface Cat2 { + name: String +} +type Cat3_0 { + name: String +} +type Cat3_1 { + name: String +} +type Cat3_2 { + name: String +} +union Cat3 = Cat3_0 | Cat3_1 | Cat3_2 +enum Cat4 { + NFC + MAINECOON +} +input Cat5 { + name: String +} diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/description.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/description.graphql new file mode 100644 index 00000000..c92a66cb --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/description.graphql @@ -0,0 +1,8 @@ +""" +Cat is best kawaii animal in the world. +meow! +""" +type Cat { + """Shiny brillian name.""" + name: String +} diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/directive.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/directive.graphql new file mode 100644 index 00000000..6bbffa83 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/directive.graphql @@ -0,0 +1,2 @@ +directive @foo on FIELD | OBJECT +directive @bar repeatable on FIELD | OBJECT diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/directive_locations.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/directive_locations.graphql new file mode 100644 index 00000000..488c2c5d --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/directive_locations.graphql @@ -0,0 +1,13 @@ +directive @foo on OBJECT | UNION | ENUM +interface Named { + name: String! +} +type Person implements Named @foo { + name: String! +} +enum ConnectionStatus @foo { + ONLINE + OFFLINE + ERROR +} +union PersonUnion @foo = Person diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/extensions.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/extensions.graphql new file mode 100644 index 00000000..6a7006eb --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/extensions.graphql @@ -0,0 +1,24 @@ +schema { + query: Query +} +extend schema { + subscription: Subscription +} +directive @permission(permission: String!) on FIELD_DEFINITION +directive @extends on OBJECT +directive @key(fields: String!) on OBJECT | INTERFACE +type Query @extends { + dogs: [Dog!]! +} +type Subscription { + dogEvents: [Dog!]! +} +type Dog { + name: String! +} +type Person @key(fields: "name") { + name: String! +} +extend type Dog { + owner: Person! @permission(permission: "admin") +} diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/field_definition.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/field_definition.graphql new file mode 100644 index 00000000..ebbcc8aa --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/field_definition.graphql @@ -0,0 +1,3 @@ +input CatInput { + food: String = "fish & meat" +} diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/schema.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/schema.graphql new file mode 100644 index 00000000..f4db1698 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/schema.graphql @@ -0,0 +1,42 @@ +"""schema description""" +schema { + query: TopQuery + mutation: TopMutation + subscription: TopSubscription +} +type TopMutation { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg: String + ): Boolean +} +type TopQuery { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg: String + ): Boolean +} +type TopSubscription { + noop: Boolean + noop2( + """noop2 foo bar""" + arg: String + ): Boolean + noop3( + """noop3 foo bar""" + arg1: String + + """noop3 foo bar""" + arg2: String + ): Boolean +} diff --git a/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/swapi.graphql b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/swapi.graphql new file mode 100644 index 00000000..ac5c25b8 --- /dev/null +++ b/formatter/testdata/baseline/FormatSchemaDocument/spaceIndent/swapi.graphql @@ -0,0 +1,92 @@ +schema { + query: Query + mutation: Mutation + subscription: Subscription +} +type Query { + hero(episode: Episode): Character + reviews(episode: Episode!): [Review] + search(text: String): [SearchResult] + character(id: ID!): Character + droid(id: ID!): Droid + human(id: ID!): Human + starship(id: ID!): Starship +} +type Mutation { + createReview(episode: Episode, review: ReviewInput!): Review +} +type Subscription { + reviewAdded(episode: Episode): Review +} +enum Episode { + NEWHOPE + EMPIRE + JEDI +} +interface Character { + id: ID! + name: String! + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! +} +enum LengthUnit { + METER + FOOT +} +type Human implements Character { + id: ID! + name: String! + homePlanet: String + height(unit: LengthUnit = METER): Float + mass: Float + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! + starships: [Starship] +} +type Droid implements Character { + id: ID! + name: String! + friends: [Character] + friendsConnection(first: Int, after: ID): FriendsConnection! + appearsIn: [Episode]! + primaryFunction: String +} +type FriendsConnection { + totalCount: Int + edges: [FriendsEdge] + friends: [Character] + pageInfo: PageInfo! +} +type FriendsEdge { + cursor: ID! + node: Character +} +type PageInfo { + startCursor: ID + endCursor: ID + hasNextPage: Boolean! +} +type Review { + episode: Episode + stars: Int! + commentary: String +} +input ReviewInput { + stars: Int! + commentary: String + favorite_color: ColorInput +} +input ColorInput { + red: Int! + green: Int! + blue: Int! +} +type Starship { + id: ID! + name: String! + length(unit: LengthUnit = METER): Float + coordinates: [[Float!]!] +} +union SearchResult = Human | Droid | Starship