~netlandish/gobwebs-graphql

adfac6aa2e952c90a9756200877a9ed0a3ebd330 — Peter Sanchez 3 months ago 3adf35e
Making handler paths customizable
1 files changed, 16 insertions(+), 10 deletions(-)

M graphql.go
M graphql.go => graphql.go +16 -10
@@ 30,6 30,10 @@ type GraphQL struct {
	Scopes        []string
	MaxComplexity int
	MaxUploadSize int

	QueryPath      string
	ScopesPath     string
	PlaygroundPath string
}

type GQLExtension struct {


@@ 81,23 85,25 @@ func (g *GQLExtension) Extend(gserver *server.Server) (*server.Server, error) {
	srv.SetRecoverFunc(g.gqlEmailRecover)
	srv.Use(extension.FixedComplexityLimit(g.GQL.MaxComplexity))

	qroute := g.eg.POST("/query", func(c echo.Context) error {
	qroute := g.eg.POST(g.GQL.QueryPath, func(c echo.Context) error {
		// Hate this...
		ctx := server.EchoContext(c.Request().Context(), c)
		c.SetRequest(c.Request().WithContext(ctx))
		srv.ServeHTTP(c.Response(), c.Request())
		return nil
	})
	g.eg.GET("/query/api-scopes.json", func(c echo.Context) error {
		info := struct {
			Scopes []string `json:"scopes"`
		}{g.GQL.Scopes}
	if g.GQL.ScopesPath != "" {
		g.eg.GET(g.GQL.ScopesPath, func(c echo.Context) error {
			info := struct {
				Scopes []string `json:"scopes"`
			}{g.GQL.Scopes}

		return c.JSON(http.StatusOK, &info)
	})
	if g.s.Config.Debug {
			return c.JSON(http.StatusOK, &info)
		})
	}
	if g.GQL.PlaygroundPath != "" {
		// If debug is set, add a handler for the default playground
		g.eg.GET("/graphql-debug", func(c echo.Context) error {
		g.eg.GET(g.GQL.PlaygroundPath, func(c echo.Context) error {
			// Hate this...
			ctx := server.EchoContext(c.Request().Context(), c)
			c.SetRequest(c.Request().WithContext(ctx))


@@ 210,6 216,6 @@ The following stack trace was produced:

// NewGQLExtension will return a GQLExtension that can be passed to a gobwebs server
func NewGQLExtension(eg *echo.Group, schema graphql.ExecutableSchema, scopes []string) *GQLExtension {
	gql := &GraphQL{Schema: schema, Scopes: scopes}
	gql := &GraphQL{Schema: schema, Scopes: scopes, QueryPath: "/query"}
	return &GQLExtension{GQL: gql, eg: eg}
}