1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
package graphql_test
import (
"testing"
"github.com/graph-gophers/graphql-go"
)
func TestSchemaEmptyTypeDefinitions(t *testing.T) {
cases := []struct {
name string
sdl string
wantErr bool
}{
{
name: "empty object type",
sdl: `type Query { dummy: Int } type Empty { }`,
wantErr: true,
},
{
name: "empty interface type",
sdl: `type Query { dummy: Int } interface EmptyInterface { }`,
wantErr: true,
},
{
name: "empty input object type",
sdl: `type Query { dummy(arg: EmptyInput): Int } input EmptyInput { }`,
wantErr: true,
},
{
name: "valid types (controls)",
sdl: `type Query { dummy: Int } interface Node { id: ID! } input Something { v: Int }`,
wantErr: false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
_, err := graphql.ParseSchema(tc.sdl, nil)
if tc.wantErr && err == nil {
t.Fatalf("expected error for %s, got none", tc.name)
}
if !tc.wantErr && err != nil {
t.Fatalf("unexpected error for %s: %v", tc.name, err)
}
})
}
}
|