GQL002: Name method invocation can be removed
| Value | |
|---|---|
| Rule ID | GQL002 |
| Category | Usage |
| Default severity | Warning |
| Enabled by default | Yes |
| Code fix provided | Yes |
| Introduced in | v7.7 |
Cause
The same name is provided in Field, Connection or ConnectionBuilder.Create
and Name methods.
Rule description
Field name should be provided in the Field, Connection or
ConnectionBuilder.Create method. The Name method call is unnecessary and can
be removed.
How to fix violations
Remove the Name method call.
Example of a violation
Field<StringGraphType>("Name").Name("Name");
Connection<StringGraphType>("Name").Name("Name");
ConnectionBuilder<string>.Create<StringGraphType>("Name").Name("Name");
ConnectionBuilder.Create<StringGraphType, string>("Name").Name("Name");Example of how to fix
Field<StringGraphType>("Name");
Connection<StringGraphType>("Name");
ConnectionBuilder<string>.Create<StringGraphType>("Name");
ConnectionBuilder.Create<StringGraphType, string>("Name");Suppress a warning
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable GQL002
// The code that's violating the rule is on this line.
#pragma warning restore GQL002To disable the rule for a file, folder, or project, set its severity to none
in the
configuration file.
[*.cs]
dotnet_diagnostic.GQL002.severity = noneFor more information, see How to suppress code analysis warnings.
Related rules
GQL001: Define the name in Field, Connection or ConnectionBuilder.Create method
GQL003: Different names defined by Field, Connection or ConnectionBuilder.Create and Name methods