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