...
1
2
3
4 package followschema
5
6 import (
7 "context"
8 "reflect"
9 "testing"
10
11 "github.com/stretchr/testify/require"
12
13 "github.com/99designs/gqlgen/client"
14 "github.com/99designs/gqlgen/graphql/handler"
15 )
16
17 func TestForcedResolverFieldIsPointer(t *testing.T) {
18 field, ok := reflect.TypeOf((*ForcedResolverResolver)(nil)).Elem().MethodByName("Field")
19 require.True(t, ok)
20 require.Equal(t, "*followschema.Circle", field.Type.Out(0).String())
21 }
22
23 func TestEnums(t *testing.T) {
24 t.Run("list of enums", func(t *testing.T) {
25 require.Equal(t, StatusOk, AllStatus[0])
26 require.Equal(t, StatusError, AllStatus[1])
27 })
28
29 t.Run("invalid enum values", func(t *testing.T) {
30 require.Equal(t, StatusOk, AllStatus[0])
31 require.Equal(t, StatusError, AllStatus[1])
32 })
33 }
34
35 func TestUnionFragments(t *testing.T) {
36 resolvers := &Stub{}
37 resolvers.QueryResolver.ShapeUnion = func(ctx context.Context) (ShapeUnion, error) {
38 return &Circle{Radius: 32}, nil
39 }
40
41 srv := handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolvers}))
42 c := client.New(srv)
43
44 t.Run("inline fragment on union", func(t *testing.T) {
45 var resp struct {
46 ShapeUnion struct {
47 Radius float64
48 }
49 }
50 c.MustPost(`query {
51 shapeUnion {
52 ... on Circle {
53 radius
54 }
55 }
56 }
57 `, &resp)
58 require.NotEmpty(t, resp.ShapeUnion.Radius)
59 })
60
61 t.Run("named fragment", func(t *testing.T) {
62 var resp struct {
63 ShapeUnion struct {
64 Radius float64
65 }
66 }
67 c.MustPost(`query {
68 shapeUnion {
69 ...C
70 }
71 }
72
73 fragment C on ShapeUnion {
74 ... on Circle {
75 radius
76 }
77 }
78 `, &resp)
79 require.NotEmpty(t, resp.ShapeUnion.Radius)
80 })
81 }
82
View as plain text