Skip to content

Commit 99cf6bd

Browse files
committed
Fix list element index in error messages
1 parent 32f1c98 commit 99cf6bd

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

rules.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,9 +1761,9 @@ func isValidLiteralValue(ttype Input, valueAST ast.Value) (bool, []string) {
17611761
itemType, _ := ttype.OfType.(Input)
17621762
if valueAST, ok := valueAST.(*ast.ListValue); ok {
17631763
messagesReduce := []string{}
1764-
for _, value := range valueAST.Values {
1764+
for idx, value := range valueAST.Values {
17651765
_, messages := isValidLiteralValue(itemType, value)
1766-
for idx, message := range messages {
1766+
for _, message := range messages {
17671767
messagesReduce = append(messagesReduce, fmt.Sprintf(`In element #%v: %v`, idx+1, message))
17681768
}
17691769
}

rules_arguments_of_correct_type_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func TestValidate_ArgValuesOfCorrectType_InvalidListValue_IncorrectItemType(t *t
500500
`,
501501
[]gqlerrors.FormattedError{
502502
testutil.RuleError(
503-
"Argument \"stringListArg\" has invalid value [\"one\", 2].\nIn element #1: Expected type \"String\", found 2.",
503+
"Argument \"stringListArg\" has invalid value [\"one\", 2].\nIn element #2: Expected type \"String\", found 2.",
504504
4, 47,
505505
),
506506
})
@@ -742,7 +742,7 @@ func TestValidate_ArgValuesOfCorrectType_InvalidInputObjectValue_PartialObject_I
742742
`,
743743
[]gqlerrors.FormattedError{
744744
testutil.RuleError(
745-
"Argument \"complexArg\" has invalid value {stringListField: [\"one\", 2], requiredField: true}.\nIn field \"stringListField\": In element #1: Expected type \"String\", found 2.",
745+
"Argument \"complexArg\" has invalid value {stringListField: [\"one\", 2], requiredField: true}.\nIn field \"stringListField\": In element #2: Expected type \"String\", found 2.",
746746
4, 41,
747747
),
748748
})

rules_default_values_of_correct_type_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestValidate_VariableDefaultValuesOfCorrectType_ListVariablesWithInvalidIte
9797
[]gqlerrors.FormattedError{
9898
testutil.RuleError(
9999
`Variable "$a" has invalid default value: ["one", 2].`+
100-
"\nIn element #1: Expected type \"String\", found 2.",
100+
"\nIn element #2: Expected type \"String\", found 2.",
101101
2, 40),
102102
})
103103
}

0 commit comments

Comments
 (0)