Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed May 22, 2024
1 parent 5a28e03 commit 9bd8a89
Show file tree
Hide file tree
Showing 6 changed files with 657 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public DefaultGraphQLHttpClient(HttpClient httpClient)
Uri requestUri)
{
var method = request.Method;

if(method == GraphQLHttpMethod.Get)
{
if (request.Body is not OperationRequest)
Expand Down Expand Up @@ -263,7 +263,7 @@ private static void WriteOperationJson(ArrayWriter arrayWriter, GraphQLHttpReque
throw new InvalidOperationException(
HttpResources.DefaultGraphQLHttpClient_BatchNotAllowed);
}

var sb = new StringBuilder();
var appendAmpersand = false;

Expand Down Expand Up @@ -295,8 +295,7 @@ private static void WriteOperationJson(ArrayWriter arrayWriter, GraphQLHttpReque
{
AppendAmpersand(sb, ref appendAmpersand);
sb.Append("variables=");
sb.Append(
Uri.EscapeDataString(FormatDocumentAsJson(arrayWriter, or.VariablesNode)));
sb.Append(Uri.EscapeDataString(FormatDocumentAsJson(arrayWriter, or.VariablesNode)));
}
else if (or.Variables is not null)
{
Expand All @@ -309,8 +308,7 @@ private static void WriteOperationJson(ArrayWriter arrayWriter, GraphQLHttpReque
{
AppendAmpersand(sb, ref appendAmpersand);
sb.Append("extensions=");
sb.Append(
Uri.EscapeDataString(FormatDocumentAsJson(arrayWriter, or.ExtensionsNode)));
sb.Append(Uri.EscapeDataString(FormatDocumentAsJson(arrayWriter, or.ExtensionsNode)));
}
else if (or.Extensions is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static class GraphQLHttpClientExtensions
? GetAsync(client, operation, cancellationToken)
: GetAsync(client, operation, uri, cancellationToken);
}

/// <summary>
/// Sends a GraphQL GET request to the specified GraphQL endpoint.
/// </summary>
Expand Down Expand Up @@ -129,7 +129,7 @@ public static class GraphQLHttpClientExtensions
? GetAsync(client, operation, cancellationToken)
: GetAsync(client, operation, uri, cancellationToken);
}

/// <summary>
/// Sends a GraphQL GET request to the specified GraphQL endpoint.
/// </summary>
Expand Down Expand Up @@ -159,7 +159,7 @@ public static class GraphQLHttpClientExtensions
? GetAsync(client, operation, cancellationToken)
: GetAsync(client, operation, uri, cancellationToken);
}

/// <summary>
/// Sends a GraphQL GET request to the specified GraphQL endpoint.
/// </summary>
Expand Down Expand Up @@ -214,12 +214,12 @@ public static class GraphQLHttpClientExtensions
{
throw new ArgumentNullException(nameof(client));
}

var request = new GraphQLHttpRequest(operation)
{
Method = GraphQLHttpMethod.Get,
};

return client.SendAsync(request, cancellationToken);
}

Expand Down Expand Up @@ -256,12 +256,12 @@ public static class GraphQLHttpClientExtensions
{
throw new ArgumentNullException(nameof(uri));
}

var request = new GraphQLHttpRequest(operation, new Uri(uri))
{
Method = GraphQLHttpMethod.Get,
};

return client.SendAsync(request, cancellationToken);
}

Expand Down Expand Up @@ -298,12 +298,12 @@ public static class GraphQLHttpClientExtensions
{
throw new ArgumentNullException(nameof(uri));
}

var request = new GraphQLHttpRequest(operation, uri)
{
Method = GraphQLHttpMethod.Get,
};

return client.SendAsync(request, cancellationToken);
}

Expand Down Expand Up @@ -418,7 +418,7 @@ public static class GraphQLHttpClientExtensions
? PostAsync(client, operation, cancellationToken)
: PostAsync(client, operation, uri, cancellationToken);
}

