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

Optimized Field Merging #6649

Merged
merged 2 commits into from
Oct 31, 2023
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
54 changes: 54 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Release

on:
push:
tags:
- '12.*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.x
7.x
8.x

- name: Get the version
id: get_version
run: echo "GIT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Build Packages
run: |
./build.sh pack --SemVersion ${{ env.GIT_TAG }} --Configuration Release

- name: Push Packages
run: |
./build.cmd publish --skip
env:
NuGetApiKey: ${{ secrets.NUGETAPIKEY }}

- name: Get release
id: get_release
run: |
RELEASE_ID=$(gh api repos/ChilliCream/graphql-platform/releases/tags/${{ env.GIT_TAG }} --jq '.id')
UPLOAD_URL=$(gh api repos/ChilliCream/graphql-platform/releases/$RELEASE_ID --jq '.upload_url')
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV
echo "UPLOAD_URL=${UPLOAD_URL}" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Release Assets
run: |
for file in ./output/packages/*.nupkg; do
echo "Uploading $file"
gh release upload ${{ env.GIT_TAG }} "$file" --repo ChilliCream/graphql-platform
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using HotChocolate.Language;
using HotChocolate.Properties;
using static HotChocolate.Utilities.ThrowHelper;
Expand Down Expand Up @@ -190,21 +191,64 @@ public static bool IsNamedType(this IType type)
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool IsType(this IType type, TypeKind kind)
{
if (type.Kind == kind)
{
return true;
}

if (type.Kind == TypeKind.NonNull && ((NonNullType)type).Type.Kind == kind)
if (type.Kind == TypeKind.NonNull && ((NonNullType) type).Type.Kind == kind)
{
return true;
}

return false;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool IsType(this IType type, TypeKind kind1, TypeKind kind2)
{
if (type.Kind == kind1 || type.Kind == kind2)
{
return true;
}

if (type.Kind == TypeKind.NonNull)
{
var innerKind = ((NonNullType) type).Type.Kind;

if (innerKind == kind1 || innerKind == kind2)
{
return true;
}
}

return false;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static bool IsType(this IType type, TypeKind kind1, TypeKind kind2, TypeKind kind3)
{
if (type.Kind == kind1 || type.Kind == kind2 || type.Kind == kind3)
{
return true;
}

if (type.Kind == TypeKind.NonNull)
{
var innerKind = ((NonNullType) type).Type.Kind;

if (innerKind == kind1 || innerKind == kind2 || innerKind == kind3)
{
return true;
}
}

return false;
}

public static IType InnerType(this IType type)
{
if (type is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public IOutputType NonNullString

public IDictionary<string, object?> ContextData { get; set; } = default!;

public List<FieldInfoPair> CurrentFieldPairs { get; } = new();

public List<FieldInfoPair> NextFieldPairs { get; } = new();

public HashSet<FieldInfoPair> ProcessedFieldPairs { get; } = new();

public IList<FieldInfo> RentFieldInfoList()
{
FieldInfoListBuffer buffer = _buffers.Peek();
Expand Down
2 changes: 1 addition & 1 deletion src/HotChocolate/Core/src/Validation/ErrorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static IError FieldIsRequiredButNull(
.Build();
}

public static IError FieldsAreNotMergable(
public static IError FieldsAreNotMergeable(
this IDocumentValidatorContext context,
FieldInfo fieldA,
FieldInfo fieldB)
Expand Down
38 changes: 37 additions & 1 deletion src/HotChocolate/Core/src/Validation/FieldInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using HotChocolate.Language;
using HotChocolate.Types;

Expand All @@ -7,7 +8,7 @@ namespace HotChocolate.Validation;
/// The validation field info provides access to the field node and the type
/// information of the referenced field.
/// </summary>
public readonly struct FieldInfo
public readonly struct FieldInfo : IEquatable<FieldInfo>
{
/// <summary>
/// Initializes a new instance of <see cref="FieldInfo"/>
Expand Down Expand Up @@ -41,4 +42,39 @@ public FieldInfo(IType declaringType, IType type, FieldNode field)
/// Gets the field selection.
/// </summary>
public FieldNode Field { get; }

/// <summary>
/// Compares this field info to another field info.
/// </summary>
/// <param name="other">
/// The other field info.
/// </param>
/// <returns>
/// <c>true</c> if the field infos are equal.
/// </returns>
public bool Equals(FieldInfo other)
=> Field.Equals(other.Field) &&
DeclaringType.Equals(other.DeclaringType) &&
Type.Equals(other.Type);

/// <summary>
/// Compares this field info to another object.
/// </summary>
/// <param name="obj">
/// The other object.
/// </param>
/// <returns>
/// <c>true</c> if the field infos are equal.
/// </returns>
public override bool Equals(object? obj)
=> obj is FieldInfo other && Equals(other);

/// <summary>
/// Returns the hash code of this instance.
/// </summary>
/// <returns>
/// The hash code of this instance.
/// </returns>
public override int GetHashCode()
=> HashCode.Combine(Field, DeclaringType, Type);
}
67 changes: 67 additions & 0 deletions src/HotChocolate/Core/src/Validation/FieldInfoPair.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;

namespace HotChocolate.Validation;

/// <summary>
/// Represents a pair of field infos.
/// </summary>
public readonly struct FieldInfoPair : IEquatable<FieldInfoPair>
{
/// <summary>
/// Initializes a new instance of <see cref="FieldInfoPair"/>.
/// </summary>
/// <param name="fieldA">
/// The first field info.
/// </param>
/// <param name="fieldB">
/// The second field info.
/// </param>
public FieldInfoPair(FieldInfo fieldA, FieldInfo fieldB)
{
FieldA = fieldA;
FieldB = fieldB;
}

/// <summary>
/// Gets the first field info.
/// </summary>
public FieldInfo FieldA { get; }

/// <summary>
/// Gets the second field info.
/// </summary>
public FieldInfo FieldB { get; }

/// <summary>
/// Compares this field info pair to another field info pair.
/// </summary>
/// <param name="other">
/// The other field info pair.
/// </param>
/// <returns>
/// <c>true</c> if the field info pairs are equal.
/// </returns>
public bool Equals(FieldInfoPair other)
=> FieldA.Equals(other.FieldA) && FieldB.Equals(other.FieldB);

/// <summary>
/// Compares this field info pair to another object.
/// </summary>
/// <param name="obj">
/// The other object.
/// </param>
/// <returns>
/// <c>true</c> if the field info pairs are equal.
/// </returns>
public override bool Equals(object? obj)
=> obj is FieldInfoPair other && Equals(other);

/// <summary>
/// Returns the hash code for this field info pair.
/// </summary>
/// <returns>
/// The hash code for this field info pair.
/// </returns>
public override int GetHashCode()
=> HashCode.Combine(FieldA, FieldB);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.4" />
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 15 additions & 0 deletions src/HotChocolate/Core/src/Validation/IDocumentValidatorContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ public interface IDocumentValidatorContext : ISyntaxVisitorContext
/// </summary>
IDictionary<string, object?> ContextData { get; }

/// <summary>
/// When processing field merging this list holds the field pairs that are processed.
/// </summary>
List<FieldInfoPair> CurrentFieldPairs { get; }

/// <summary>
/// When processing field merging this list holds the field pairs that are processed next.
/// </summary>
List<FieldInfoPair> NextFieldPairs { get; }

/// <summary>
/// When processing field merging this set represents the already processed field pairs.
/// </summary>
HashSet<FieldInfoPair> ProcessedFieldPairs { get; }

/// <summary>
/// Rents a list of field infos.
/// </summary>
Expand Down
Loading