Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made Cost Metrics Class Public #7213

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace HotChocolate.CostAnalysis;

/// <summary>https://ibm.github.io/graphql-specs/cost-spec.html#sec-__cost</summary>
internal sealed class CostMetrics
public sealed class CostMetrics
{
/// <summary>https://ibm.github.io/graphql-specs/cost-spec.html#sec-Field-Cost</summary>
public double FieldCost { get; set; } = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace HotChocolate.Execution;

internal static class CostAnalyzerRequestContextExtensions
/// <summary>
/// Cost Analyzer extensions for the <see cref="IRequestContext"/>.
/// </summary>
public static class CostAnalyzerRequestContextExtensions
{
public static IRequestContext AddCostMetrics(
internal static IRequestContext AddCostMetrics(
this IRequestContext context,
CostMetrics costMetrics)
{
Expand All @@ -22,7 +25,36 @@ public static IRequestContext AddCostMetrics(
return context;
}

public static CostAnalyzerMode GetCostAnalyzerMode(
/// <summary>
/// Gets the cost metrics from the context.
/// </summary>
/// <param name="context">
/// The request context.
/// </param>
/// <returns>
/// Returns the cost metrics.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="context"/> is <c>null</c>.
/// </exception>
public static CostMetrics GetCostMetrics(
this IRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

if (context.ContextData.TryGetValue(WellKnownContextData.CostMetrics, out var value) &&
value is CostMetrics costMetrics)
{
return costMetrics;
}

return new CostMetrics();
}

internal static CostAnalyzerMode GetCostAnalyzerMode(
this IRequestContext context,
CostOptions options)
{
Expand Down
Loading