Skip to content

Commit

Permalink
Merge pull request #160 from movio/fix-merge-into-error-result
Browse files Browse the repository at this point in the history
Ensure the destination map for merging is never nil
  • Loading branch information
Lucian Jones authored Jun 16, 2022
2 parents 127c5a4 + 9605826 commit 24b50dc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ func mergeExecutionResults(results []executionResult) (map[string]interface{}, e
}

data := results[0].Data
switch ptr := data.(type) {
case nil:
data = make(map[string]interface{})
case map[string]interface{}:
if ptr == nil {
data = make(map[string]interface{})
}
}

for _, result := range results[1:] {
if err := mergeExecutionResultsRec(result.Data, data, result.InsertionPoint); err != nil {
return nil, err
Expand Down
21 changes: 21 additions & 0 deletions execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5794,6 +5794,27 @@ func TestQueryWithArrayBoundaryFields(t *testing.T) {
f.checkSuccess(t)
}

func TestMergeWithNull(t *testing.T) {
nullMap := make(map[string]interface{})
dataMap := map[string]interface{}{
"data": "foo",
}

require.NoError(t, json.Unmarshal([]byte(`null`), &nullMap))

merged, err := mergeExecutionResults([]executionResult{
{
Data: nullMap,
},
{
Data: dataMap,
},
})

require.NoError(t, err)
require.Equal(t, dataMap, merged)
}

func TestSchemaUpdate_serviceError(t *testing.T) {
schemaA := `directive @boundary on OBJECT
type Service {
Expand Down

0 comments on commit 24b50dc

Please sign in to comment.