Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn authored Oct 11, 2023
2 parents 3060420 + b741f5f commit 9517baf
Show file tree
Hide file tree
Showing 87 changed files with 7,744 additions and 131 deletions.
4 changes: 4 additions & 0 deletions .build/Build.Tests.2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ partial class Build
.Produces(TestResultDirectory / "*.trx")
.Executes(() => RunTests(SourceDirectory / "HotChocolate" / "Neo4J" / "HotChocolate.Neo4J.sln"));

Target TestHotChocolateOpenApi => _ => _
.Produces(TestResultDirectory / "*.trx")
.Executes(() => RunTests(SourceDirectory / "HotChocolate" / "OpenApi" / "HotChocolate.OpenApi.sln"));

Target TestHotChocolatePersistedQueries => _ => _
.Produces(TestResultDirectory / "*.trx")
.Executes(() => RunTests(SourceDirectory / "HotChocolate" / "PersistedQueries" / "HotChocolate.PersistedQueries.sln"));
Expand Down
1 change: 1 addition & 0 deletions .build/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static class Helpers
Path.Combine("HotChocolate", "Marten"),
Path.Combine("HotChocolate", "MongoDb"),
Path.Combine("HotChocolate", "Neo4J"),
Path.Combine("HotChocolate", "OpenApi"),
Path.Combine("HotChocolate", "Raven"),
Path.Combine("HotChocolate", "Skimmed"),
Path.Combine("HotChocolate", "Stitching"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace HotChocolate.Execution.Processing;

public sealed partial class OperationCompiler
{
internal sealed class CompilerContext(ISchema schema, DocumentNode document, bool disableNullBubbling)
internal sealed class CompilerContext(ISchema schema, DocumentNode document, bool enableNullBubbling)
{
public ISchema Schema { get; } = schema;

Expand All @@ -30,7 +30,7 @@ internal sealed class CompilerContext(ISchema schema, DocumentNode document, boo
public IImmutableList<ISelectionSetOptimizer> Optimizers { get; private set; } =
ImmutableList<ISelectionSetOptimizer>.Empty;

public bool EnableNullBubbling { get; } = disableNullBubbling;
public bool EnableNullBubbling { get; } = enableNullBubbling;

public void Initialize(
ObjectType type,
Expand Down
10 changes: 6 additions & 4 deletions src/HotChocolate/Core/src/Execution/Processing/Selection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected Selection(Selection selection)
/// <inheritdoc />
public int Id { get; }

internal CustomOptionsFlags CustomOptions { get; private set; }
public CustomOptionsFlags CustomOptions { get; private set; }

/// <inheritdoc />
public SelectionExecutionStrategy Strategy { get; private set; }
Expand Down Expand Up @@ -320,7 +320,7 @@ internal void MarkAsStream(long ifCondition)
_flags |= Flags.Stream;
}

internal void SetOption(CustomOptionsFlags customOptions)
public void SetOption(CustomOptionsFlags customOptions)
{
if ((_flags & Flags.Sealed) == Flags.Sealed)
{
Expand Down Expand Up @@ -390,14 +390,16 @@ private enum Flags
}

[Flags]
internal enum CustomOptionsFlags : byte
public enum CustomOptionsFlags : byte
{
None = 0,
Option1 = 1,
Option2 = 2,
Option3 = 4,
Option4 = 8,
Option5 = 16
Option5 = 16,
Option6 = 32,
Option7 = 64
}

internal sealed class Sealed : Selection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Text.Json;
using HotChocolate.Types;
using static HotChocolate.Execution.ErrorHelper;
using static HotChocolate.Execution.Processing.PathHelper;
Expand Down Expand Up @@ -89,6 +90,30 @@ internal static partial class ValueCompletion
return resultList;
}

if (result is JsonElement { ValueKind: JsonValueKind.Array } node)
{
var resultList = operationContext.Result.RentList(4);
resultList.IsNullable = elementType.Kind is not TypeKind.NonNull;
resultList.SetParent(parent, index);

var i = 0;
foreach (var element in node.EnumerateArray())
{
if (resultList.Count == resultList.Capacity)
{
resultList.Grow();
}

if (!TryCompleteElement(context, selection, elementType, isLeafType, resultList, i++, element))
{
operationContext.Result.AddRemovedResult(resultList);
return null;
}
}

return resultList;
}

var errorPath = CreatePathFromContext(selection, parent, index);
var error = ListValueIsNotSupported(result.GetType(), selection.SyntaxNode, errorPath);
operationContext.ReportError(error, resolverContext, selection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public void ApplyConfiguration(

if (type.IsListType())
{
throw ThrowHelper.CannotInferTypeFromJsonObj(ctx.Type.Name);
JsonObjectTypeExtensions.InferListResolver(def);
return;
}

if (namedType is ScalarType scalarType)
Expand All @@ -46,7 +47,7 @@ public void ApplyConfiguration(
}
}

private string? GetPropertyName(DirectiveNode directive)
private static string? GetPropertyName(DirectiveNode directive)
{
if (directive.Arguments.Count == 0)
{
Expand Down
13 changes: 12 additions & 1 deletion src/HotChocolate/Core/src/Types.Json/JsonObjectTypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.Json;
using System.Threading.Tasks;
using HotChocolate.Resolvers;
using HotChocolate.Types.Descriptors.Definitions;

Expand Down Expand Up @@ -44,7 +46,8 @@ public static IObjectFieldDescriptor FromJson(

if (type.IsListType())
{
throw ThrowHelper.CannotInferTypeFromJsonObj(ctx.Type.Name);
InferListResolver(def);
return;
}

if (namedType is ScalarType scalarType)
Expand Down Expand Up @@ -98,6 +101,11 @@ public static IObjectFieldDescriptor FromJson<TResult>(
return descriptor;
}

internal static void InferListResolver(ObjectFieldDefinition def)
{
def.PureResolver = ctx => new ValueTask<object?>(ctx.ToEnumerable());
}

internal static void InferResolver(
ITypeSystemObject type,
ObjectFieldDefinition def,
Expand Down Expand Up @@ -257,6 +265,9 @@ internal static void InferResolver(
}
}

private static IEnumerable<JsonElement> ToEnumerable(this IPureResolverContext context)
=> context.Parent<JsonElement>().EnumerateArray();

private static JsonElement? GetProperty(this IPureResolverContext context, string propertyName)
=> context.Parent<JsonElement>().TryGetProperty(propertyName, out var element)
? element
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#nullable enable

using System;
using System.Collections.Generic;
using HotChocolate.Language;
using HotChocolate.Resolvers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public static DirectiveNode CreateNode(string? reason = null)

var arguments = reason is null
? Array.Empty<ArgumentNode>()
: new[] { new ArgumentNode(DeprecatedDirectiveType.Names.Reason, reason) };
: new[] { new ArgumentNode(WellKnownDirectives.DeprecationReasonArgument, reason) };

return new DirectiveNode(
null,
new NameNode(DeprecatedDirectiveType.Names.Deprecated),
new NameNode(WellKnownDirectives.Deprecated),
arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected override void Configure(
IDirectiveTypeDescriptor<DeprecatedDirective> descriptor)
{
descriptor
.Name(Names.Deprecated)
.Name(WellKnownDirectives.Deprecated)
.Description(TypeResources.DeprecatedDirectiveType_TypeDescription)
.Location(DirectiveLocation.FieldDefinition)
.Location(DirectiveLocation.ArgumentDefinition)
Expand All @@ -25,15 +25,9 @@ protected override void Configure(

descriptor
.Argument(t => t.Reason)
.Name(Names.Reason)
.Name(WellKnownDirectives.DeprecationReasonArgument)
.Description(TypeResources.DeprecatedDirectiveType_ReasonDescription)
.Type<StringType>()
.DefaultValue(WellKnownDirectives.DeprecationDefaultReason);
}

public static class Names
{
public const string Deprecated = "deprecated";
public const string Reason = "reason";
}
}
2 changes: 2 additions & 0 deletions src/HotChocolate/Core/src/Types/Types/Directives/Tag.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System;
using HotChocolate.Properties;
using HotChocolate.Utilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ enum FooEnum @tag(name: "OnEnum") {

directive @foo(arg: String @tag(name: "OnDirectiveArgument")) on QUERY

directive @tag(name: String) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
61 changes: 51 additions & 10 deletions src/HotChocolate/Fusion/src/Abstractions/FusionGraphPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class FusionGraphPackage : IDisposable, IAsyncDisposable
private static readonly SyntaxSerializerOptions _syntaxSerializerOptions =
new()
{
Indented = true,
Indented = true,
MaxDirectivesPerLine = 0
};

Expand Down Expand Up @@ -202,7 +202,7 @@ public Task<JsonDocument> GetFusionGraphSettingsAsync(
return Task.FromResult(
JsonDocument.Parse(
"""
{
{
"fusionTypePrefix" : null,
"fusionTypeSelf": false
}
Expand Down Expand Up @@ -416,7 +416,7 @@ public async Task<IReadOnlyList<SubgraphConfiguration>> GetSubgraphConfiguration
/// <exception cref="FusionGraphPackageException">
/// The Fusion graph package must be opened in read/write mode to update contents.
/// </exception>
public Task SetSubgraphConfigurationAsync(
public async Task SetSubgraphConfigurationAsync(
SubgraphConfiguration configuration,
CancellationToken cancellationToken = default)
{
Expand All @@ -430,21 +430,60 @@ public Task SetSubgraphConfigurationAsync(
throw new FusionGraphPackageException(FusionGraphPackage_CannotWrite);
}

if (_package.RelationshipExists(configuration.Name))
await RemoveSubgraphConfigurationAsync(configuration.Name, cancellationToken);

await WriteSubgraphConfigurationAsync(configuration, cancellationToken);
}

/// <summary>
/// Removes a subgraph configuration from the package.
/// </summary>
/// <param name="subgraphName">
/// The name of the subgraph configuration to remove.
/// </param>
/// <param name="cancellationToken">
/// The cancellation token.
/// </param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="subgraphName"/> is <c>null</c>.
/// </exception>
/// <exception cref="FusionGraphPackageException">
/// The Fusion graph package must be opened in read/write mode to update contents.
/// </exception>
public Task RemoveSubgraphConfigurationAsync(
string subgraphName,
CancellationToken cancellationToken = default)
{
if (subgraphName is null)
{
var rootRel = _package.GetRelationship(configuration.Name);
throw new ArgumentNullException(nameof(subgraphName));
}

if (_package.FileOpenAccess != FileAccess.ReadWrite)
{
throw new FusionGraphPackageException(FusionGraphPackage_CannotWrite);
}

if (_package.RelationshipExists(subgraphName))
{
var rootRel = _package.GetRelationship(subgraphName);
var rootPart = _package.GetPart(rootRel.TargetUri);

foreach (var relationship in rootPart.GetRelationships())
{
_package.DeletePart(relationship.TargetUri);
}

_package.DeleteRelationship(configuration.Name);
_package.DeleteRelationship(subgraphName);
_package.DeletePart(rootPart.Uri);
}

return WriteSubgraphConfigurationAsync(configuration, cancellationToken);
_package.Flush();

return Task.CompletedTask;
}

private static async Task<DocumentNode> ReadSchemaPartAsync(
Expand Down Expand Up @@ -523,7 +562,8 @@ private async Task<SubgraphConfiguration> ReadSubgraphConfigurationAsync(
config.Name,
schema.ToString(true),
extensions.Select(t => t.ToString(_syntaxSerializerOptions)).ToArray(),
config.Clients);
config.Clients,
config.Extensions);
}

private async Task<SubgraphConfigJson> ReadSubgraphConfigurationJsonPartAsync(
Expand Down Expand Up @@ -578,7 +618,8 @@ private async Task<PackagePart> WriteSubgraphConfigurationJsonPartAsync(
{
var config = new SubgraphConfigJson(
configuration.Name,
configuration.Clients);
configuration.Clients,
configuration.ConfigurationExtensions);

var path = $"{configuration.Name}/{SubgraphConfigFileName}";
var uri = PackUriHelper.CreatePartUri(new Uri(path, UriKind.Relative));
Expand Down Expand Up @@ -646,4 +687,4 @@ public ValueTask DisposeAsync()
_package.Close();
return default;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ItemGroup>
<InternalsVisibleTo Include="HotChocolate.Fusion" />
<InternalsVisibleTo Include="HotChocolate.Fusion.Composition" />
<InternalsVisibleTo Include="HotChocolate.Fusion.CommandLine" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions src/HotChocolate/Fusion/src/Abstractions/JsonElementExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json;
using HotChocolate.Utilities;

namespace HotChocolate.Fusion;

internal static class JsonElementExtensions
{
public static JsonElement SafeClone(this JsonElement element)
{
var writer = new ArrayWriter();
using var jsonWriter = new Utf8JsonWriter(writer);

element.WriteTo(jsonWriter);
var reader = new Utf8JsonReader(writer.GetSpan(), true, default);

return JsonElement.ParseValue(ref reader);
}
}
Loading

0 comments on commit 9517baf

Please sign in to comment.