Skip to content

Commit

Permalink
Merge branch 'main' into chore/#6868-GreenDonutPackageClean
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Feb 10, 2024
2 parents 75b73f0 + a3b1259 commit ebaca1e
Show file tree
Hide file tree
Showing 897 changed files with 2,899 additions and 4,279 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,7 @@ jobs:
path: |
**/__mismatch__/*
- name: Fail if tests failed or were cancelled
run: exit 1
if: |
steps.run-tests.outcome == 'failure' ||
steps.run-tests.outcome == 'cancelled'
codeql:
name: CodeQL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Buffers;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Text.Json.Nodes;
using HotChocolate;
Expand All @@ -21,6 +20,26 @@ protected override void Format(IBufferWriter<byte> snapshot, IExecutionResult va
FormatStreamAsync(snapshot, (IResponseStream)value).Wait();
}
}

protected override void FormatMarkdown(IBufferWriter<byte> snapshot, IExecutionResult value)
{
if (value.Kind is ExecutionResultKind.SingleResult)
{
snapshot.Append("```json");
snapshot.AppendLine();
snapshot.Append(value.ToJson());
}
else
{
snapshot.Append("```text");
snapshot.AppendLine();
FormatStreamAsync(snapshot, (IResponseStream)value).Wait();
}

snapshot.AppendLine();
snapshot.Append("```");
snapshot.AppendLine();
}

private static async Task FormatStreamAsync(
IBufferWriter<byte> snapshot,
Expand Down Expand Up @@ -79,7 +98,7 @@ private static async Task FormatStreamAsync(
}
}

internal class JsonResultPatcher
internal sealed class JsonResultPatcher
{
private const string _data = "data";
private const string _items = "items";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ private static async Task FormatStreamAsync(
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Buffers;
using HotChocolate;
using HotChocolate.Language;
using HotChocolate.Language.Utilities;

Expand Down Expand Up @@ -27,4 +26,14 @@ protected override void Format(IBufferWriter<byte> snapshot, ISyntaxNode value)

ArrayPool<char>.Shared.Return(buffer);
}

protected override void FormatMarkdown(IBufferWriter<byte> snapshot, ISyntaxNode value)
{
snapshot.Append("```graphql");
snapshot.AppendLine();
Format(snapshot, value);
snapshot.AppendLine();
snapshot.Append("```");
snapshot.AppendLine();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Buffers;

namespace CookieCrumble.Formatters;

/// <summary>
/// Formats a snapshot segment value for the snapshot file.
/// </summary>
public interface IMarkdownSnapshotValueFormatter
{
/// <summary>
/// Specifies if the formatter can handle the snapshot segment value.
/// </summary>
/// <param name="value">
/// The snapshot segment value.
/// </param>
/// <returns>
/// <c>true</c> if the formatter can handle the snapshot segment value;
/// otherwise, <c>false</c>.
/// </returns>
bool CanHandle(object? value);

/// <summary>
/// Formats the specified snapshot segment value for the snapshot file.
/// </summary>
/// <param name="snapshot">
/// The snapshot file writer.
/// </param>
/// <param name="value">
/// The snapshot segment vale.
/// </param>
void FormatMarkdown(IBufferWriter<byte> snapshot, object? value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ public interface ISnapshotValueFormatter
/// The snapshot segment vale.
/// </param>
void Format(IBufferWriter<byte> snapshot, object? value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Buffers;
using System.Text.Encodings.Web;
using System.Text.Json;

namespace CookieCrumble.Formatters;

internal sealed class JsonElementSnapshotValueFormatter : SnapshotValueFormatter<JsonElement>
{
private readonly JsonSerializerOptions _options =
new(JsonSerializerDefaults.Web)
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
};

protected override void Format(IBufferWriter<byte> snapshot, JsonElement value)
{
var buffer = JsonSerializer.SerializeToUtf8Bytes(value, _options);
var span = snapshot.GetSpan(buffer.Length);
buffer.AsSpan().CopyTo(span);
snapshot.Advance(buffer.Length);
}

protected override void FormatMarkdown(IBufferWriter<byte> snapshot, JsonElement value)
{
snapshot.Append("```json");
snapshot.AppendLine();
Format(snapshot, value);
snapshot.AppendLine();
snapshot.Append("```");
snapshot.AppendLine();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if NET7_0_OR_GREATER
using System.Buffers;
using HotChocolate.Fusion.Execution.Nodes;
using HotChocolate.Fusion.Planning;

namespace CookieCrumble.Formatters;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@ internal sealed class SchemaSnapshotValueFormatter : SnapshotValueFormatter<ISch
{
protected override void Format(IBufferWriter<byte> snapshot, ISchema value)
=> snapshot.Append(value.ToString());

protected override void FormatMarkdown(IBufferWriter<byte> snapshot, ISchema value)
{
snapshot.Append("```graphql");
snapshot.AppendLine();
Format(snapshot, value);
snapshot.AppendLine();
snapshot.Append("```");
snapshot.AppendLine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace CookieCrumble.Formatters;
/// <summary>
/// Formats a snapshot segment value for the snapshot file.
/// </summary>
public abstract class SnapshotValueFormatter<TValue> : ISnapshotValueFormatter
public abstract class SnapshotValueFormatter<TValue>
: ISnapshotValueFormatter
, IMarkdownSnapshotValueFormatter
{
public bool CanHandle(object? value)
=> value is TValue casted && CanHandle(casted);
Expand All @@ -15,6 +17,19 @@ protected virtual bool CanHandle(TValue? value)

public void Format(IBufferWriter<byte> snapshot, object? value)
=> Format(snapshot, (TValue)value!);

public void FormatMarkdown(IBufferWriter<byte> snapshot, object? value)
=> FormatMarkdown(snapshot, (TValue)value!);

protected abstract void Format(IBufferWriter<byte> snapshot, TValue value);

protected virtual void FormatMarkdown(IBufferWriter<byte> snapshot, TValue value)
{
snapshot.Append("```text");
snapshot.AppendLine();
Format(snapshot, value);
snapshot.AppendLine();
snapshot.Append("```");
snapshot.AppendLine();
}
}
1 change: 0 additions & 1 deletion src/CookieCrumble/src/CookieCrumble/LocalFactDiscoverer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
Expand Down
Loading

0 comments on commit ebaca1e

Please sign in to comment.