diff --git a/graphql.go b/graphql.go index a2f04b5e..bd303da3 100644 --- a/graphql.go +++ b/graphql.go @@ -290,11 +290,13 @@ func (s *Schema) Exec(ctx context.Context, queryString string, operationName str if !s.res.QueryResolver.IsValid() { panic("schema created without resolver, can not exec") } - execF := s.exec + var execF Exec = func(ctx context.Context, queryString string, operationName string, variables map[string]interface{}) *Response { + return s.exec(ctx, queryString, operationName, variables, s.res) + } for _, m := range s.middlewares { execF = m(execF) } - return execF(ctx, queryString, operationName, variables, s.res) + return execF(ctx, queryString, operationName, variables) } func (s *Schema) exec(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) *Response { diff --git a/graphql_test.go b/graphql_test.go index 92577335..2621113b 100644 --- a/graphql_test.go +++ b/graphql_test.go @@ -11,7 +11,6 @@ import ( "github.com/graph-gophers/graphql-go/example/social" "github.com/graph-gophers/graphql-go/example/starwars" "github.com/graph-gophers/graphql-go/gqltesting" - "github.com/graph-gophers/graphql-go/internal/exec/resolvable" "github.com/graph-gophers/graphql-go/introspection" "github.com/graph-gophers/graphql-go/trace/tracer" "strings" @@ -4712,15 +4711,15 @@ func TestMiddlewares_In_Exec(t *testing.T) { `, r, graphql.WithMiddlewares( func(next graphql.Exec) graphql.Exec { - return func(ctx context.Context, q string, o string, v map[string]interface{}, r *resolvable.Schema) *graphql.Response { + return func(ctx context.Context, q string, o string, v map[string]interface{}) *graphql.Response { m1Called = true - return next(ctx, q, o, v, r) + return next(ctx, q, o, v) } }, func(next graphql.Exec) graphql.Exec { - return func(ctx context.Context, q string, o string, v map[string]interface{}, r *resolvable.Schema) *graphql.Response { + return func(ctx context.Context, q string, o string, v map[string]interface{}) *graphql.Response { m2Called = true - return next(ctx, q, o, v, r) + return next(ctx, q, o, v) } }, ), diff --git a/middleware.go b/middleware.go index 8f0a45c8..3a7989f9 100644 --- a/middleware.go +++ b/middleware.go @@ -4,20 +4,19 @@ import ( "context" "github.com/graph-gophers/graphql-go/errors" - "github.com/graph-gophers/graphql-go/internal/exec/resolvable" ) // Exec executes the given query with the schema's resolver. -type Exec func(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) *Response +type Exec func(ctx context.Context, queryString string, operationName string, variables map[string]interface{}) *Response // Middleware can wrap Exec to add additional behaviour type Middleware func(next Exec) Exec func ParseErrorsMiddleware(parseErrors func([]*errors.QueryError) []*errors.QueryError) Middleware { return func(next Exec) Exec { - return func(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) *Response { + return func(ctx context.Context, queryString string, operationName string, variables map[string]interface{}) *Response { // perform the original query - response := next(ctx, queryString, operationName, variables, res) + response := next(ctx, queryString, operationName, variables) // mutate the errors response.Errors = parseErrors(response.Errors) // return the response @@ -30,12 +29,12 @@ func ParseErrorsMiddleware(parseErrors func([]*errors.QueryError) []*errors.Quer // If no response is returned, we simply continue by calling next(). func InspectInputMiddleware(inspectInput func(queryString string, operationName string, variables map[string]interface{}) *Response) Middleware { return func(next Exec) Exec { - return func(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) *Response { + return func(ctx context.Context, queryString string, operationName string, variables map[string]interface{}) *Response { if response := inspectInput(queryString, operationName, variables); response != nil { return response } - return next(ctx, queryString, operationName, variables, res) + return next(ctx, queryString, operationName, variables) } } }