Skip to content

Commit

Permalink
[BUG] fix disable suggestion bug (#3456)
Browse files Browse the repository at this point in the history
* fix disable suggestion bug

* use assert.Len
  • Loading branch information
tomoikey authored Dec 25, 2024
1 parent 663d013 commit dc565aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions graphql/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ func (e *Executor) parseQuery(
validator.RemoveRule("FieldsOnCorrectType")

rule := rules.FieldsOnCorrectTypeRuleWithoutSuggestions
// remove the rule added when it was last executed
validator.RemoveRule(rule.Name)
validator.AddRule(rule.Name, rule.RuleFunc)
}

Expand Down
7 changes: 7 additions & 0 deletions graphql/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ func TestExecutorDisableSuggestion(t *testing.T) {
exec.SetDisableSuggestion(true)
resp := query(exec, "", "{nam}")
assert.Equal(t, "", string(resp.Data))
assert.Len(t, resp.Errors, 1)
assert.Equal(t, "input:1: Cannot query field \"nam\" on type \"Query\".\n", resp.Errors.Error())

// check if the error message is displayed correctly even if an error occurs multiple times
resp = query(exec, "", "{nam}")
assert.Equal(t, "", string(resp.Data))
assert.Len(t, resp.Errors, 1)
assert.Equal(t, "input:1: Cannot query field \"nam\" on type \"Query\".\n", resp.Errors.Error())
})
}
Expand Down

0 comments on commit dc565aa

Please sign in to comment.