Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment on lines +230 to +231
Copy link
Copy Markdown
Collaborator Author

@tomoikey tomoikey Dec 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If gqlparser has a function like Contains, it might be better to use it and add a conditional if check to determine whether the rule is already duplicated.

However, in terms of computational cost, this implementation should not cause any issues. Therefore, I think it would be sufficient to leave this as a future TODO for now.

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,7 +181,14 @@ func TestExecutorDisableSuggestion(t *testing.T) {
exec.SetDisableSuggestion(true)
resp := query(exec, "", "{nam}")
assert.Equal(t, "", string(resp.Data))
assert.Equal(t, len(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.Equal(t, "input:1: Cannot query field \"nam\" on type \"Query\".\n", resp.Errors.Error())
assert.Equal(t, len(resp.Errors), 1)
})
}

Expand Down