Back to Graphql Dotnet

GQL008: Don't use an obsolete 'Argument' method

docs2/site/docs/analyzers/gql008.md

8.8.42.3 KB
Original Source

GQL008: Don't use an obsolete 'Argument' method

Value
Rule IDGQL008
CategoryUsage
Default severityWarning
Enabled by defaultYes
Code fix providedYes
Introduced inv7.7

Cause

This rule triggers when the obsolete Argument<TArgumentGraphType, TArgumentType>() method with two type parameters was used on the field builder.

Rule description

The method overload Argument<TArgumentGraphType, TArgumentType>(name, description, defaultValue, configure) is obsolete and will be remove in future version.

How to fix violations

Use Argument<TArgumentGraphType>() method overload with a single generic type parameter. Use Action<QueryArgument> parameter to configure default argument value.

Example of a violation

c#
Field<StringGraphType>("Text").Argument<StringGraphType, string>(
    "arg",
    "description",
    "MyDefault");

Field<StringGraphType>("Text").Argument<StringGraphType, string>(
    "arg",
    "description",
    "MyDefault",
    argument => argument.DeprecationReason = "Deprecation Reason");

Example of how to fix

c#
Field<StringGraphType>("Text").Argument<StringGraphType>(
    "arg",
    "description",
    argument => argument.DefaultValue = "MyDefault");

Field<StringGraphType>("Text").Argument<StringGraphType>(
    "arg",
    "description",
    argument =>
    {
        argument.DeprecationReason = "Deprecation Reason";
        argument.DefaultValue = "MyDefault";
    });

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.

csharp
#pragma warning disable GQL008
// The code that's violating the rule is on this line.
#pragma warning restore GQL008

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

ini
[*.cs]
dotnet_diagnostic.GQL008.severity = none

For more information, see How to suppress code analysis warnings.