diff --git a/src/HotChocolate/Core/src/Execution/Internal/MiddlewareContextMarshal.cs b/src/HotChocolate/Core/src/Execution/Internal/MiddlewareContextMarshal.cs index 9fbef8f0508..01a0769bc68 100644 --- a/src/HotChocolate/Core/src/Execution/Internal/MiddlewareContextMarshal.cs +++ b/src/HotChocolate/Core/src/Execution/Internal/MiddlewareContextMarshal.cs @@ -18,7 +18,9 @@ public static class MiddlewareContextMarshal /// /// The resolver context. /// - /// + /// + /// Returns the result data of the current resolver context. + /// public static ObjectResult? GetParentResultUnsafe(IResolverContext context) { if (context is null) @@ -30,4 +32,54 @@ public static class MiddlewareContextMarshal ? middlewareContext.ParentResult : null; } + + /// + /// Gets the parent result data of the current . + /// + /// + /// The result data for which to get the parent. + /// + /// + /// The type of the result data. + /// + /// + /// Returns the parent result data of the current . + /// + /// + /// Throws if is null. + /// + public static ResultData? GetParent(T resultData) where T : ResultData + { + if (resultData == null) + { + throw new ArgumentNullException(nameof(resultData)); + } + + return resultData.Parent; + } + + /// + /// Gets the index under which the is stored in the parent result. + /// + /// + /// The result data for which to get the parent index. + /// + /// + /// The type of the result data. + /// + /// + /// Returns the index under which the is stored in the parent result. + /// + /// + /// Throws if is null. + /// + public static int GetParentIndex(T resultData) where T : ResultData + { + if (resultData == null) + { + throw new ArgumentNullException(nameof(resultData)); + } + + return resultData.ParentIndex; + } } \ No newline at end of file