Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gracenoah committed Nov 13, 2018
1 parent 9862c30 commit 8066edb
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 1 deletion.
212 changes: 212 additions & 0 deletions codegen/testserver/generated.go

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

26 changes: 26 additions & 0 deletions codegen/testserver/generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,29 @@ func TestTracer(t *testing.T) {
require.NoError(t, err)
require.True(t, called)
})

t.Run("model methods", func(t *testing.T) {
t.Run("without context", func(t *testing.T) {
var resp struct {
ModelMethods struct {
NoContext bool
}
}
err := c.Post(`query { modelMethods{ noContext } }`, &resp)
require.NoError(t, err)
require.True(t, resp.ModelMethods.NoContext)
})
t.Run("with context", func(t *testing.T) {
var resp struct {
ModelMethods struct {
WithContext bool
}
}
err := c.Post(`query { modelMethods{ withContext } }`, &resp)
require.NoError(t, err)
require.True(t, resp.ModelMethods.WithContext)
})
})
}

func TestResponseExtension(t *testing.T) {
Expand Down Expand Up @@ -556,6 +579,9 @@ func (r *testResolver) User() UserResolver {
func (r *testResolver) Query() QueryResolver {
return &testQueryResolver{}
}
func (r *testResolver) ModelMethods() ModelMethodsResolver {
return &modelMethodsResolver{}
}

type testQueryResolver struct{ queryResolver }

Expand Down
2 changes: 2 additions & 0 deletions codegen/testserver/gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ resolver:
models:
It:
model: "github.com/99designs/gqlgen/codegen/testserver/introspection.It"
ModelMethods:
model: "github.com/99designs/gqlgen/codegen/testserver.ModelMethods"
InvalidIdentifier:
model: "github.com/99designs/gqlgen/codegen/testserver/invalid-packagename.InvalidIdentifier"
Changes:
Expand Down
16 changes: 15 additions & 1 deletion codegen/testserver/models.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
package testserver

import "fmt"
import (
context "context"
"fmt"
)

type ForcedResolver struct {
Field Circle
}

type ModelMethods struct {
}

func (m ModelMethods) NoContext() bool {
return true
}

func (m ModelMethods) WithContext(_ context.Context) bool {
return true
}

type Error struct {
ID string
}
Expand Down
12 changes: 12 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ func (r *Resolver) Subscription() SubscriptionResolver {
func (r *Resolver) User() UserResolver {
return &userResolver{r}
}
func (r *Resolver) ModelMethods() ModelMethodsResolver {
return &modelMethodsResolver{}
}

type modelMethodsResolver struct{}

func (r *modelMethodsResolver) ResolverField(ctx context.Context, obj *ModelMethods) (bool, error) {
return true, nil
}

type forcedResolverResolver struct{ *Resolver }

Expand Down Expand Up @@ -68,6 +77,9 @@ func (r *queryResolver) User(ctx context.Context, id int) (User, error) {
func (r *queryResolver) NullableArg(ctx context.Context, arg *int) (*string, error) {
panic("not implemented")
}
func (r *queryResolver) ModelMethods(ctx context.Context) (*ModelMethods, error) {
return &ModelMethods{}, nil
}
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
Loading

0 comments on commit 8066edb

Please sign in to comment.