-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it easier to write to the result state and the result extensions. (
- Loading branch information
1 parent
64c5ab9
commit baf13ae
Showing
11 changed files
with
247 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/HotChocolate/Core/src/Execution/Serialization/NeedsFormatting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Text.Json; | ||
|
||
namespace HotChocolate.Execution.Serialization; | ||
|
||
/// <summary> | ||
/// This helper class allows us to indicate to the formatters that the inner value | ||
/// has a custom formatter. | ||
/// </summary> | ||
/// <remarks> | ||
/// The downside of this helper is that we bind it explicitly to JSON. | ||
/// If there were alternative query formatter that use different formats we would get | ||
/// into trouble with this. | ||
/// | ||
/// This is also the reason for keeping this internal. | ||
/// </remarks> | ||
internal abstract class NeedsFormatting | ||
{ | ||
/// <summary> | ||
/// Formats the value as JSON | ||
/// </summary> | ||
/// <param name="writer"> | ||
/// The JSON writer. | ||
/// </param> | ||
/// <param name="options"> | ||
/// The JSON serializer options. | ||
/// </param> | ||
public abstract void FormatValue(Utf8JsonWriter writer, JsonSerializerOptions options); | ||
} | ||
|
||
/// <summary> | ||
/// This helper class allows us to indicate to the formatters that the inner value | ||
/// has a custom formatter. | ||
/// </summary> | ||
/// <remarks> | ||
/// The downside of this helper is that we bind it explicitly to JSON. | ||
/// If there were alternative query formatter that use different formats we would get | ||
/// into trouble with this. | ||
/// | ||
/// This is also the reason for keeping this internal. | ||
/// </remarks> | ||
internal sealed class NeedsFormatting<TValue> : NeedsFormatting | ||
{ | ||
private readonly TValue _value; | ||
|
||
public NeedsFormatting(TValue value) | ||
{ | ||
_value = value; | ||
} | ||
|
||
/// <summary> | ||
/// Formats the value as JSON | ||
/// </summary> | ||
/// <param name="writer"> | ||
/// The JSON writer. | ||
/// </param> | ||
/// <param name="options"> | ||
/// The JSON serializer options. | ||
/// </param> | ||
public override void FormatValue(Utf8JsonWriter writer, JsonSerializerOptions options) | ||
=> JsonSerializer.Serialize(writer, _value, options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/HotChocolate/Core/src/Types/Resolvers/IOperationResultBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#nullable enable | ||
namespace HotChocolate.Resolvers; | ||
|
||
/// <summary> | ||
/// This helper allows modifying some aspects of the overall operation result object. | ||
/// </summary> | ||
public interface IOperationResultBuilder | ||
{ | ||
/// <summary> | ||
/// Sets a property on the result context data which can be used for further processing | ||
/// in the request pipeline. | ||
/// </summary> | ||
/// <param name="key">The key.</param> | ||
/// <param name="value">The value.</param> | ||
void SetResultState(string key, object? value); | ||
|
||
/// <summary> | ||
/// Sets a property on the result extension data which will | ||
/// be serialized and send to the consumer. | ||
/// | ||
/// <code> | ||
/// { | ||
/// ... | ||
/// "extensions": { | ||
/// "yourKey": "yourValue" | ||
/// } | ||
/// } | ||
/// </code> | ||
/// | ||
/// </summary> | ||
/// <param name="key">The key.</param> | ||
/// <param name="value">The value.</param> | ||
void SetExtension<TValue>(string key, TValue value); | ||
} |
Oops, something went wrong.