docs2/site/docs/analyzers/gql014.md
| Value | |
|---|---|
| Rule ID | GQL014 |
| Category | Usage |
| Default severity | Error |
| Enabled by default | Yes |
| Code fix provided | No |
| Introduced in | v8.0 |
This rule triggers when any of the fields defined by the OneOf input graph
type has default value.
All the fields defined by the OneOf input graph type must not have default
value. The rule runs on the code-first input types when
IInputObjectGraphType.IsOneOf = true; and type-first models decorated with
[OneOf] attribute. If the field is decorated with the [Ignore] attribute the
rule violation is not reported.
Remove default values from all the fields in the OneOf graph type.
Code-first:
public class UserIdentifierInputGraphType : InputObjectGraphType<UserIdentifier>
{
public UserIdentifierInputGraphType()
{
IsOneOf = true;
Field(x => x.NickName, nullable: true).DefaultValue("Joe");
}
}
Type-first:
[OneOf]
public class UserIdentifier
{
[DefaultValue("Joe")]
public string? NickName { get; set; }
}
Remove the default value.
Code-first:
public class UserIdentifierInputGraphType : InputObjectGraphType<UserIdentifier>
{
public UserIdentifierInputGraphType()
{
IsOneOf = true;
Field(x => x.NickName, nullable: true);
}
}
Type-first:
[OneOf]
public class UserIdentifier
{
public string? Name { get; set; }
}
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 GQL014
// The code that's violating the rule is on this line.
#pragma warning restore GQL014
To disable the rule for a file, folder, or project, set its severity to none
in the
configuration file.
[*.cs]
dotnet_diagnostic.GQL014.severity = none
For more information, see How to suppress code analysis warnings.