< Summary

Information
Class: NGql.Core.Mutation
Assembly: NGql.Core
File(s): /home/runner/work/NGql/NGql/src/Core/Mutation.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 76
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Name()100%11100%
get_FieldsList()100%11100%
get_Variables()100%11100%
Variable(...)100%11100%
Variable(...)100%11100%
Select(...)100%11100%
Select(...)100%11100%
Select(...)100%11100%
ToString()100%11100%
op_Implicit(...)100%11100%

File(s)

/home/runner/work/NGql/NGql/src/Core/Mutation.cs

#LineLine coverage
 1using NGql.Core.Abstractions;
 2
 3namespace NGql.Core;
 4
 5/// <summary>
 6/// Builds a GraphQL <c>mutation</c> operation. Use <see cref="Select(NGql.Core.Query)"/> to
 7/// embed a sub-<see cref="Query"/> that carries arguments via <see cref="Query.Where(string, object)"/>,
 8/// or <see cref="Select(string[])"/> for plain field names.
 9/// </summary>
 10/// <remarks>
 11/// <para>
 12/// <b>New code should prefer <see cref="Builders.QueryBuilder.CreateMutationBuilder(string)"/>.</b>
 13/// The fluent <see cref="Builders.QueryBuilder"/> surface is the recommended way to author both
 14/// queries and mutations in NGql 2.x and beyond — it offers a richer API (<c>Include</c>,
 15/// <c>WithMetadata</c>, sub-field lambdas, <c>PreservationBuilder</c> support) and avoids the
 16/// classic <see cref="Query"/>+<c>Where</c> idiom required by <see cref="Mutation"/> for
 17/// argument-bearing root fields.
 18/// </para>
 19/// <para>
 20/// <see cref="Mutation"/> remains supported for backwards compatibility with NGql 1.x call sites
 21/// and continues to render the same GraphQL output. There is currently no removal timeline.
 22/// </para>
 23/// </remarks>
 24/// <param name="name">Operation name (rendered as <c>mutation Name(...)</c>).</param>
 25/// <param name="variables">Operation variables; their <c>$name:Type</c> declarations appear in the operation signature.
 3326public sealed class Mutation(string name, params Variable[] variables)
 27{
 3328    private readonly QueryBlock _block = new(name, "mutation", variables: variables);
 29
 30    /// <inheritdoc cref="QueryBlock.Name"/>
 331    public string Name => _block.Name;
 32
 33    /// <inheritdoc cref="QueryBlock.FieldsList"/>
 634    public IEnumerable<object> FieldsList => _block.FieldsList;
 35
 36    /// <inheritdoc cref="QueryBlock.Variables"/>
 637    public IEnumerable<Variable> Variables => _block.Variables;
 38
 39    /// <inheritdoc cref="QueryBlock.AddVariable(NGql.Core.Variable)"/>
 40    public Mutation Variable(Variable variable)
 41    {
 942        _block.AddVariable(variable);
 943        return this;
 44    }
 45
 46    /// <inheritdoc cref="QueryBlock.AddVariable(string,string)"/>
 47    public Mutation Variable(string name, string type)
 48    {
 349        _block.AddVariable(name, type);
 350        return this;
 51    }
 52
 53    /// <inheritdoc cref="QueryBlock.AddField(System.Collections.Generic.IEnumerable{object})"/>
 54    public Mutation Select(IEnumerable<object> selectList)
 55    {
 356        _block.AddField(selectList);
 357        return this;
 58    }
 59
 60    /// <inheritdoc cref="QueryBlock.AddField(string[])"/>
 61    public Mutation Select(params string[] selects)
 62    {
 1563        _block.AddField(selects);
 1564        return this;
 65    }
 66
 67    /// <inheritdoc cref="QueryBlock.AddField(QueryBlock)"/>
 68    public Mutation Select(Query subQuery)
 69    {
 1570        _block.AddField(subQuery.Block);
 1571        return this;
 72    }
 73
 974    public override string ToString() => _block.ToString();
 1575    public static implicit operator string(Mutation mutation) => mutation._block.ToString();
 76}