Skip to content

Commit

Permalink
Fixes skip/include directive on fusion gateway. (#7050)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Apr 12, 2024
1 parent 565484c commit ed99eb6
Show file tree
Hide file tree
Showing 485 changed files with 2,228 additions and 24,658 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public void DefaultValueTests_Simple()
.AddQueryType<Queries>()
.AddMutationType<Mutations>();

ServiceProvider serviceProvider = services.BuildServiceProvider();
IRequestExecutorResolver executorResolver = serviceProvider.GetRequiredService<IRequestExecutorResolver>();
IRequestExecutor executor = executorResolver.GetRequestExecutorAsync().Result;
var serviceProvider = services.BuildServiceProvider();
var executorResolver = serviceProvider.GetRequiredService<IRequestExecutorResolver>();
var executor = executorResolver.GetRequestExecutorAsync().Result;

// Act
IExecutionResult result = executor.ExecuteAsync("mutation{ doSomething(input: { }) { result } }").Result;
var result = executor.ExecuteAsync("mutation{ doSomething(input: { }) { result } }").Result;

// Extract the data from the result
var jsonResult = result.ToJson();
Expand Down
12 changes: 2 additions & 10 deletions src/HotChocolate/Core/src/Abstractions/Error.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using HotChocolate.Execution;
using HotChocolate.Language;
using HotChocolate.Properties;

namespace HotChocolate;
Expand All @@ -22,8 +21,7 @@ public Error(
Path? path = null,
IReadOnlyList<Location>? locations = null,
IReadOnlyDictionary<string, object?>? extensions = null,
Exception? exception = null,
ISyntaxNode? syntaxNode = null)
Exception? exception = null)
{
if (string.IsNullOrEmpty(message))
{
Expand All @@ -38,7 +36,6 @@ public Error(
Locations = locations;
Extensions = extensions;
Exception = exception;
SyntaxNode = syntaxNode;

if (code is not null)
{
Expand Down Expand Up @@ -70,11 +67,6 @@ public Error(

/// <inheritdoc />
public Exception? Exception { get; }

/// <summary>
/// Gets the syntax node that caused the error.
/// </summary>
public ISyntaxNode? SyntaxNode { get; }

/// <inheritdoc />
public IError WithMessage(string message)
Expand Down Expand Up @@ -205,5 +197,5 @@ public IError WithException(Exception? exception)

/// <inheritdoc />
public IError RemoveException()
=> new Error(Message, Code, Path, Locations, Extensions, syntaxNode: SyntaxNode);
=> new Error(Message, Code, Path, Locations, Extensions);
}
30 changes: 20 additions & 10 deletions src/HotChocolate/Core/src/Abstractions/ErrorBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using HotChocolate.Language;
using HotChocolate.Properties;

#nullable enable

namespace HotChocolate;

public class ErrorBuilder : IErrorBuilder
Expand All @@ -19,7 +17,6 @@ public class ErrorBuilder : IErrorBuilder
private List<Location>? _locations;
private bool _dirtyLocation;
private bool _dirtyExtensions;
private ISyntaxNode? _syntaxNode;

public ErrorBuilder()
{
Expand All @@ -37,12 +34,12 @@ private ErrorBuilder(IError error)
_path = error.Path;
_exception = error.Exception;

if (error.Extensions is { } && error.Extensions.Count > 0)
if (error.Extensions is { Count: > 0 })
{
_extensions = new OrderedDictionary<string, object?>(error.Extensions);
}

if (error.Locations is { } && error.Locations.Count > 0)
if (error.Locations is { Count: > 0 })
{
_locations = [..error.Locations,];
}
Expand Down Expand Up @@ -100,7 +97,7 @@ public IErrorBuilder RemovePath()

public IErrorBuilder AddLocation(Location location)
{
if (_dirtyLocation && _locations is { })
if (_dirtyLocation && _locations is not null)
{
_locations = [.._locations,];
_dirtyLocation = false;
Expand All @@ -113,9 +110,23 @@ public IErrorBuilder AddLocation(Location location)
public IErrorBuilder AddLocation(int line, int column) =>
AddLocation(new Location(line, column));

public IErrorBuilder SetSyntaxNode(ISyntaxNode? syntaxNode)
public IErrorBuilder AddLocation<T>(IReadOnlyList<T>? syntaxNodes) where T : ISyntaxNode
{
_syntaxNode = syntaxNode;
if (syntaxNodes is null)
{
_locations = null;
_dirtyLocation = false;
return this;
}

foreach (var syntaxNode in syntaxNodes)
{
if (syntaxNode.Location is { } location)
{
AddLocation(location.Line, location.Column);
}
}

return this;
}

Expand Down Expand Up @@ -203,8 +214,7 @@ public IError Build()
_path,
_locations,
_extensions,
_exception,
_syntaxNode);
_exception);
}

public static ErrorBuilder New() => new();
Expand Down
38 changes: 2 additions & 36 deletions src/HotChocolate/Core/src/Abstractions/ErrorBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,9 @@
using System;
using System.Globalization;
using HotChocolate.Language;

#nullable enable

namespace HotChocolate;

public static class ErrorBuilderExtensions
{
public static IErrorBuilder AddLocation(
this IErrorBuilder builder,
ISyntaxNode? syntaxNode)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}

if (syntaxNode is { Location: not null, })
{
builder.SetSyntaxNode(syntaxNode);

if (syntaxNode.Location is not null)
{
return builder.AddLocation(
syntaxNode.Location.Line,
syntaxNode.Location.Column);
}
}

return builder;
}

public static IErrorBuilder SetMessage(
this IErrorBuilder builder,
string format,
params object[] args) =>
builder.SetMessage(string.Format(
CultureInfo.InvariantCulture,
format,
args));
public static IErrorBuilder SetMessage(this IErrorBuilder builder, string format, params object[] args)
=> builder.SetMessage(string.Format(CultureInfo.InvariantCulture, format, args));
}
50 changes: 0 additions & 50 deletions src/HotChocolate/Core/src/Abstractions/ErrorExtensions.cs

This file was deleted.

4 changes: 1 addition & 3 deletions src/HotChocolate/Core/src/Abstractions/IError.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;

#nullable enable

namespace HotChocolate;

/// <summary>
Expand Down Expand Up @@ -40,7 +38,7 @@ public interface IError
/// This property is optional and can be null.
/// </summary>
IReadOnlyDictionary<string, object?>? Extensions { get; }

/// <summary>
/// Gets the exception associated with this error.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/HotChocolate/Core/src/Abstractions/IErrorBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IErrorBuilder

IErrorBuilder AddLocation(int line, int column);

IErrorBuilder SetSyntaxNode(ISyntaxNode? syntaxNode);
IErrorBuilder AddLocation<T>(IReadOnlyList<T>? syntaxNodes) where T : ISyntaxNode;

IErrorBuilder ClearLocations();

Expand Down
26 changes: 10 additions & 16 deletions src/HotChocolate/Core/src/Authorization/AuthorizeMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@

namespace HotChocolate.Authorization;

internal sealed class AuthorizeMiddleware
internal sealed class AuthorizeMiddleware(
FieldDelegate next,
AuthorizeDirective directive)
{
private readonly FieldDelegate _next;
private readonly AuthorizeDirective _directive;

public AuthorizeMiddleware(
FieldDelegate next,
AuthorizeDirective directive)
{
_next = next ??
throw new ArgumentNullException(nameof(next));
_directive = directive ??
throw new ArgumentNullException(nameof(directive));
}
private readonly FieldDelegate _next = next ??
throw new ArgumentNullException(nameof(next));
private readonly AuthorizeDirective _directive = directive ??
throw new ArgumentNullException(nameof(directive));

public async Task InvokeAsync(IMiddlewareContext context)
{
Expand Down Expand Up @@ -87,7 +81,7 @@ private void SetError(
.SetMessage(AuthorizeMiddleware_NoDefaultPolicy)
.SetCode(ErrorCodes.Authentication.NoDefaultPolicy)
.SetPath(context.Path)
.AddLocation(context.Selection.SyntaxNode)
.AddLocation([context.Selection.SyntaxNode])
.Build(),
AuthorizeResult.PolicyNotFound
=> ErrorBuilder.New()
Expand All @@ -96,7 +90,7 @@ private void SetError(
_directive.Policy!)
.SetCode(ErrorCodes.Authentication.PolicyNotFound)
.SetPath(context.Path)
.AddLocation(context.Selection.SyntaxNode)
.AddLocation([context.Selection.SyntaxNode])
.Build(),
_
=> ErrorBuilder.New()
Expand All @@ -106,7 +100,7 @@ private void SetError(
? ErrorCodes.Authentication.NotAuthorized
: ErrorCodes.Authentication.NotAuthenticated)
.SetPath(context.Path)
.AddLocation(context.Selection.SyntaxNode)
.AddLocation([context.Selection.SyntaxNode])
.Build(),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public IRequestContext RequestContext
}
set
{
RequestContextHolder? holder = _requestContextCurrent.Value;
var holder = _requestContextCurrent.Value;

if (holder is null)
{
Expand Down
Loading

0 comments on commit ed99eb6

Please sign in to comment.