/// <summary>
/// Sends a GraphQL POST request to the specified GraphQL endpoint.
/// </summary>
Expand Down Expand Up @@ -452,7 +452,7 @@ public static class GraphQLHttpClientExtensions
? PostAsync(client, operation, cancellationToken)
: PostAsync(client, operation, uri, cancellationToken);
}

/// <summary>
/// Sends a GraphQL POST request to the specified GraphQL endpoint.
/// </summary>
Expand Down Expand Up @@ -511,11 +511,69 @@ public static class GraphQLHttpClientExtensions
{
throw new ArgumentNullException(nameof(client));
}

var request = new GraphQLHttpRequest(operation) { Method = GraphQLHttpMethod.Post, };
return client.SendAsync(request, cancellationToken);
}

/// <summary>
/// Sends a GraphQL POST request to the specified GraphQL endpoint.
/// </summary>
/// <param name="client">
/// The <see cref="GraphQLHttpClient"/> to send the request with.
/// </param>
/// <param name="batch">
/// The GraphQL variable batch request.
/// </param>
/// <param name="cancellationToken">
/// A cancellation token to cancel the operation.
/// </param>
/// <returns>
/// A <see cref="Task{TResult}"/> representing the asynchronous operation.
/// </returns>
public static Task<GraphQLHttpResponse> PostAsync(
this GraphQLHttpClient client,
VariableBatchRequest batch,
CancellationToken cancellationToken = default)
{
if (client == null)
{
throw new ArgumentNullException(nameof(client));
}

var request = new GraphQLHttpRequest(batch) { Method = GraphQLHttpMethod.Post, };
return client.SendAsync(request, cancellationToken);
}

/// <summary>
/// Sends a GraphQL POST request to the specified GraphQL endpoint.
/// </summary>
/// <param name="client">
/// The <see cref="GraphQLHttpClient"/> to send the request with.
/// </param>
/// <param name="batch">
/// The GraphQL operation batch request.
/// </param>
/// <param name="cancellationToken">
/// A cancellation token to cancel the operation.
/// </param>
/// <returns>
/// A <see cref="Task{TResult}"/> representing the asynchronous operation.
/// </returns>
public static Task<GraphQLHttpResponse> PostAsync(
this GraphQLHttpClient client,
OperationBatchRequest batch,
CancellationToken cancellationToken = default)
{
if (client == null)
{
throw new ArgumentNullException(nameof(client));
}

var request = new GraphQLHttpRequest(batch) { Method = GraphQLHttpMethod.Post, };
return client.SendAsync(request, cancellationToken);
}

/// <summary>
/// Sends a GraphQL POST request to the specified GraphQL endpoint.
/// </summary>
Expand Down Expand Up @@ -549,12 +607,96 @@ public static class GraphQLHttpClientExtensions
{
throw new ArgumentNullException(nameof(uri));
}

var request = new GraphQLHttpRequest(operation, new Uri(uri))
{
Method = GraphQLHttpMethod.Post,
};


return client.SendAsync(request, cancellationToken);
}

/// <summary>
/// Sends a GraphQL POST request to the specified GraphQL endpoint.
/// </summary>
/// <param name="client">
/// The <see cref="GraphQLHttpClient"/> to send the request with.
/// </param>
/// <param name="batch">
/// The GraphQL variable batch request.
/// </param>
/// <param name="uri">
/// The GraphQL request URI.
/// </param>
/// <param name="cancellationToken">
/// A cancellation token to cancel the operation.
/// </param>
/// <returns>
/// A <see cref="Task{TResult}"/> representing the asynchronous operation.
/// </returns>
public static Task<GraphQLHttpResponse> PostAsync(
this GraphQLHttpClient client,
VariableBatchRequest batch,
string uri,
CancellationToken cancellationToken = default)
{
if (client == null)
{
throw new ArgumentNullException(nameof(client));
}

if (uri == null)
{
throw new ArgumentNullException(nameof(uri));
}

var request = new GraphQLHttpRequest(batch, new Uri(uri))
{
Method = GraphQLHttpMethod.Post,
};

return client.SendAsync(request, cancellationToken);
}

