Skip to content

Commit

Permalink
Merge pull request 99designs#538 from 99designs/test-input-marshalling
Browse files Browse the repository at this point in the history
Test for 99designs#487
  • Loading branch information
vektah authored Feb 7, 2019
2 parents b6afaa9 + 0c9663a commit 96fe566
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 0 deletions.
100 changes: 100 additions & 0 deletions codegen/testserver/generated.go

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

34 changes: 34 additions & 0 deletions codegen/testserver/input_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package testserver

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

"github.com/99designs/gqlgen/client"
"github.com/99designs/gqlgen/handler"
"github.com/stretchr/testify/require"
)

func TestInput(t *testing.T) {
resolvers := &Stub{}

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

c := client.New(srv.URL)

t.Run("when function errors on directives", func(t *testing.T) {
resolvers.QueryResolver.InputSlice = func(ctx context.Context, arg []string) (b bool, e error) {
return true, nil
}

var resp struct {
DirectiveArg *string
}

err := c.Post(`query { inputSlice(arg: ["ok", 1, 2, "ok"]) }`, &resp)

require.EqualError(t, err, `http 422: {"errors":[{"message":"Expected type String!, found 1.","locations":[{"line":1,"column":32}]},{"message":"Expected type String!, found 2.","locations":[{"line":1,"column":35}]}],"data":null}`)
require.Nil(t, resp.DirectiveArg)
})
}
3 changes: 3 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func (r *queryResolver) DirectiveInputNullable(ctx context.Context, arg *InputDi
func (r *queryResolver) DirectiveInput(ctx context.Context, arg InputDirectives) (*string, error) {
panic("not implemented")
}
func (r *queryResolver) InputSlice(ctx context.Context, arg []string) (bool, 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 @@ -16,6 +16,7 @@ type Query {
directiveNullableArg(arg: Int @range(min:0), arg2: Int @range): String
directiveInputNullable(arg: InputDirectives): String
directiveInput(arg: InputDirectives!): String
inputSlice(arg: [String!]!): Boolean!
}

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 96fe566

Please sign in to comment.