Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for #487 #538

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.