/// <summary>
/// Sends a GraphQL POST request to the specified GraphQL endpoint.
/// </summary>
/// <param name="client">
/// The <see cref="GraphQLHttpClient"/> to send the request with.
/// </param>
/// <param name="batch">
/// The GraphQL operation batch request.
/// </param>
/// <param name="uri">
/// The GraphQL request URI.
/// </param>
/// <param name="cancellationToken">
/// A cancellation token to cancel the operation.
/// </param>
/// <returns>
/// A <see cref="Task{TResult}"/> representing the asynchronous operation.
/// </returns>
public static Task<GraphQLHttpResponse> PostAsync(
this GraphQLHttpClient client,
OperationBatchRequest batch,
string uri,
CancellationToken cancellationToken = default)
{
if (client == null)
{
throw new ArgumentNullException(nameof(client));
}

if (uri == null)
{
throw new ArgumentNullException(nameof(uri));
}

var request = new GraphQLHttpRequest(batch, new Uri(uri))
{
Method = GraphQLHttpMethod.Post,
};

return client.SendAsync(request, cancellationToken);
}

Expand Down Expand Up @@ -591,12 +733,96 @@ public static class GraphQLHttpClientExtensions
{
throw new ArgumentNullException(nameof(uri));
}

var request = new GraphQLHttpRequest(operation, uri)
{
Method = GraphQLHttpMethod.Post,
};

return client.SendAsync(request, cancellationToken);
}
}
}

/// <summary>
/// Sends a GraphQL POST request to the specified GraphQL endpoint.
/// </summary>
/// <param name="client">
/// The <see cref="GraphQLHttpClient"/> to send the request with.
/// </param>
/// <param name="batch">
/// The GraphQL variable batch request.
/// </param>
/// <param name="uri">
/// The GraphQL request URI.
/// </param>
/// <param name="cancellationToken">
/// A cancellation token to cancel the operation.
/// </param>
/// <returns>
/// A <see cref="Task{TResult}"/> representing the asynchronous operation.
/// </returns>
public static Task<GraphQLHttpResponse> PostAsync(
this GraphQLHttpClient client,
VariableBatchRequest batch,
Uri uri,
CancellationToken cancellationToken = default)
{
if (client == null)
{
throw new ArgumentNullException(nameof(client));
}

if (uri == null)
{
throw new ArgumentNullException(nameof(uri));
}

var request = new GraphQLHttpRequest(batch, uri)
{
Method = GraphQLHttpMethod.Post,
};

return client.SendAsync(request, cancellationToken);
}

/// <summary>
/// Sends a GraphQL POST request to the specified GraphQL endpoint.
/// </summary>
/// <param name="client">
/// The <see cref="GraphQLHttpClient"/> to send the request with.
/// </param>
/// <param name="batch">
/// The GraphQL operation batch request.
/// </param>
/// <param name="uri">
/// The GraphQL request URI.
/// </param>
/// <param name="cancellationToken">
/// A cancellation token to cancel the operation.
/// </param>
/// <returns>
/// A <see cref="Task{TResult}"/> representing the asynchronous operation.
/// </returns>
public static Task<GraphQLHttpResponse> PostAsync(
this GraphQLHttpClient client,
OperationBatchRequest batch,
Uri uri,
CancellationToken cancellationToken = default)
{
if (client == null)
{
throw new ArgumentNullException(nameof(client));
}

if (uri == null)
{
throw new ArgumentNullException(nameof(uri));
}

var request = new GraphQLHttpRequest(batch, uri)
{
Method = GraphQLHttpMethod.Post,
};

return client.SendAsync(request, cancellationToken);
}
}
Loading

0 comments on commit 9bd8a89

Please sign in to comment.