Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions v2/pkg/engine/resolve/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package resolve

import "errors"

const (
locationsField = "locations"
)

var (
lBrace = []byte("{")
rBrace = []byte("}")
Expand All @@ -16,7 +20,7 @@ var (
literalFalse = []byte("false")
literalErrors = []byte("errors")
literalMessage = []byte("message")
literalLocations = []byte("locations")
literalLocations = []byte(locationsField)
literalPath = []byte("path")
literalUnderscoreEntities = []byte("_entities")
literalExtensions = []byte("extensions")
Expand All @@ -35,19 +39,3 @@ var (
errHeaderPathInvalid = errors.New("invalid header path: header variables must be of this format: .request.header.{{ key }} ")
ErrUnableToResolve = errors.New("unable to resolve operation")
)

var (
Comment thread
SkArchon marked this conversation as resolved.
errorPaths = [][]string{
{"message"},
{"locations"},
{"path"},
{"extensions"},
}
)

const (
errorsMessagePathIndex = 0
errorsLocationsPathIndex = 1
errorsPathPathIndex = 2
errorsExtensionsPathIndex = 3
)
36 changes: 31 additions & 5 deletions v2/pkg/engine/resolve/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,12 +936,38 @@ func (l *Loader) optionallyOmitErrorFields(values []*astjson.Value) {

// optionallyOmitErrorLocations removes the "locations" object from all values.
func (l *Loader) optionallyOmitErrorLocations(values []*astjson.Value) {
if !l.omitSubgraphErrorLocations {
return
}
arena := astjson.Arena{}

for _, value := range values {
if value.Exists("locations") {
value.Del("locations")
// If the flag is set, delete all locations
if !value.Exists(locationsField) || l.omitSubgraphErrorLocations {
value.Del(locationsField)
continue
}

// Create a new array via astjson we can append to the valid types
validLocations := arena.NewArray()
validIndex := 0

// GetArray will return nil if not an array which will not be ranged over
allLocations := value.Get(locationsField)
for _, loc := range allLocations.GetArray() {
line := loc.Get("line")
column := loc.Get("column")

// Keep location only if both line and column are > 0 (spec says 0 is invalid)
// In case it is not an int, 0 will be returned which is invalid anyway
if line.GetInt() > 0 && column.GetInt() > 0 {
validLocations.SetArrayItem(validIndex, loc)
validIndex++
}
}

// If all locations were invalid, delete the locations field
if len(validLocations.GetArray()) > 0 {
value.Set(locationsField, validLocations)
} else {
value.Del(locationsField)
}
}
}
Expand Down
Loading