Skip to content

Commit

Permalink
Merge pull request #664 from luraproject/log_when_bad_graphql_config_…
Browse files Browse the repository at this point in the history
…found

Log error when bad graphql config is provided
  • Loading branch information
kpacha authored May 29, 2023
2 parents 91e3fc7 + 0b6d1d2 commit 8d86f07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions proxy/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (
func NewGraphQLMiddleware(logger logging.Logger, remote *config.Backend) Middleware {
opt, err := graphql.GetOptions(remote.ExtraConfig)
if err != nil {
if err != graphql.ErrNoConfigFound {
logger.Warning(
fmt.Sprintf("[BACKEND: %s][GraphQL] %s", remote.URLPattern, err.Error()))
}
return EmptyMiddleware
}

Expand Down
9 changes: 5 additions & 4 deletions transport/http/client/graphql/graphql.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0

/*
Package graphql offers a param extractor and basic types for building GraphQL requests
Package graphql offers a param extractor and basic types for building GraphQL requests
*/
package graphql

Expand Down Expand Up @@ -53,13 +53,13 @@ type Options struct {
Method OperationMethod `json:"method"`
}

var errNoConfigFound = errors.New("grapghql: no configuration found")
var ErrNoConfigFound = errors.New("grapghql: no configuration found")

// GetOptions extracts the Options config from the backend's extra config
func GetOptions(cfg config.ExtraConfig) (*Options, error) {
tmp, ok := cfg[Namespace]
if !ok {
return nil, errNoConfigFound
return nil, ErrNoConfigFound
}

b, err := json.Marshal(tmp)
Expand Down Expand Up @@ -92,7 +92,8 @@ func GetOptions(cfg config.ExtraConfig) (*Options, error) {

// New resturns a new Extractor, ready to be use on a middleware
func New(opt Options) *Extractor {
replacements := [][2]string{}
var replacements [][2]string

title := cases.Title(language.Und)
for k, v := range opt.Variables {
val, ok := v.(string)
Expand Down

0 comments on commit 8d86f07

Please sign in to comment.