forked from graph-gophers/graphql-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate multiple inherited interfaces with
&
This replaces: ```graphql type Foo implements Bar, Baz { field: Type } ``` With: ```graphql type Foo implements Bar & Baz { field: Type } ``` This is more consistent with other trailing lists of values which either have an explicit separator (union members) or are prefixed with a sigil (directives). This avoids parse ambiguity in the case of an omitted field set, illustrated by [github.com/graphql/graphql-js#1166](graphql/graphql-js#1166). For now, the old method of declaration remains valid. References: - graphql/graphql-js#1169 - graphql/graphql-spec#90 - graphql/graphql-spec@32b55ed
- Loading branch information
Showing
4 changed files
with
89 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package schema | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"text/scanner" | ||
|
||
"github.com/graph-gophers/graphql-go/internal/common" | ||
) | ||
|
||
type testCase struct { | ||
description string | ||
declaration string | ||
expected *Object | ||
} | ||
|
||
func TestParseObjectDeclaration(t *testing.T) { | ||
tests := []testCase{ | ||
{ | ||
"allows '&' separator", | ||
"Alien implements Being & Intelligent { name: String, iq: Int }", | ||
&Object{ | ||
Name: "Alien", | ||
interfaceNames: []string{"Being", "Intelligent"}, | ||
}, | ||
}, | ||
{ | ||
"allows legacy ',' separator", | ||
"Alien implements Being, Intelligent { name: String, iq: Int }", | ||
&Object{ | ||
Name: "Alien", | ||
interfaceNames: []string{"Being", "Intelligent"}, | ||
}, | ||
}, | ||
} | ||
|
||
setup := func(schema string) *common.Lexer { | ||
sc := &scanner.Scanner{ | ||
Mode: scanner.ScanIdents | scanner.ScanInts | scanner.ScanFloats | scanner.ScanStrings, | ||
} | ||
sc.Init(strings.NewReader(schema)) | ||
return common.NewLexer(sc) | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.description, func(t *testing.T) { | ||
lex := setup(test.declaration) | ||
var actual *Object | ||
|
||
parse := func() { actual = parseObjectDeclaration(lex) } | ||
if err := lex.CatchSyntaxError(parse); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if test.expected.Name != actual.Name { | ||
t.Errorf("wrong object name: want %q, got %q", test.expected.Name, actual.Name) | ||
} | ||
|
||
if len(test.expected.interfaceNames) != len(actual.interfaceNames) { | ||
t.Fatalf("wrong number of interface names: want %s, got %s", test.expected.interfaceNames, actual.interfaceNames) | ||
} | ||
|
||
for i, expectedName := range test.expected.interfaceNames { | ||
actualName := actual.interfaceNames[i] | ||
if expectedName != actualName { | ||
t.Errorf("wrong interface name: want %q, got %q", expectedName, actualName) | ||
} | ||
} | ||
}) | ||
} | ||
} |