forked from graph-gophers/graphql-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce exec middleware for schema
Signed-off-by: Krzysztof Niepokojczycki <[email protected]>
- Loading branch information
Showing
3 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package graphql | ||
|
||
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 | ||
|
||
// 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 { | ||
// perform the original query | ||
response := next(ctx, queryString, operationName, variables, res) | ||
// mutate the errors | ||
response.Errors = parseErrors(response.Errors) | ||
// return the response | ||
return response | ||
} | ||
} | ||
} |