Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if FUSION
namespace HotChocolate.Fusion.Transport;
#else
namespace HotChocolate.Transport;
#endif

/// <summary>
/// This class provides the default content types for GraphQL requests and responses.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using static HotChocolate.Transport.Properties.TransportAbstractionResources;

namespace HotChocolate.Transport.Http;
#if FUSION
namespace HotChocolate.Fusion.Transport;
#else
namespace HotChocolate.Transport;
#endif

/// <summary>
/// A file reference can be used to upload a file with the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace HotChocolate.Transport.Http;
#if FUSION
namespace HotChocolate.Fusion.Transport;
#else
namespace HotChocolate.Transport;
#endif

/// <summary>
/// The file reference info contains the actual
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using HotChocolate.Language;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Transport.Http;
#if FUSION
namespace HotChocolate.Fusion.Transport;
#else
namespace HotChocolate.Transport;
#endif

/// <summary>
/// This file literal is used in order to allow for file references in <see cref="ObjectValueNode"/>.
Expand Down Expand Up @@ -61,7 +65,11 @@ public FileReferenceNode(FileReference value)
/// Gets a <see cref="Location"/> of this node in the parsed source text
/// if available the parser provided this information.
/// </summary>
#if FUSION
public HotChocolate.Language.Location? Location => null;
#else
public Location? Location => null;
#endif

/// <summary>
/// Gets the actual file reference.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using HotChocolate.Language;

#if FUSION
namespace HotChocolate.Fusion.Transport;
#else
namespace HotChocolate.Transport;
#endif

