Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
faddiv authored Feb 24, 2024
2 parents ccbc85b + 1865894 commit 08ef4b2
Show file tree
Hide file tree
Showing 120 changed files with 9,912 additions and 1,597 deletions.
4 changes: 3 additions & 1 deletion cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"meros",
"Structs",
"reencode",
"WunderGraph"
"WunderGraph",
"CCPA",
"decompile"
],
"ignoreWords": [
"Badurina",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public static void MatchSnapshot(
ISnapshotValueFormatter? formatter = null)
=> Snapshot.Match(value, postFix?.ToString(), extension, formatter);

public static void MatchMarkdownSnapshot(
this object? value,
object? postFix = null,
string? extension = null,
ISnapshotValueFormatter? formatter = null)
=> Snapshot.Create(postFix?.ToString(), extension).Add(value, formatter: formatter).MatchMarkdown();

public static void MatchSnapshot(
this ISyntaxNode? value,
string? postFix = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CookieCrumble.Formatters;

internal sealed class JsonSnapshotValueFormatter : ISnapshotValueFormatter
internal sealed class JsonSnapshotValueFormatter : ISnapshotValueFormatter, IMarkdownSnapshotValueFormatter
{
private static readonly JsonSerializerSettings _settings =
new()
Expand All @@ -22,9 +22,19 @@ internal sealed class JsonSnapshotValueFormatter : ISnapshotValueFormatter

public bool CanHandle(object? value)
=> true;

public void Format(IBufferWriter<byte> snapshot, object? value)
=> snapshot.Append(JsonConvert.SerializeObject(value, _settings));

public void FormatMarkdown(IBufferWriter<byte> snapshot, object? value)
{
snapshot.Append("```json");
snapshot.AppendLine();
Format(snapshot, value);
snapshot.AppendLine();
snapshot.Append("```");
snapshot.AppendLine();
}

private class ChildFirstContractResolver : DefaultContractResolver
{
Expand Down
11 changes: 7 additions & 4 deletions src/GreenDonut/test/Core.Tests/TaskCacheOwnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ public class TaskCacheOwnerTests
public void EnsureTaskCacheIsReused()
{
// arrange
var cacheOwner1 = new TaskCacheOwner();
var pool = TaskCachePool.Create();
var cacheOwner1 = new TaskCacheOwner(pool);
var cache = cacheOwner1.Cache;
cacheOwner1.Dispose();

// act
using var cacheOwner2 = new TaskCacheOwner();
using var cacheOwner2 = new TaskCacheOwner(pool);

// assert
Assert.Same(cache, cacheOwner2.Cache);
Expand All @@ -23,9 +24,11 @@ public void EnsureTaskCacheIsReused()
public void EnsureNewCachesAreIssued()
{
// arrange
var pool = TaskCachePool.Create();

// act
using var cacheOwner1 = new TaskCacheOwner();
using var cacheOwner2 = new TaskCacheOwner();
using var cacheOwner1 = new TaskCacheOwner(pool);
using var cacheOwner2 = new TaskCacheOwner(pool);

// assert
Assert.NotSame(cacheOwner1.Cache, cacheOwner2.Cache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Core\src\Core\HotChocolate.Core.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,7 @@
<ProjectReference Include="..\..\..\Language\src\Language.SyntaxTree\HotChocolate.Language.SyntaxTree.csproj" />
</ItemGroup>

<ItemGroup>

</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.7" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@
<ProjectReference Include="..\Transport.Sockets\HotChocolate.Transport.Sockets.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Include="System.Text.Json" Version="6.0.7" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current">
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current">

<PropertyGroup>
<PackageId>HotChocolate.Abstractions</PackageId>
Expand All @@ -15,15 +15,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="System.Threading.Channels" Version="7.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="System.Threading.Channels" Version="6.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using HotChocolate.Execution.Processing;
using HotChocolate.Resolvers;

namespace HotChocolate.Execution.Internal;

/// <summary>
/// An unsafe class that provides a set of methods to access the
/// underlying data representations of the middleware context.
/// </summary>
public static class MiddlewareContextMarshal
{
/// <summary>
/// Gets access to the result data of an object in the GraphQL execution.
/// ResultData is pooled and writing to it can corrupt the result.
/// Multiple threads might be writing into the result object.
/// </summary>
/// <param name="context">
/// The resolver context.
/// </param>
/// <returns>
/// Returns the result data of the current resolver context.
/// </returns>
public static ObjectResult? GetParentResultUnsafe(IResolverContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

return context is MiddlewareContext middlewareContext
? middlewareContext.ParentResult
: null;
}

/// <summary>
/// Gets the parent result data of the current <paramref name="resultData"/>.
/// </summary>
/// <param name="resultData">
/// The result data for which to get the parent.
/// </param>
/// <typeparam name="T">
/// The type of the result data.
/// </typeparam>
/// <returns>
/// Returns the parent result data of the current <paramref name="resultData"/>.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Throws if <paramref name="resultData"/> is <c>null</c>.
/// </exception>
public static ResultData? GetParent<T>(T resultData) where T : ResultData
{
if (resultData == null)
{
throw new ArgumentNullException(nameof(resultData));
}

return resultData.Parent;
}

/// <summary>
/// Gets the index under which the <paramref name="resultData"/> is stored in the parent result.
/// </summary>
/// <param name="resultData">
/// The result data for which to get the parent index.
/// </param>
/// <typeparam name="T">
/// The type of the result data.
/// </typeparam>
/// <returns>
/// Returns the index under which the <paramref name="resultData"/> is stored in the parent result.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Throws if <paramref name="resultData"/> is <c>null</c>.
/// </exception>
public static int GetParentIndex<T>(T resultData) where T : ResultData
{
if (resultData == null)
{
throw new ArgumentNullException(nameof(resultData));
}

return resultData.ParentIndex;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using HotChocolate.Execution.Properties;
Expand Down
6 changes: 4 additions & 2 deletions src/HotChocolate/Core/src/Execution/Processing/PathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace HotChocolate.Execution.Processing;

internal static class PathHelper
{
private const int _initialPathLength = 64;

public static Path CreatePathFromContext(ObjectResult parent)
=> CreatePath(parent);

Expand All @@ -18,7 +20,7 @@ public static Path CreatePathFromContext(ISelection selection, ResultData parent

private static Path CreatePath(ResultData parent, object segmentValue)
{
object[] segments = ArrayPool<object>.Shared.Rent(64);
var segments = ArrayPool<object>.Shared.Rent(_initialPathLength);
segments[0] = segmentValue;
var length = Build(segments, parent);
var path = CreatePath(parent.PatchPath, segments, length);
Expand All @@ -28,7 +30,7 @@ private static Path CreatePath(ResultData parent, object segmentValue)

private static Path CreatePath(ResultData parent)
{
var segments = ArrayPool<object>.Shared.Rent(64);
var segments = ArrayPool<object>.Shared.Rent(_initialPathLength);
var length = Build(segments, parent, 0);
var path = CreatePath(parent.PatchPath, segments, length);
ArrayPool<object>.Shared.Return(segments);
Expand Down
1 change: 1 addition & 0 deletions src/HotChocolate/Core/src/Execution/RequestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public RequestExecutor(
CollectEnricher(applicationServices, list);
CollectEnricher(executorServices, list);
_enricher = list.ToArray();
return;

static void CollectEnricher(IServiceProvider services, List<IRequestContextEnricher> list)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ private void WriteCtorServiceResolution(List<RequestMiddlewareParameterInfo> par
{
case RequestMiddlewareParameterKind.Service when !parameter.IsNullable:
_writer.WriteIndentedLine(
"var cp{0} = core.Services.GetRequiredService<global::{1}>();",
"var cp{0} = core.Services.GetRequiredService<{1}>();",
i,
parameter.TypeName);
break;

case RequestMiddlewareParameterKind.Service when parameter.IsNullable:
_writer.WriteIndentedLine(
"var cp{0} = core.Services.GetService<global::{1}>();",
"var cp{0} = core.Services.GetService<{1}>();",
i,
parameter.TypeName);
break;
Expand Down Expand Up @@ -155,6 +155,11 @@ private void WriteFactory(string typeName, List<RequestMiddlewareParameterInfo>
for (var i = 0; i < parameters.Count; i++)
{
var parameter = parameters[i];

if(i > 0)
{
_writer.Write(", ");
}

if (parameter.Kind is RequestMiddlewareParameterKind.Next)
{
Expand All @@ -179,14 +184,14 @@ private void WriteInvokeServiceResolution(List<RequestMiddlewareParameterInfo> p
{
case RequestMiddlewareParameterKind.Service when !parameter.IsNullable:
_writer.WriteIndentedLine(
"var ip{0} = context.Services.GetRequiredService<global::{1}>();",
"var ip{0} = context.Services.GetRequiredService<{1}>();",
i,
parameter.TypeName);
break;

case RequestMiddlewareParameterKind.Service when parameter.IsNullable:
_writer.WriteIndentedLine(
"var ip{0} = context.Services.GetService<global::{1}>();",
"var ip{0} = context.Services.GetService<{1}>();",
i,
parameter.TypeName);
break;
Expand Down Expand Up @@ -217,6 +222,11 @@ private void WriteInvoke(string methodName, List<RequestMiddlewareParameterInfo>
for (var i = 0; i < parameters.Count; i++)
{
var parameter = parameters[i];

if(i > 0)
{
_writer.Write(", ");
}

if (parameter.Kind is RequestMiddlewareParameterKind.Next)
{
Expand All @@ -243,7 +253,7 @@ public void WriteInterceptMethod(

_writer.WriteIndentedLine(
"[InterceptsLocation(\"{0}\", {1}, {2})]",
location.FilePath,
location.FilePath.Replace("\\", "\\\\"),
location.LineNumber,
location.CharacterNumber);
_writer.WriteIndentedLine(
Expand Down
Loading

0 comments on commit 08ef4b2

Please sign in to comment.