< Summary

Information
Class: NGql.Core.Abstractions.QueryDefinition
Assembly: NGql.Core
File(s): /home/runner/work/NGql/NGql/src/Core/Abstractions/QueryDefinition.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 88
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
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_Description()100%11100%
get_Fields()100%22100%
set_Fields(...)100%11100%
get_Variables()100%22100%
set_Variables(...)100%11100%
get_Metadata()100%22100%
set_Metadata(...)100%11100%
get_MergingStrategy()100%11100%
get_OperationType()100%11100%
ToString()100%11100%
op_Implicit(...)100%11100%

File(s)

/home/runner/work/NGql/NGql/src/Core/Abstractions/QueryDefinition.cs

#LineLine coverage
 1using System.Text.Json.Serialization;
 2using NGql.Core.Builders;
 3
 4namespace NGql.Core.Abstractions;
 5
 6/// <summary>
 7///     Represents a query definition.
 8/// </summary>
 95439public sealed record QueryDefinition(string Name, string Description = "")
 10{
 11    internal Dictionary<string, FieldDefinition>? _fields;
 12    internal SortedSet<Variable>? _variables;
 13    internal Dictionary<string, object?>? _metadata;
 14
 15    /// <summary>
 16    /// The name of the query.
 17    /// </summary>
 18    [JsonPropertyName("name")]
 5146819    public string Name { get; init; } = Name;
 20
 21    /// <summary>
 22    /// The description of the query.
 23    /// </summary>
 24    [JsonPropertyName("description")]
 954325    public string Description { get; init; } = Description;
 26
 27    /// <summary>
 28    ///     The collection of fields related to <see cref="QueryDefinition"/>.
 29    /// </summary>
 30    [JsonPropertyName("fields")]
 31    public Dictionary<string, FieldDefinition> Fields
 32    {
 7515633        get => _fields ??= new(StringComparer.OrdinalIgnoreCase);
 334        internal set => _fields = value;
 35    }
 36
 37    /// <summary>
 38    ///     The collection of variables related to fields or arguments.
 39    /// </summary>
 40    [JsonIgnore]
 41    public SortedSet<Variable> Variables
 42    {
 754543        get => _variables ??= new();
 344        internal set => _variables = value;
 45    }
 46
 47    /// <summary>
 48    /// Metadata associated with the query definition.
 49    /// This can include additional information such as descriptions, tags, or any other relevant data.
 50    ///
 51    /// Not used during query text generation but can be useful for documentation or introspection purposes.
 52    /// </summary>
 53    [JsonPropertyName("metadata")]
 54    public Dictionary<string, object?> Metadata
 55    {
 22856        get => _metadata ??= [];
 6957        set => _metadata = value;
 58    }
 59
 60    /// <summary>
 61    /// Merging strategy for this query definition.
 62    /// </summary>
 63    [JsonPropertyName("mergingStrategy")]
 163564    public MergingStrategy MergingStrategy { get; set; } = MergingStrategy.MergeByDefault;
 65
 66    /// <summary>
 67    /// The kind of root operation rendered by this definition (query or mutation).
 68    /// Selected by the factory on <see cref="QueryBuilder"/>; consumers do not set this directly.
 69    /// </summary>
 70    [JsonIgnore]
 812471    internal OperationType OperationType { get; set; } = OperationType.Query;
 72
 73    /// <inheritdoc cref="QueryBlock.ToString()"/>
 74    public override string ToString()
 75    {
 810676        var builder = QueryTextBuilder.GetFromPool();
 77        try
 78        {
 810679            return builder.Build(this);
 80        }
 81        finally
 82        {
 810683            QueryTextBuilder.ReturnToPool(builder);
 810684        }
 810685    }
 86
 387    public static implicit operator string(QueryDefinition query) => query.ToString();
 88}