From dc565aaa30d1d9828bf079b6f417e5155c0df34b Mon Sep 17 00:00:00 2001 From: tomoikey <55743826+tomoikey@users.noreply.github.com> Date: Thu, 26 Dec 2024 04:07:37 +0900 Subject: [PATCH] [BUG] fix disable suggestion bug (#3456) * fix disable suggestion bug * use assert.Len --- graphql/executor/executor.go | 2 ++ graphql/executor/executor_test.go | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/graphql/executor/executor.go b/graphql/executor/executor.go index 6168f987056..849f2d0d35c 100644 --- a/graphql/executor/executor.go +++ b/graphql/executor/executor.go @@ -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) } diff --git a/graphql/executor/executor_test.go b/graphql/executor/executor_test.go index 44c9b11ae19..7d7728f23fc 100644 --- a/graphql/executor/executor_test.go +++ b/graphql/executor/executor_test.go @@ -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()) }) }