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

Split Cookie Crumble into multiple libraries #7774

Merged
merged 4 commits into from
Nov 29, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
86 changes: 50 additions & 36 deletions src/CookieCrumble/CookieCrumble.sln
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2465C122-714C-4D0A-A24D-D9C22A25D73A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookieCrumble", "src\CookieCrumble\CookieCrumble.csproj", "{8E71FA9B-8352-4675-A9B4-A934E40AF9E0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{EB8F1D90-60D6-48FA-9744-D4180A0E4AC0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookieCrumble.Tests", "test\CookieCrumble.Tests\CookieCrumble.Tests.csproj", "{844E7501-7ED6-4548-8E99-D8E50D4F39A4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8E71FA9B-8352-4675-A9B4-A934E40AF9E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E71FA9B-8352-4675-A9B4-A934E40AF9E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E71FA9B-8352-4675-A9B4-A934E40AF9E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E71FA9B-8352-4675-A9B4-A934E40AF9E0}.Release|Any CPU.Build.0 = Release|Any CPU
{844E7501-7ED6-4548-8E99-D8E50D4F39A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{844E7501-7ED6-4548-8E99-D8E50D4F39A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{844E7501-7ED6-4548-8E99-D8E50D4F39A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{844E7501-7ED6-4548-8E99-D8E50D4F39A4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8E71FA9B-8352-4675-A9B4-A934E40AF9E0} = {2465C122-714C-4D0A-A24D-D9C22A25D73A}
{844E7501-7ED6-4548-8E99-D8E50D4F39A4} = {EB8F1D90-60D6-48FA-9744-D4180A0E4AC0}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2465C122-714C-4D0A-A24D-D9C22A25D73A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookieCrumble", "src\CookieCrumble\CookieCrumble.csproj", "{8E71FA9B-8352-4675-A9B4-A934E40AF9E0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookieCrumble.Fusion", "src\CookieCrumble.Fusion\CookieCrumble.Fusion.csproj", "{E6862862-986B-4A67-8703-49C70051DBDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookieCrumble.HotChocolate", "src\CookieCrumble.HotChocolate\CookieCrumble.HotChocolate.csproj", "{9B57E4BC-E62A-4B7B-94FB-462C5F92D35B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{EB8F1D90-60D6-48FA-9744-D4180A0E4AC0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookieCrumble.Tests", "test\CookieCrumble.Tests\CookieCrumble.Tests.csproj", "{844E7501-7ED6-4548-8E99-D8E50D4F39A4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8E71FA9B-8352-4675-A9B4-A934E40AF9E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E71FA9B-8352-4675-A9B4-A934E40AF9E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E71FA9B-8352-4675-A9B4-A934E40AF9E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E71FA9B-8352-4675-A9B4-A934E40AF9E0}.Release|Any CPU.Build.0 = Release|Any CPU
{E6862862-986B-4A67-8703-49C70051DBDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6862862-986B-4A67-8703-49C70051DBDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6862862-986B-4A67-8703-49C70051DBDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6862862-986B-4A67-8703-49C70051DBDC}.Release|Any CPU.Build.0 = Release|Any CPU
{9B57E4BC-E62A-4B7B-94FB-462C5F92D35B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B57E4BC-E62A-4B7B-94FB-462C5F92D35B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B57E4BC-E62A-4B7B-94FB-462C5F92D35B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B57E4BC-E62A-4B7B-94FB-462C5F92D35B}.Release|Any CPU.Build.0 = Release|Any CPU
{844E7501-7ED6-4548-8E99-D8E50D4F39A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{844E7501-7ED6-4548-8E99-D8E50D4F39A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{844E7501-7ED6-4548-8E99-D8E50D4F39A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{844E7501-7ED6-4548-8E99-D8E50D4F39A4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8E71FA9B-8352-4675-A9B4-A934E40AF9E0} = {2465C122-714C-4D0A-A24D-D9C22A25D73A}
{E6862862-986B-4A67-8703-49C70051DBDC} = {2465C122-714C-4D0A-A24D-D9C22A25D73A}
{9B57E4BC-E62A-4B7B-94FB-462C5F92D35B} = {2465C122-714C-4D0A-A24D-D9C22A25D73A}
{844E7501-7ED6-4548-8E99-D8E50D4F39A4} = {EB8F1D90-60D6-48FA-9744-D4180A0E4AC0}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>CookieCrumble.Fusion</AssemblyName>
<RootNamespace>CookieCrumble.Fusion</RootNamespace>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CookieCrumble\CookieCrumble.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\Fusion\src\Core\HotChocolate.Fusion.csproj" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions src/CookieCrumble/src/CookieCrumble.Fusion/CookieCrumbleFusion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using CookieCrumble.Fusion.Formatters;

namespace CookieCrumble.Fusion;

public static class CookieCrumbleFusion
{
public static void Initialize()
{
Snapshot.TryRegisterFormatter(SnapshotValueFormatters.QueryPlan);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Buffers;
using CookieCrumble.Formatters;
using HotChocolate.Fusion.Execution.Nodes;

namespace CookieCrumble.Formatters;
namespace CookieCrumble.Fusion.Formatters;

internal sealed class QueryPlanSnapshotValueFormatter() : SnapshotValueFormatter<QueryPlan>("json")
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using CookieCrumble.Formatters;

namespace CookieCrumble.Fusion.Formatters;

/// <summary>
/// Provides access to well-known snapshot value formatters.
/// </summary>
public static class SnapshotValueFormatters
{
public static ISnapshotValueFormatter QueryPlan { get; } =
new QueryPlanSnapshotValueFormatter();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>CookieCrumble.HotChocolate</AssemblyName>
<RootNamespace>CookieCrumble.HotChocolate</RootNamespace>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CookieCrumble\CookieCrumble.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\AspNetCore\src\Transport.Abstractions\HotChocolate.Transport.Abstractions.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\AspNetCore\src\Transport.Http\HotChocolate.Transport.Http.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\Core\src\Execution\HotChocolate.Execution.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\Core\src\Types\HotChocolate.Types.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\Language\src\Language.SyntaxTree\HotChocolate.Language.SyntaxTree.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using CookieCrumble.HotChocolate.Formatters;

namespace CookieCrumble.HotChocolate;

public static class CookieCrumbleHotChocolate
{
public static void Initialize()
{
Snapshot.TryRegisterFormatter(SnapshotValueFormatters.ExecutionResult);
Snapshot.TryRegisterFormatter(SnapshotValueFormatters.GraphQL);
Snapshot.TryRegisterFormatter(SnapshotValueFormatters.GraphQLHttp);
Snapshot.TryRegisterFormatter(SnapshotValueFormatters.OperationResult);
Snapshot.TryRegisterFormatter(SnapshotValueFormatters.Schema);
Snapshot.TryRegisterFormatter(SnapshotValueFormatters.SchemaError);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using HotChocolate.Execution.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace CookieCrumble;
namespace CookieCrumble.HotChocolate;

public static class CommonTestExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using CookieCrumble.HotChocolate.Formatters;
using HotChocolate;
using HotChocolate.Execution;
using HotChocolate.Language;
using CoreFormatters = CookieCrumble.Formatters.SnapshotValueFormatters;

namespace CookieCrumble.HotChocolate;

public static class SnapshotExtensions
{
public static void MatchSnapshot(
this ISyntaxNode? value,
string? postFix = null)
=> Snapshot.Match(
value,
postFix,
extension: ".graphql",
formatter: SnapshotValueFormatters.GraphQL);

public static void MatchSnapshot(
this ISchema? value,
string? postFix = null)
=> Snapshot.Match(
value,
postFix,
extension: ".graphql",
formatter: SnapshotValueFormatters.Schema);

public static void MatchSnapshot(
this IExecutable? value,
string? postFix = null)
=> Snapshot.Match(
value,
postFix,
formatter: CoreFormatters.PlainText);

public static Snapshot AddResult(
this Snapshot snapshot,
IExecutionResult result,
string? name = null)
{
if (result.ContextData is null)
{
snapshot.Add(result.ToJson(), name);
return snapshot;
}

snapshot.Add(
result.ToJson(),
string.IsNullOrEmpty(name)
? "Result:"
: $"{name} Result:");

if (result.ContextData.TryGetValue("query", out var queryResult) &&
queryResult is string queryString &&
!string.IsNullOrWhiteSpace(queryString))
{
snapshot.Add(
queryString,
string.IsNullOrEmpty(name)
? "Query:"
: $"{name} Query:",
CoreFormatters.PlainText);
}

if (result.ContextData.TryGetValue("sql", out var sql))
{
snapshot.Add(
sql,
string.IsNullOrEmpty(name)
? "SQL:"
: $"{name} SQL:",
CoreFormatters.PlainText);
}

if (result.ContextData.TryGetValue("expression", out var expression))
{
snapshot.Add(
expression,
string.IsNullOrEmpty(name)
? "Expression:"
: $"{name} Expression:",
CoreFormatters.PlainText);
}

if (result.ContextData.TryGetValue("ex", out var exception))
{
snapshot.Add(exception, "Exception:");
}

return snapshot;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Buffers;
using System.Text.Json;
using System.Text.Json.Nodes;
using CookieCrumble.Formatters;
using HotChocolate;
using HotChocolate.Execution;

namespace CookieCrumble.Formatters;
namespace CookieCrumble.HotChocolate.Formatters;

internal sealed class ExecutionResultSnapshotValueFormatter
: SnapshotValueFormatter<IExecutionResult>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
using System.Buffers;
using System.Net.Http.Headers;
using System.Text.Json;
using CookieCrumble.Formatters;
using HotChocolate.Transport.Http;
using Microsoft.AspNetCore.WebUtilities;

namespace CookieCrumble.Formatters;
namespace CookieCrumble.HotChocolate.Formatters;

internal sealed class GraphQLHttpResponseFormatter : SnapshotValueFormatter<HttpResponseMessage>
internal sealed class GraphQLHttpResponseFormatter : SnapshotValueFormatter<GraphQLHttpResponse>
{
protected override void Format(IBufferWriter<byte> snapshot, HttpResponseMessage value)
protected override void Format(IBufferWriter<byte> snapshot, GraphQLHttpResponse value)
{
var contentType = value.Content.Headers.ContentType;
var contentType = value.ContentHeaders.ContentType;

if (string.Equals(contentType?.MediaType, "multipart/mixed", StringComparison.Ordinal))
{
var boundary = contentType!.Parameters.First(
t => string.Equals(t.Name, "boundary", StringComparison.Ordinal));
FormatStreamAsync(snapshot, boundary, value.Content.ReadAsStream()).Wait();
FormatStreamAsync(snapshot, boundary, value.HttpResponseMessage.Content.ReadAsStream()).Wait();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Buffers;
using CookieCrumble.Formatters;
using HotChocolate.Language;
using HotChocolate.Language.Utilities;

namespace CookieCrumble.Formatters;
namespace CookieCrumble.HotChocolate.Formatters;

internal sealed class GraphQLSnapshotValueFormatter : SnapshotValueFormatter<ISyntaxNode>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Buffers;
using System.Text.Json;
using CookieCrumble.Formatters;
using HotChocolate.Transport;

namespace CookieCrumble.Formatters;
namespace CookieCrumble.HotChocolate.Formatters;

internal sealed class OperationResultSnapshotValueFormatter : SnapshotValueFormatter<OperationResult>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Buffers;
using CookieCrumble.Formatters;
using HotChocolate;

namespace CookieCrumble.Formatters;
namespace CookieCrumble.HotChocolate.Formatters;

internal sealed class SchemaErrorSnapshotValueFormatter
: SnapshotValueFormatter<ISchemaError[]>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Buffers;
using CookieCrumble.Formatters;
using HotChocolate;

namespace CookieCrumble.Formatters;
namespace CookieCrumble.HotChocolate.Formatters;

internal sealed class SchemaSnapshotValueFormatter() : SnapshotValueFormatter<ISchema>("graphql")
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using CookieCrumble.Formatters;

namespace CookieCrumble.HotChocolate.Formatters;

/// <summary>
/// Provides access to well-known snapshot value formatters.
/// </summary>
public static class SnapshotValueFormatters
{
public static ISnapshotValueFormatter ExecutionResult { get; } =
new ExecutionResultSnapshotValueFormatter();

public static ISnapshotValueFormatter GraphQL { get; } =
new GraphQLSnapshotValueFormatter();

public static ISnapshotValueFormatter GraphQLHttp { get; } =
new GraphQLHttpResponseFormatter();

public static ISnapshotValueFormatter OperationResult { get; } =
new OperationResultSnapshotValueFormatter();

public static ISnapshotValueFormatter Schema { get; } =
new SchemaSnapshotValueFormatter();

public static ISnapshotValueFormatter SchemaError { get; } =
new SchemaErrorSnapshotValueFormatter();
}
7 changes: 0 additions & 7 deletions src/CookieCrumble/src/CookieCrumble/CookieCrumble.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,4 @@
<PackageReference Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\HotChocolate\Core\src\Core\HotChocolate.Core.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\AspNetCore\src\AspNetCore\HotChocolate.AspNetCore.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\AspNetCore\src\Transport.Abstractions\HotChocolate.Transport.Abstractions.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\Fusion\src\Core\HotChocolate.Fusion.csproj" />
</ItemGroup>

</Project>
Loading
Loading