Skip to content

Commit d9b3a66

Browse files
authored
Refined Query Conventions (#6880)
1 parent 1634426 commit d9b3a66

File tree

894 files changed

+2896
-4276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

894 files changed

+2896
-4276
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,7 @@ jobs:
275275
path: |
276276
**/__mismatch__/*
277277
278-
- name: Fail if tests failed or were cancelled
279-
run: exit 1
280-
if: |
281-
steps.run-tests.outcome == 'failure' ||
282-
steps.run-tests.outcome == 'cancelled'
278+
283279
284280
codeql:
285281
name: CodeQL

src/CookieCrumble/src/CookieCrumble/Formatters/ExecutionResultSnapshotValueFormatter.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Buffers;
2-
using System.Runtime.InteropServices;
32
using System.Text.Json;
43
using System.Text.Json.Nodes;
54
using HotChocolate;
@@ -21,6 +20,26 @@ protected override void Format(IBufferWriter<byte> snapshot, IExecutionResult va
2120
FormatStreamAsync(snapshot, (IResponseStream)value).Wait();
2221
}
2322
}
23+
24+
protected override void FormatMarkdown(IBufferWriter<byte> snapshot, IExecutionResult value)
25+
{
26+
if (value.Kind is ExecutionResultKind.SingleResult)
27+
{
28+
snapshot.Append("```json");
29+
snapshot.AppendLine();
30+
snapshot.Append(value.ToJson());
31+
}
32+
else
33+
{
34+
snapshot.Append("```text");
35+
snapshot.AppendLine();
36+
FormatStreamAsync(snapshot, (IResponseStream)value).Wait();
37+
}
38+
39+
snapshot.AppendLine();
40+
snapshot.Append("```");
41+
snapshot.AppendLine();
42+
}
2443

2544
private static async Task FormatStreamAsync(
2645
IBufferWriter<byte> snapshot,
@@ -79,7 +98,7 @@ private static async Task FormatStreamAsync(
7998
}
8099
}
81100

82-
internal class JsonResultPatcher
101+
internal sealed class JsonResultPatcher
83102
{
84103
private const string _data = "data";
85104
private const string _items = "items";

src/CookieCrumble/src/CookieCrumble/Formatters/GraphQLHttpResponseFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ private static async Task FormatStreamAsync(
6565
}
6666
}
6767
}
68-
}
68+
}

src/CookieCrumble/src/CookieCrumble/Formatters/GraphQLSnapshotValueFormatter.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Buffers;
2-
using HotChocolate;
32
using HotChocolate.Language;
43
using HotChocolate.Language.Utilities;
54

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

2827
ArrayPool<char>.Shared.Return(buffer);
2928
}
29+
30+
protected override void FormatMarkdown(IBufferWriter<byte> snapshot, ISyntaxNode value)
31+
{
32+
snapshot.Append("```graphql");
33+
snapshot.AppendLine();
34+
Format(snapshot, value);
35+
snapshot.AppendLine();
36+
snapshot.Append("```");
37+
snapshot.AppendLine();
38+
}
3039
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Buffers;
2+
3+
namespace CookieCrumble.Formatters;
4+
5+
/// <summary>
6+
/// Formats a snapshot segment value for the snapshot file.
7+
/// </summary>
8+
public interface IMarkdownSnapshotValueFormatter
9+
{
10+
/// <summary>
11+
/// Specifies if the formatter can handle the snapshot segment value.
12+
/// </summary>
13+
/// <param name="value">
14+
/// The snapshot segment value.
15+
/// </param>
16+
/// <returns>
17+
/// <c>true</c> if the formatter can handle the snapshot segment value;
18+
/// otherwise, <c>false</c>.
19+
/// </returns>
20+
bool CanHandle(object? value);
21+
22+
/// <summary>
23+
/// Formats the specified snapshot segment value for the snapshot file.
24+
/// </summary>
25+
/// <param name="snapshot">
26+
/// The snapshot file writer.
27+
/// </param>
28+
/// <param name="value">
29+
/// The snapshot segment vale.
30+
/// </param>
31+
void FormatMarkdown(IBufferWriter<byte> snapshot, object? value);
32+
}

src/CookieCrumble/src/CookieCrumble/Formatters/ISnapshotValueFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ public interface ISnapshotValueFormatter
2929
/// The snapshot segment vale.
3030
/// </param>
3131
void Format(IBufferWriter<byte> snapshot, object? value);
32-
}
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Buffers;
2+
using System.Text.Encodings.Web;
3+
using System.Text.Json;
4+
5+
namespace CookieCrumble.Formatters;
6+
7+
internal sealed class JsonElementSnapshotValueFormatter : SnapshotValueFormatter<JsonElement>
8+
{
9+
private readonly JsonSerializerOptions _options =
10+
new(JsonSerializerDefaults.Web)
11+
{
12+
WriteIndented = true,
13+
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
14+
};
15+
16+
protected override void Format(IBufferWriter<byte> snapshot, JsonElement value)
17+
{
18+
var buffer = JsonSerializer.SerializeToUtf8Bytes(value, _options);
19+
var span = snapshot.GetSpan(buffer.Length);
20+
buffer.AsSpan().CopyTo(span);
21+
snapshot.Advance(buffer.Length);
22+
}
23+
24+
protected override void FormatMarkdown(IBufferWriter<byte> snapshot, JsonElement value)
25+
{
26+
snapshot.Append("```json");
27+
snapshot.AppendLine();
28+
Format(snapshot, value);
29+
snapshot.AppendLine();
30+
snapshot.Append("```");
31+
snapshot.AppendLine();
32+
}
33+
}

src/CookieCrumble/src/CookieCrumble/Formatters/QueryPlanSnapshotValueFormatter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#if NET7_0_OR_GREATER
22
using System.Buffers;
33
using HotChocolate.Fusion.Execution.Nodes;
4-
using HotChocolate.Fusion.Planning;
54

65
namespace CookieCrumble.Formatters;
76

src/CookieCrumble/src/CookieCrumble/Formatters/SchemaSnapshotValueFormatter.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,14 @@ internal sealed class SchemaSnapshotValueFormatter : SnapshotValueFormatter<ISch
77
{
88
protected override void Format(IBufferWriter<byte> snapshot, ISchema value)
99
=> snapshot.Append(value.ToString());
10+
11+
protected override void FormatMarkdown(IBufferWriter<byte> snapshot, ISchema value)
12+
{
13+
snapshot.Append("```graphql");
14+
snapshot.AppendLine();
15+
Format(snapshot, value);
16+
snapshot.AppendLine();
17+
snapshot.Append("```");
18+
snapshot.AppendLine();
19+
}
1020
}

src/CookieCrumble/src/CookieCrumble/Formatters/SnapshotValueFormatter.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ namespace CookieCrumble.Formatters;
55
/// <summary>
66
/// Formats a snapshot segment value for the snapshot file.
77
/// </summary>
8-
public abstract class SnapshotValueFormatter<TValue> : ISnapshotValueFormatter
8+
public abstract class SnapshotValueFormatter<TValue>
9+
: ISnapshotValueFormatter
10+
, IMarkdownSnapshotValueFormatter
911
{
1012
public bool CanHandle(object? value)
1113
=> value is TValue casted && CanHandle(casted);
@@ -15,6 +17,19 @@ protected virtual bool CanHandle(TValue? value)
1517

1618
public void Format(IBufferWriter<byte> snapshot, object? value)
1719
=> Format(snapshot, (TValue)value!);
20+
21+
public void FormatMarkdown(IBufferWriter<byte> snapshot, object? value)
22+
=> FormatMarkdown(snapshot, (TValue)value!);
1823

1924
protected abstract void Format(IBufferWriter<byte> snapshot, TValue value);
25+
26+
protected virtual void FormatMarkdown(IBufferWriter<byte> snapshot, TValue value)
27+
{
28+
snapshot.Append("```text");
29+
snapshot.AppendLine();
30+
Format(snapshot, value);
31+
snapshot.AppendLine();
32+
snapshot.Append("```");
33+
snapshot.AppendLine();
34+
}
2035
}

0 commit comments

Comments
 (0)