Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
44 changes: 40 additions & 4 deletions v2/pkg/engine/resolve/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,11 +936,47 @@ 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
}
for _, value := range values {
if value.Exists("locations") {
// If the flag is set, delete all locations
if !value.Exists("locations") || l.omitSubgraphErrorLocations {
value.Del("locations")
continue
}

locations := value.Get("locations")
if locations.Type() != astjson.TypeArray {
continue
}

locationsArray := locations.GetArray()
locationsClone := slices.Clone(locationsArray)
Comment thread
Noroth marked this conversation as resolved.
Outdated

deletedEntries := 0
locationsArrayLength := len(locationsArray)

// We loop on a clone since we delete elements inline
for i, loc := range locationsClone {
line := loc.Get("line")
column := loc.Get("column")

// Skip invalid locations: nil values or values <= 0
if line == nil || column == nil {
locations.Del(strconv.Itoa(i - deletedEntries))
deletedEntries++
continue
}

// Keep location only if both line and column are > 0
// In case it is not an int, 0 will be returned which is invalid anyway
isValid := line.GetInt() > 0 && column.GetInt() > 0
if !isValid {
locations.Del(strconv.Itoa(i - deletedEntries))
deletedEntries++
}
Comment thread
Noroth marked this conversation as resolved.
}

// If all locations were invalid, delete the locations field
if locationsArrayLength == deletedEntries {
value.Del("locations")
}
}
Expand Down
Loading