< Summary

Information
Class: NGql.Core.Abstractions.InlineFragmentDefinition
Assembly: NGql.Core
File(s): /home/runner/work/NGql/NGql/src/Core/Abstractions/InlineFragmentDefinition.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 78
Line coverage: 100%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
get_TypeName()100%11100%
get_Fields()100%22100%
GetOrCreateFieldsStore()100%22100%
get_InlineFragments()100%22100%
.cctor()100%11100%
Equals(...)50%44100%
GetHashCode()100%11100%

File(s)

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

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Text.Json.Serialization;
 3
 4namespace NGql.Core.Abstractions;
 5
 6/// <summary>
 7///     Represents a GraphQL inline fragment — a type-conditional selection set rendered as
 8///     <c>... on TypeName { … }</c>. Used to narrow a parent field whose schema type is a
 9///     union or interface to a specific concrete type.
 10/// </summary>
 11/// <remarks>
 12///     Inline fragments are siblings of regular fields under their parent <see cref="FieldDefinition"/>
 13///     (see <see cref="FieldDefinition.InlineFragments"/>). They are kept in a separate collection
 14///     because their access pattern (lookup by type name) and rendering shape (the <c>... on</c>
 15///     prefix) differ from regular fields. Nested inline fragments — fragments inside fragments —
 16///     are supported recursively.
 17/// </remarks>
 18[SuppressMessage("Minor Code Smell", "S2292:Trivial properties should be auto-implemented")]
 19public sealed record InlineFragmentDefinition
 20{
 21    internal FieldChildren? _fields;
 22    internal Dictionary<string, InlineFragmentDefinition>? _fragments;
 23
 24    /// <summary>
 25    /// Creates an inline fragment for <paramref name="typeName"/> with no children.
 26    /// </summary>
 27    /// <param name="typeName">The GraphQL type the fragment narrows to (e.g. <c>"Repository"</c>).
 28    /// Rendered verbatim — case matters, GraphQL type names are case-sensitive.</param>
 6929    public InlineFragmentDefinition(string typeName)
 30    {
 6931        if (string.IsNullOrWhiteSpace(typeName))
 32        {
 933            throw new ArgumentException("Inline fragment type name cannot be null or whitespace.", nameof(typeName));
 34        }
 35
 6036        TypeName = typeName;
 6037    }
 38
 39    /// <summary>
 40    /// The GraphQL type the fragment narrows to. Rendered verbatim after <c>... on </c>.
 41    /// </summary>
 42    [JsonPropertyName("typeName")]
 11443    public string TypeName { get; init; }
 44
 45    /// <summary>
 46    /// Fields selected when the parent value's runtime type is <see cref="TypeName"/>.
 47    /// </summary>
 48    [JsonPropertyName("fields")]
 49    public IReadOnlyDictionary<string, FieldDefinition> Fields
 1550        => (IReadOnlyDictionary<string, FieldDefinition>?)_fields ?? EmptyFields;
 51
 52    /// <summary>
 53    /// Get-or-add the underlying <see cref="FieldChildren"/> store. Internal so the builder
 54    /// can pass a stable reference when the user's lambda adds fields to the fragment.
 55    /// </summary>
 56    internal FieldChildren GetOrCreateFieldsStore()
 5157        => _fields ??= new FieldChildren();
 58
 59    /// <summary>
 60    /// Nested inline fragments inside this fragment's selection set. Useful when the fragment's
 61    /// fields themselves return union/interface types that need further narrowing.
 62    /// </summary>
 63    [JsonPropertyName("inlineFragments")]
 64    public IReadOnlyDictionary<string, InlineFragmentDefinition> InlineFragments
 965        => (IReadOnlyDictionary<string, InlineFragmentDefinition>?)_fragments ?? EmptyFragments;
 66
 367    private static readonly IReadOnlyDictionary<string, FieldDefinition> EmptyFields = new Dictionary<string, FieldDefin
 368    private static readonly IReadOnlyDictionary<string, InlineFragmentDefinition> EmptyFragments = new Dictionary<string
 69
 70    public bool Equals(InlineFragmentDefinition? other)
 71    {
 672        if (other is null) return false;
 673        if (ReferenceEquals(this, other)) return true;
 674        return string.Equals(TypeName, other.TypeName, StringComparison.Ordinal);
 75    }
 76
 677    public override int GetHashCode() => StringComparer.Ordinal.GetHashCode(TypeName);
 78}