git.sr.ht/~sircmpwn/gqlgen@v0.0.0-20200522192042-c84d29a1c940/codegen/testserver/input_test.go (about) 1 package testserver 2 3 import ( 4 "context" 5 "testing" 6 7 "git.sr.ht/~sircmpwn/gqlgen/client" 8 "git.sr.ht/~sircmpwn/gqlgen/graphql/handler" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestInput(t *testing.T) { 13 resolvers := &Stub{} 14 srv := handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolvers})) 15 c := client.New(srv) 16 17 t.Run("when function errors on directives", func(t *testing.T) { 18 resolvers.QueryResolver.InputSlice = func(ctx context.Context, arg []string) (b bool, e error) { 19 return true, nil 20 } 21 22 var resp struct { 23 DirectiveArg *string 24 } 25 26 err := c.Post(`query { inputSlice(arg: ["ok", 1, 2, "ok"]) }`, &resp) 27 28 require.EqualError(t, err, `http 422: {"errors":[{"message":"Expected type String!, found 1.","locations":[{"line":1,"column":32}],"extensions":{"code":"GRAPHQL_VALIDATION_FAILED"}},{"message":"Expected type String!, found 2.","locations":[{"line":1,"column":35}],"extensions":{"code":"GRAPHQL_VALIDATION_FAILED"}}],"data":null}`) 29 require.Nil(t, resp.DirectiveArg) 30 }) 31 }