forked from 99designs/gqlgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_test.go
57 lines (48 loc) · 1.28 KB
/
input_test.go
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
49
50
51
52
53
54
55
56
57
package codegen
import (
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/tools/go/loader"
)
func TestTypeUnionAsInput(t *testing.T) {
err := generate("inputunion", `
type Query {
addBookmark(b: Bookmarkable!): Boolean!
}
type Item {}
union Bookmarkable = Item
`)
require.EqualError(t, err, "model plan failed: Bookmarkable! cannot be used as argument of Query.addBookmark. only input and scalar types are allowed")
}
func TestTypeInInput(t *testing.T) {
err := generate("typeinput", `
type Query {
addBookmark(b: BookmarkableInput!): Boolean!
}
type Item {}
input BookmarkableInput {
item: Item
}
`)
require.EqualError(t, err, "model plan failed: Item cannot be used as a field of BookmarkableInput. only input and scalar types are allowed")
}
func generate(name string, schema string, typemap ...TypeMap) error {
cfg := Config{
SchemaStr: schema,
Exec: PackageConfig{Filename: "gen/" + name + "/exec.go"},
Model: PackageConfig{Filename: "gen/" + name + "/model.go"},
}
if len(typemap) > 0 {
cfg.Models = typemap[0]
}
err := Generate(cfg)
if err == nil {
conf := loader.Config{}
conf.Import("github.com/99designs/gqlgen/codegen/testdata/gen/" + name)
_, err = conf.Load()
if err != nil {
panic(err)
}
}
return err
}