public interface IOperationRequest : IRequestBody
{
Expand All @@ -24,6 +28,13 @@ public interface IOperationRequest : IRequestBody
/// </summary>
ErrorHandlingMode? OnError { get; }

#if FUSION
/// <summary>
/// Gets an <see cref="JsonSegment"/> representing the extension values to include with the
/// operation.
/// </summary>
JsonSegment Extensions { get; }
#else
/// <summary>
/// Gets a dictionary containing extension values to include with the operation.
/// </summary>
Expand All @@ -34,4 +45,5 @@ public interface IOperationRequest : IRequestBody
/// operation.
/// </summary>
ObjectValueNode? ExtensionsNode { get; }
#endif
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
#if FUSION
using HotChocolate.Text.Json;

namespace HotChocolate.Fusion.Transport;
#else
using System.Text.Json;

namespace HotChocolate.Transport;
#endif

/// <summary>
/// Represents a GraphQL request body that can be sent over a WebSocket connection or HTTP connection.
/// </summary>
public interface IRequestBody
{
#if FUSION
/// <summary>
/// Writes a serialized version of this request to a <see cref="JsonWriter"/>.
/// </summary>
/// <param name="writer">
/// The JSON writer.
/// </param>
void WriteTo(JsonWriter writer);
#else
/// <summary>
/// Writes a serialized version of this request to a <see cref="Utf8JsonWriter"/>.
/// </summary>
/// <param name="writer">
/// The JSON writer.
/// </param>
void WriteTo(Utf8JsonWriter writer);
#endif
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#if FUSION
using System.Collections.Immutable;
using HotChocolate.Text.Json;
using HotChocolate.Fusion.Transport.Http;
using HotChocolate.Fusion.Transport.Serialization;

namespace HotChocolate.Fusion.Transport;
#else
using System.Collections.Immutable;
using System.Text.Json;
using HotChocolate.Transport.Serialization;

namespace HotChocolate.Transport;
#endif

/// <summary>
/// Represents a GraphQL batch request that can be sent over a WebSocket or HTTP connection.
Expand All @@ -11,11 +20,32 @@ public readonly struct OperationBatchRequest
: IRequestBody
, IEquatable<OperationBatchRequest>
{
#if FUSION
/// <summary>
/// Gets the list of operation requests to execute.
/// Initializes a new instance of <see cref="OperationBatchRequest"/> with the specified
/// immutable array of operation requests.
/// </summary>
public ImmutableArray<IOperationRequest> Requests { get; }
/// <param name="requests">
/// The requests of this batch.
/// </param>
/// <param name="fileMap">
/// The file map entries for multipart file uploads. Default is empty.
/// </param>
public OperationBatchRequest(
ImmutableArray<IOperationRequest> requests,
ImmutableArray<FileEntry> fileMap = default)
{
if (requests.IsDefaultOrEmpty)
{
throw new ArgumentException(
"The batch request must contain at least one operation.",
nameof(requests));
}

Requests = requests;
FileMap = fileMap;
}
#else
/// <summary>
/// Initializes a new instance of <see cref="OperationBatchRequest"/> with the specified
/// immutable array of operation requests.
Expand All @@ -37,6 +67,22 @@ public OperationBatchRequest(ImmutableArray<IOperationRequest> requests)

Requests = requests;
}
#endif

/// <summary>
/// Gets the list of operation requests to execute.
/// </summary>
public ImmutableArray<IOperationRequest> Requests { get; }

#if FUSION
/// <summary>
/// Gets the file map entries for multipart file uploads.
/// Each entry maps a file key in the variable JSON to the actual file stream,
/// enabling the transport layer to construct the multipart form per the
/// GraphQL multipart request specification.
/// </summary>
public ImmutableArray<FileEntry> FileMap { get; }
#endif

/// <summary>
/// Writes the request to the specified <paramref name="writer"/>.
Expand All @@ -47,7 +93,11 @@ public OperationBatchRequest(ImmutableArray<IOperationRequest> requests)
/// <exception cref="ArgumentNullException">
/// Thrown if the <paramref name="writer"/> is <see langword="null"/>.
/// </exception>
#if FUSION
public void WriteTo(JsonWriter writer)
#else
public void WriteTo(Utf8JsonWriter writer)
#endif
{
ArgumentNullException.ThrowIfNull(writer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,68 @@
#if FUSION
using System.Collections.Immutable;
using HotChocolate.Language;
using HotChocolate.Fusion.Execution;
using HotChocolate.Fusion.Transport.Http;
using HotChocolate.Fusion.Transport.Serialization;
using HotChocolate.Text.Json;

namespace HotChocolate.Fusion.Transport;
#else
using System.Text.Json;
using HotChocolate.Language;
using HotChocolate.Transport.Serialization;

namespace HotChocolate.Transport;
#endif

/// <summary>
/// Represents a GraphQL operation request that can be sent over a WebSocket or HTTP connection.
/// </summary>
public sealed class OperationRequest : IEquatable<OperationRequest>, IOperationRequest
{
#if FUSION
/// <summary>
/// Initializes a new instance of the <see cref="OperationRequest"/> struct.
/// </summary>
/// <param name="query">
/// The query document containing the operation to execute.
/// </param>
/// <param name="id">
/// The ID of a previously persisted operation that should be executed.
/// </param>
/// <param name="operationName">
/// The name of the operation to execute.
/// </param>
/// <param name="onError">
/// The requested error handling mode.
/// </param>
/// <param name="variables">
/// The pre-serialized variable values to use when executing the operation.
/// </param>
/// <param name="extensions">
/// The pre-serialized extension values to include with the operation.
/// </param>
/// <param name="fileMap">
/// The file map entries for multipart file uploads. Default is empty.
/// </param>
public OperationRequest(
string? query,
string? id,
string? operationName,
ErrorHandlingMode? onError,
VariableValues variables,
JsonSegment extensions,
ImmutableArray<FileEntry> fileMap = default)
{
Query = query;
Id = id;
OperationName = operationName;
OnError = onError;
Variables = variables;
Extensions = extensions;
FileMap = fileMap;
}
#else
/// <summary>
/// Initializes a new instance of the <see cref="OperationRequest"/> struct.
/// </summary>
Expand Down Expand Up @@ -88,6 +142,7 @@ public OperationRequest(
Variables = variables;
Extensions = extensions;
}
#endif

/// <summary>
/// Gets the ID of a previously persisted operation that should be executed.
Expand All @@ -109,6 +164,25 @@ public OperationRequest(
/// </summary>
public ErrorHandlingMode? OnError { get; }

#if FUSION
/// <summary>
/// Gets the pre-serialized variable values to use when executing the operation.
/// </summary>
public VariableValues Variables { get; }

/// <summary>
/// Gets the pre-serialized extension values to include with the operation.
/// </summary>
public JsonSegment Extensions { get; }

/// <summary>
/// Gets the file map entries for multipart file uploads.
/// Each entry maps a file key in the variable JSON to the actual file stream,
/// enabling the transport layer to construct the multipart form per the
/// GraphQL multipart request specification.
/// </summary>
public ImmutableArray<FileEntry> FileMap { get; }
#else
/// <summary>
/// Gets a dictionary containing the variable values to use when executing the operation.
/// </summary>
Expand All @@ -130,14 +204,19 @@ public OperationRequest(
/// operation.
/// </summary>
public ObjectValueNode? ExtensionsNode { get; }
#endif

/// <summary>
/// Writes a serialized version of this request to a <see cref="Utf8JsonWriter"/>.
/// Writes a serialized version of this request to a JSON writer.
/// </summary>
/// <param name="writer">
/// The JSON writer.
/// </param>
#if FUSION
public void WriteTo(JsonWriter writer)
#else
public void WriteTo(Utf8JsonWriter writer)
#endif
{
ArgumentNullException.ThrowIfNull(writer);

Expand All @@ -153,6 +232,28 @@ public void WriteTo(Utf8JsonWriter writer)
/// <returns>
/// <see langword="true"/> if the two objects are equal; otherwise, <see langword="false"/>.
/// </returns>
#if FUSION
public bool Equals(OperationRequest? other)
{
if (other is null)
{
return false;
}

return Id == other.Id
&& Query == other.Query
&& Variables.Equals(other.Variables)
&& Extensions.Equals(other.Extensions);
}

/// <inheritdoc/>
public override bool Equals(object? obj)
=> obj is OperationRequest other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode()
=> HashCode.Combine(Id, Query, Variables, Extensions);
#else
public bool Equals(OperationRequest? other)
{
if (other is null)
Expand All @@ -175,6 +276,7 @@ public override bool Equals(object? obj)
/// <inheritdoc/>
public override int GetHashCode()
=> HashCode.Combine(Id, Query, Variables, Extensions, VariablesNode, ExtensionsNode);
#endif

/// <summary>
/// Determines whether two <see cref="OperationRequest"/> objects are equal.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System.Text.Encodings.Web;
using System.Text.Json;

#if FUSION
namespace HotChocolate.Fusion.Transport.Serialization;
#else
namespace HotChocolate.Transport.Serialization;
#endif

/// <summary>
/// A helper class that contains the default settings for JSON serialization.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if FUSION
namespace HotChocolate.Fusion.Transport.Serialization;
#else
namespace HotChocolate.Transport.Serialization;
#endif

/// <summary>
/// A helper class that contains the default names of the GraphQL request properties.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#if FUSION
namespace HotChocolate.Fusion.Transport.Serialization;
#else
namespace HotChocolate.Transport.Serialization;
#endif

/// <summary>
/// This helper class contains the default property names for the GraphQL result object.
Expand Down
Loading
Loading