-
Notifications
You must be signed in to change notification settings - Fork 12
/
graph_server_mocked.go
30 lines (25 loc) · 1.01 KB
/
graph_server_mocked.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package test
import (
"context"
"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/gin-gonic/gin"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api-sdk/graph/generated"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api-sdk/graph/resolver"
"github.com/vektah/gqlparser/v2/gqlerror"
)
func GraphServerMocked() (gin.HandlerFunc, *resolver.Resolver) {
r := &resolver.Resolver{}
srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: r}))
srv.SetRecoverFunc(func(ctx context.Context, err interface{}) error {
return gqlerror.Errorf("Internal server error! %v ", err)
})
srv.SetErrorPresenter(func(ctx context.Context, e error) *gqlerror.Error {
err := graphql.DefaultErrorPresenter(ctx, e)
// Error hook place, Returned error can be customized. Check https://gqlgen.com/reference/errors/
return err
})
return func(c *gin.Context) {
srv.ServeHTTP(c.Writer, c.Request)
}, r
}