Skip to content

Remove GraphQLHttpRequest.PreprocessHttpRequestMessage #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2023
Merged
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
11 changes: 0 additions & 11 deletions src/GraphQL.Client/GraphQLHttpRequest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Net.Http.Headers;
using System.Runtime.Serialization;
using System.Text;
using GraphQL.Client.Abstractions;

@@ -21,13 +20,6 @@ public GraphQLHttpRequest(GraphQLRequest other)
{
}

/// <summary>
/// Allows to preprocess a <see cref="HttpRequestMessage"/> before it is sent, i.e. add custom headers
/// </summary>
[IgnoreDataMember]
[Obsolete("Inherit from GraphQLHttpRequest and override ToHttpRequestMessage() to customize the HttpRequestMessage. Will be removed in v4.0.0.")]
public Action<HttpRequestMessage> PreprocessHttpRequestMessage { get; set; } = message => { };

/// <summary>
/// Creates a <see cref="HttpRequestMessage"/> from this <see cref="GraphQLHttpRequest"/>.
/// Used by <see cref="GraphQLHttpClient"/> to convert GraphQL requests when sending them as regular HTTP requests.
@@ -48,9 +40,6 @@ public virtual HttpRequestMessage ToHttpRequestMessage(GraphQLHttpClientOptions
if (options.DefaultUserAgentRequestHeader != null)
message.Headers.UserAgent.Add(options.DefaultUserAgentRequestHeader);

#pragma warning disable CS0618 // Type or member is obsolete
PreprocessHttpRequestMessage(message);
#pragma warning restore CS0618 // Type or member is obsolete
return message;
}
}
22 changes: 0 additions & 22 deletions tests/GraphQL.Integration.Tests/QueryAndMutationTests/Base.cs
Original file line number Diff line number Diff line change
@@ -163,28 +163,6 @@ query Human($id: String!){
Assert.Equal("Han Solo", queryResponse.Data.Human.Name);
}

[Fact]
public async void PreprocessHttpRequestMessageIsCalled()
{
var callbackTester = new CallbackMonitor<HttpRequestMessage>();
var graphQLRequest = new GraphQLHttpRequest($"{{ human(id: \"1\") {{ name }} }}")
{
#pragma warning disable CS0618 // Type or member is obsolete
PreprocessHttpRequestMessage = callbackTester.Invoke
#pragma warning restore CS0618 // Type or member is obsolete
};

var expectedHeaders = new HttpRequestMessage().Headers;
expectedHeaders.UserAgent.Add(new ProductInfoHeaderValue("GraphQL.Client", typeof(GraphQLHttpClient).Assembly.GetName().Version.ToString()));
expectedHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/graphql-response+json"));
expectedHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
expectedHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8"));
var response = await StarWarsClient.SendQueryAsync(graphQLRequest, () => new { Human = new { Name = string.Empty } });
callbackTester.Should().HaveBeenInvokedWithPayload().Which.Headers.Should().BeEquivalentTo(expectedHeaders);
Assert.Null(response.Errors);
Assert.Equal("Luke", response.Data.Human.Name);
}

[Fact]
public async Task PostRequestCanBeCancelled()
{