< 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: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 88
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%
AppendTo(...)100%11100%
WriteTo(...)100%11100%
WriteUtf8(...)100%11100%
op_Implicit(...)100%11100%

File(s)

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

#LineLine coverage
 1using System.Buffers;
 2using System.Text;
 3using NGql.Core.Abstractions;
 4
 5namespace NGql.Core;
 6
 7/// <summary>
 8/// Builds a GraphQL <c>mutation</c> operation. Use <see cref="Select(NGql.Core.Query)"/> to
 9/// embed a sub-<see cref="Query"/> that carries arguments via <see cref="Query.Where(string, object)"/>,
 10/// or <see cref="Select(string[])"/> for plain field names.
 11/// </summary>
 12/// <remarks>
 13/// <para>
 14/// <b>New code should prefer <see cref="Builders.QueryBuilder.CreateMutationBuilder(string)"/>.</b>
 15/// The fluent <see cref="Builders.QueryBuilder"/> surface is the recommended way to author both
 16/// queries and mutations in NGql 2.x and beyond — it offers a richer API (<c>Include</c>,
 17/// <c>WithMetadata</c>, sub-field lambdas, <c>PreservationBuilder</c> support) and avoids the
 18/// classic <see cref="Query"/>+<c>Where</c> idiom required by <see cref="Mutation"/> for
 19/// argument-bearing root fields.
 20/// </para>
 21/// <para>
 22/// <see cref="Mutation"/> remains supported for backwards compatibility with NGql 1.x call sites
 23/// and continues to render the same GraphQL output. There is currently no removal timeline.
 24/// </para>
 25/// </remarks>
 26/// <param name="name">Operation name (rendered as <c>mutation Name(...)</c>).</param>
 27/// <param name="variables">Operation variables; their <c>$name:Type</c> declarations appear in the operation signature.
 5128public sealed class Mutation(string name, params Variable[] variables)
 29{
 5130    private readonly QueryBlock _block = new(name, "mutation", variables: variables);
 31
 32    /// <inheritdoc cref="QueryBlock.Name"/>
 333    public string Name => _block.Name;
 34
 35    /// <inheritdoc cref="QueryBlock.FieldsList"/>
 636    public IEnumerable<object> FieldsList => _block.FieldsList;
 37
 38    /// <inheritdoc cref="QueryBlock.Variables"/>
 639    public IEnumerable<Variable> Variables => _block.Variables;
 40
 41    /// <inheritdoc cref="QueryBlock.AddVariable(NGql.Core.Variable)"/>
 42    public Mutation Variable(Variable variable)
 43    {
 944        _block.AddVariable(variable);
 945        return this;
 46    }
 47
 48    /// <inheritdoc cref="QueryBlock.AddVariable(string,string)"/>
 49    public Mutation Variable(string name, string type)
 50    {
 351        _block.AddVariable(name, type);
 352        return this;
 53    }
 54
 55    /// <inheritdoc cref="QueryBlock.AddField(System.Collections.Generic.IEnumerable{object})"/>
 56    public Mutation Select(IEnumerable<object> selectList)
 57    {
 358        _block.AddField(selectList);
 359        return this;
 60    }
 61
 62    /// <inheritdoc cref="QueryBlock.AddField(string[])"/>
 63    public Mutation Select(params string[] selects)
 64    {
 1565        _block.AddField(selects);
 1566        return this;
 67    }
 68
 69    /// <inheritdoc cref="QueryBlock.AddField(QueryBlock)"/>
 70    public Mutation Select(Query subQuery)
 71    {
 3372        _block.AddField(subQuery.Block);
 3373        return this;
 74    }
 75
 1876    public override string ToString() => _block.ToString();
 77
 78    /// <inheritdoc cref="QueryBlock.AppendTo(System.Text.StringBuilder)"/>
 679    public void AppendTo(StringBuilder builder) => _block.AppendTo(builder);
 80
 81    /// <inheritdoc cref="QueryBlock.WriteTo(System.IO.TextWriter)"/>
 682    public void WriteTo(TextWriter writer) => _block.WriteTo(writer);
 83
 84    /// <inheritdoc cref="QueryBlock.WriteUtf8(System.Buffers.IBufferWriter{System.Byte})"/>
 685    public void WriteUtf8(IBufferWriter<byte> bufferWriter) => _block.WriteUtf8(bufferWriter);
 86
 1587    public static implicit operator string(Mutation mutation) => mutation._block.ToString();
 88}