Skip to content

Commit

Permalink
Add reproducable test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathew Byrne committed Feb 7, 2019
1 parent f81c61d commit efe8b02
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
49 changes: 49 additions & 0 deletions codegen/testserver/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions codegen/testserver/generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
package testserver

import (
"context"
"net/http"
"net/http/httptest"
"reflect"
"testing"

"github.com/99designs/gqlgen/client"
"github.com/99designs/gqlgen/handler"
"github.com/stretchr/testify/require"
)
Expand All @@ -30,3 +33,51 @@ func TestEnums(t *testing.T) {
require.Equal(t, StatusError, AllStatus[1])
})
}

func TestUnionFragments(t *testing.T) {
resolvers := &Stub{}
resolvers.QueryResolver.ShapeUnion = func(ctx context.Context) (ShapeUnion, error) {
return &Circle{Radius: 32}, nil
}

srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{Resolvers: resolvers})))
c := client.New(srv.URL)

t.Run("inline fragment on union", func(t *testing.T) {
var resp struct {
ShapeUnion struct {
Radius float64
}
}
c.MustPost(`query {
shapeUnion {
... on Circle {
radius
}
}
}
`, &resp)
require.NotEmpty(t, resp.ShapeUnion.Radius)
})

t.Run("named fragment", func(t *testing.T) {
var resp struct {
ShapeUnion struct {
Radius float64
}
}
c.MustPost(`query {
shapeUnion {
...C
}
}
fragment C on ShapeUnion {
... on Circle {
radius
}
}
`, &resp)
require.NotEmpty(t, resp.ShapeUnion.Radius)
})
}
3 changes: 3 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func (r *queryResolver) DirectiveInput(ctx context.Context, arg InputDirectives)
func (r *queryResolver) InputSlice(ctx context.Context, arg []string) (bool, error) {
panic("not implemented")
}
func (r *queryResolver) ShapeUnion(ctx context.Context) (ShapeUnion, error) {
panic("not implemented")
}
func (r *queryResolver) KeywordArgs(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) {
panic("not implemented")
}
Expand Down
1 change: 1 addition & 0 deletions codegen/testserver/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Query {
directiveInputNullable(arg: InputDirectives): String
directiveInput(arg: InputDirectives!): String
inputSlice(arg: [String!]!): Boolean!
shapeUnion: ShapeUnion!
}

type Subscription {
Expand Down
4 changes: 4 additions & 0 deletions codegen/testserver/stub.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit efe8b02

Please sign in to comment.