Skip to content

Commit

Permalink
Merge pull request #96 from dlecocq/non-string-computed-keys
Browse files Browse the repository at this point in the history
Support non-string computed keys
  • Loading branch information
sullivtr authored Sep 2, 2024
2 parents bf4f919 + d279b43 commit 24f101e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion graphql/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func computeMutationVariableKeys(keyMaps map[string]interface{}, responseObject
if err != nil {
return nil, err
}
mvks[k] = key.(string)
mvks[k] = fmt.Sprintf("%v", key)
}
return mvks, nil
}
Expand Down
15 changes: 15 additions & 0 deletions graphql/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ func TestComputeMutationVariableKeys(t *testing.T) {
computeKeys: map[string]interface{}{"id_key": "todos[1]"},
expectedValues: map[string]interface{}{"id_key": "another"},
},
{
body: `{"data": {"id": 1}}`,
computeKeys: map[string]interface{}{"id_key": "id"},
expectedValues: map[string]interface{}{"id_key": "1"},
},
{
body: `{"data": {"pi": 3.14159}}`,
computeKeys: map[string]interface{}{"id_key": "pi"},
expectedValues: map[string]interface{}{"id_key": "3.14159"},
},
{
body: `{"data": {"ready": false}}`,
computeKeys: map[string]interface{}{"id_key": "ready"},
expectedValues: map[string]interface{}{"id_key": "false"},
},
{
body: `{"data": {"todos": [{"id": "computed_id"}, {"id": "second_id"}]}}`,
computeKeys: map[string]interface{}{"id_key": "todos[3].id"},
Expand Down

0 comments on commit 24f101e

Please sign in to comment.