Skip to content
Open
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
1 change: 1 addition & 0 deletions src/All.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
<Folder Name="/HotChocolate/Language/src/">
<Project Path="HotChocolate/Language/src/Language.SyntaxTree/HotChocolate.Language.SyntaxTree.csproj" />
<Project Path="HotChocolate/Language/src/Language.Utf8/HotChocolate.Language.Utf8.csproj" />
<Project Path="HotChocolate/Language/src/Language.Utf8.SyntaxTree/HotChocolate.Language.Utf8.SyntaxTree.csproj" />
<Project Path="HotChocolate/Language/src/Language.Visitors/HotChocolate.Language.Visitors.csproj" />
<Project Path="HotChocolate/Language/src/Language.Web/HotChocolate.Language.Web.csproj" />
<Project Path="HotChocolate/Language/src/Language/HotChocolate.Language.csproj" />
Expand Down
1 change: 1 addition & 0 deletions src/Build.Pack.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Project Path="HotChocolate/Json/src/Json/HotChocolate.Text.Json.csproj" />
<Project Path="HotChocolate/Language/src/Language.SyntaxTree/HotChocolate.Language.SyntaxTree.csproj" />
<Project Path="HotChocolate/Language/src/Language.Utf8/HotChocolate.Language.Utf8.csproj" />
<Project Path="HotChocolate/Language/src/Language.Utf8.SyntaxTree/HotChocolate.Language.Utf8.SyntaxTree.csproj" />
<Project Path="HotChocolate/Language/src/Language.Visitors/HotChocolate.Language.Visitors.csproj" />
<Project Path="HotChocolate/Language/src/Language.Web/HotChocolate.Language.Web.csproj" />
<Project Path="HotChocolate/Language/src/Language/HotChocolate.Language.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ public interface IOperationRequest : IRequestBody
/// </summary>
string? Id { get; }

#if FUSION
/// <summary>
/// Gets the UTF-8 encoded query document containing the operation to execute.
/// </summary>
ReadOnlyMemory<byte> Query { get; }
#else
/// <summary>
/// Gets the query string or document containing the operation to execute.
/// </summary>
string? Query { get; }
#endif

/// <summary>
/// Gets the name of the operation to execute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class OperationRequest : IEquatable<OperationRequest>, IOperationR
/// Initializes a new instance of the <see cref="OperationRequest"/> struct.
/// </summary>
/// <param name="query">
/// The query document containing the operation to execute.
/// The UTF-8 encoded query document containing the operation to execute.
/// </param>
/// <param name="id">
/// The ID of a previously persisted operation that should be executed.
Expand All @@ -46,7 +46,7 @@ public sealed class OperationRequest : IEquatable<OperationRequest>, IOperationR
/// The file map entries for multipart file uploads. Default is empty.
/// </param>
public OperationRequest(
string? query,
ReadOnlyMemory<byte> query,
string? id,
string? operationName,
ErrorHandlingMode? onError,
Expand Down Expand Up @@ -149,10 +149,17 @@ public OperationRequest(
/// </summary>
public string? Id { get; }

#if FUSION
/// <summary>
/// Gets the UTF-8 encoded query document containing the operation to execute.
/// </summary>
public ReadOnlyMemory<byte> Query { get; }
#else
/// <summary>
/// Gets the query string or document containing the operation to execute.
/// </summary>
public string? Query { get; }
#endif

/// <summary>
/// Gets the name of the operation to execute.
Expand Down Expand Up @@ -241,7 +248,7 @@ public bool Equals(OperationRequest? other)
}

return Id == other.Id
&& Query == other.Query
&& Query.Span.SequenceEqual(other.Query.Span)
&& Variables.Equals(other.Variables)
&& Extensions.Equals(other.Extensions);
}
Expand All @@ -252,7 +259,7 @@ public override bool Equals(object? obj)

/// <inheritdoc/>
public override int GetHashCode()
=> HashCode.Combine(Id, Query, Variables, Extensions);
=> HashCode.Combine(Id, Query.Length, Variables, Extensions);
#else
public bool Equals(OperationRequest? other)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public static void WriteOperationRequest(JsonWriter writer, OperationRequest req
writer.WriteStringValue(request.Id);
}

if (!string.IsNullOrWhiteSpace(request.Query))
if (!request.Query.IsEmpty)
{
writer.WritePropertyName(Utf8GraphQLRequestProperties.QueryProp);
writer.WriteStringValue(request.Query);
writer.WriteStringValue(request.Query.Span);
}

if (!string.IsNullOrWhiteSpace(request.OperationName))
Expand Down Expand Up @@ -85,10 +85,10 @@ public static void WriteVariableBatchRequest(JsonWriter writer, VariableBatchReq
writer.WriteStringValue(request.Id);
}

if (!string.IsNullOrWhiteSpace(request.Query))
if (!request.Query.IsEmpty)
{
writer.WritePropertyName(Utf8GraphQLRequestProperties.QueryProp);
writer.WriteStringValue(request.Query);
writer.WriteStringValue(request.Query.Span);
}

if (!string.IsNullOrWhiteSpace(request.OperationName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class VariableBatchRequest : IOperationRequest, IEquatable<Variabl
/// Initializes a new instance of the <see cref="OperationRequest"/> struct.
/// </summary>
/// <param name="query">
/// The query document containing the operation to execute.
/// The UTF-8 encoded query document containing the operation to execute.
/// </param>
/// <param name="id">
/// The ID of a previously persisted operation that should be executed.
Expand All @@ -45,7 +45,7 @@ public sealed class VariableBatchRequest : IOperationRequest, IEquatable<Variabl
/// Thrown if the query, ID, and extensions parameters are all null.
/// </exception>
public VariableBatchRequest(
string? query,
ReadOnlyMemory<byte> query,
string? id,
string? operationName,
ErrorHandlingMode? onError,
Expand Down Expand Up @@ -146,10 +146,17 @@ public VariableBatchRequest(
/// </summary>
public string? Id { get; }

#if FUSION
/// <summary>
/// Gets the UTF-8 encoded query document containing the operation to execute.
/// </summary>
public ReadOnlyMemory<byte> Query { get; }
#else
/// <summary>
/// Gets the query string or document containing the operation to execute.
/// </summary>
public string? Query { get; }
#endif

/// <summary>
/// Gets the name of the operation to execute.
Expand Down Expand Up @@ -230,7 +237,7 @@ public bool Equals(VariableBatchRequest? other)
}

return Id == other.Id
&& Query == other.Query
&& Query.Span.SequenceEqual(other.Query.Span)
&& Variables.Equals(other.Variables)
&& Extensions.Equals(other.Extensions);
}
Expand All @@ -241,7 +248,7 @@ public override bool Equals(object? obj)

/// <inheritdoc/>
public override int GetHashCode()
=> HashCode.Combine(Id, Query, Variables, Extensions);
=> HashCode.Combine(Id, Query.Length, Variables, Extensions);
#else
public bool Equals(VariableBatchRequest? other)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,11 @@ private static Uri CreateGetRequestUri(
sb.Append(Uri.EscapeDataString(or.Id));
}

if (!string.IsNullOrWhiteSpace(or.Query))
if (!or.Query.IsEmpty)
{
AppendAmpersand(sb, ref appendAmpersand);
sb.Append("query=");
sb.Append(Uri.EscapeDataString(or.Query));
sb.Append(Uri.EscapeDataString(Encoding.UTF8.GetString(or.Query.Span)));
}

if (!string.IsNullOrWhiteSpace(or.OperationName))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if FUSION
using System.Text;
using HotChocolate.Fusion.Execution;
#endif

Expand Down Expand Up @@ -35,7 +36,7 @@ public static Task<GraphQLHttpResponse> GetAsync(
{
#if FUSION
var operation = new OperationRequest(
query,
Encoding.UTF8.GetBytes(query),
id: null,
operationName: null,
onError: null,
Expand Down Expand Up @@ -171,7 +172,7 @@ public static Task<GraphQLHttpResponse> GetAsync(
{
#if FUSION
var operation = new OperationRequest(
query,
Encoding.UTF8.GetBytes(query),
id: null,
operationName: null,
onError: null,
Expand Down Expand Up @@ -211,7 +212,7 @@ public static Task<GraphQLHttpResponse> GetAsync(
{
#if FUSION
var operation = new OperationRequest(
query,
Encoding.UTF8.GetBytes(query),
id: null,
operationName: null,
onError: null,
Expand Down Expand Up @@ -347,7 +348,7 @@ public static Task<GraphQLHttpResponse> PostAsync(
{
#if FUSION
var operation = new OperationRequest(
query,
Encoding.UTF8.GetBytes(query),
id: null,
operationName: null,
onError: null,
Expand Down Expand Up @@ -415,7 +416,7 @@ public static Task<GraphQLHttpResponse> PostAsync(
{
#if FUSION
var operation = new OperationRequest(
query,
Encoding.UTF8.GetBytes(query),
id: null,
operationName: null,
onError: null,
Expand Down Expand Up @@ -455,7 +456,7 @@ public static Task<GraphQLHttpResponse> PostAsync(
{
#if FUSION
var operation = new OperationRequest(
query,
Encoding.UTF8.GetBytes(query),
id: null,
operationName: null,
onError: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net.Http.Headers;
using HotChocolate.Language;
#if FUSION
using System.Text;
using HotChocolate.Fusion.Execution;
using HotChocolate.Fusion.Execution.Clients;
using HotChocolate.Transport.Http;
Expand Down Expand Up @@ -41,7 +42,7 @@ public GraphQLHttpRequest(string query, Uri? requestUri = null)

#if FUSION
Body = new OperationRequest(
query,
Encoding.UTF8.GetBytes(query),
id: null,
operationName: null,
onError: null,
Expand Down Expand Up @@ -70,7 +71,7 @@ public GraphQLHttpRequest(OperationRequest body, Uri? requestUri = null)
{
#if FUSION
if (string.IsNullOrEmpty(body.Id)
&& string.IsNullOrEmpty(body.Query)
&& body.Query.IsEmpty
&& body.Extensions.IsEmpty)
{
throw new ArgumentException(
Expand Down Expand Up @@ -110,7 +111,7 @@ public GraphQLHttpRequest(VariableBatchRequest body, Uri? requestUri = null)
{
#if FUSION
if (string.IsNullOrEmpty(body.Id)
&& string.IsNullOrEmpty(body.Query)
&& body.Query.IsEmpty
&& body.Extensions.IsEmpty)
{
throw new ArgumentException(
Expand Down Expand Up @@ -158,7 +159,7 @@ public GraphQLHttpRequest(OperationBatchRequest body, Uri? requestUri = null)
{
#if FUSION
if (string.IsNullOrEmpty(request.Id)
&& string.IsNullOrEmpty(request.Query)
&& request.Query.IsEmpty
&& request.Extensions.IsEmpty)
#else
if (string.IsNullOrEmpty(request.Id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ type Query {
"name": "_Default",
"transports": {
"http": {
"url": "http://localhost:5000/graphql"
"url": "http://localhost:5000/graphql",
"capabilities": {
"batching": {
"variableBatching": true,
"requestBatching": true,
"aliasBatching": true
},
"onError": "propagate"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ directive @semanticNonNull(levels: [Int!] = [0]) on FIELD_DEFINITION
"name": "_Default",
"transports": {
"http": {
"url": "http://localhost:5000/graphql"
"url": "http://localhost:5000/graphql",
"capabilities": {
"batching": {
"variableBatching": true,
"requestBatching": true,
"aliasBatching": true
},
"onError": "propagate"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ private static async Task CreateNewSettingsFile(

jsonWriter.WriteString("url", "http://localhost:5000/graphql");

// A Hot Chocolate source schema knows which transport extensions it implements, so the
// exported template declares them instead of leaving the gateway on the defaults.
jsonWriter.WriteStartObject("capabilities");

jsonWriter.WriteStartObject("batching");
jsonWriter.WriteBoolean("variableBatching", true);
jsonWriter.WriteBoolean("requestBatching", true);
jsonWriter.WriteBoolean("aliasBatching", true);
jsonWriter.WriteEndObject();

jsonWriter.WriteString("onError", "propagate");

jsonWriter.WriteEndObject();

jsonWriter.WriteEndObject();

jsonWriter.WriteEndObject();
Expand Down
Loading
Loading