Skip to content

Commit

Permalink
Fixed client issue when baseAddress is not set. (#6353)
Browse files Browse the repository at this point in the history
  • Loading branch information
A360JMaxxgamer authored Jul 19, 2023
1 parent 249087b commit 28415d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ private static HttpRequestMessage CreateRequestMessage(
if (method == GraphQLHttpMethod.Post)
{
message.Content = CreatePostContent(arrayWriter, request.Body);
message.RequestUri = requestUri;
}
else if (method == GraphQLHttpMethod.Get)
{
Expand Down Expand Up @@ -219,4 +220,4 @@ private static string FormatDocumentAsJson(ArrayWriter arrayWriter, ObjectValueN
}

public void Dispose() => _httpClient.Dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ public async Task ExecutePostAsync_Returns_OperationResult()
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
using var testServer = CreateStarWarsServer();
var httpClient = testServer.CreateClient();
httpClient.BaseAddress = new Uri(CreateUrl("/graphql"));
var client = new DefaultGraphQLHttpClient(httpClient);
var request = new GraphQLHttpRequest("query { hero(episode: JEDI) { name } }");
var request = new GraphQLHttpRequest("query { hero(episode: JEDI) { name } }", new Uri(CreateUrl("/graphql")));

// act
using var response = await client.SendAsync(request, cts.Token);

Expand All @@ -37,14 +36,14 @@ public async Task ExecuteGetAsync_Returns_OperationResult()
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
using var testServer = CreateStarWarsServer();
var httpClient = testServer.CreateClient();
httpClient.BaseAddress = new Uri(CreateUrl("/graphql"));
var client = new DefaultGraphQLHttpClient(httpClient);
var request = new GraphQLHttpRequest(
new OperationRequest("query { hero(episode: JEDI) { name } }"))
new OperationRequest("query { hero(episode: JEDI) { name } }"),
new Uri(CreateUrl("/graphql")))
{
Method = GraphQLHttpMethod.Get
};

// act
var response = await client.SendAsync(request, cts.Token);

Expand All @@ -60,27 +59,26 @@ public async Task ExecuteGetAsync_WithVariablesReturns_OperationResult()
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
using var testServer = CreateStarWarsServer();
var httpClient = testServer.CreateClient();
httpClient.BaseAddress = new Uri(CreateUrl("/graphql"));
var client = new DefaultGraphQLHttpClient(httpClient);
var request = new GraphQLHttpRequest(
new OperationRequest(
"query($episode: Episode!) { hero(episode: $episode) { name } }",
variables: new Dictionary<string, object?>()
{
{"episode", "JEDI"}
}))
}), new Uri(CreateUrl("/graphql")))
{
Method = GraphQLHttpMethod.Get
};

// act
var response = await client.SendAsync(request, cts.Token);

// assert
using var body = await response.ReadAsResultAsync(cts.Token);
body.MatchSnapshot();
}

[Fact(Skip = "Needs to be implemented.")]
public async Task Execute_Subscription_Over_SSE()
{
Expand All @@ -92,14 +90,14 @@ public async Task Execute_Subscription_Over_SSE()
var client = new DefaultGraphQLHttpClient(httpClient);
var request = new GraphQLHttpRequest(
new OperationRequest("subscription { onReview(episode: JEDI) { stars } }"));

// act
var response = await client.SendAsync(request, cts.Token);

// assert
await foreach (var result in response.ReadAsResultStreamAsync(cts.Token).WithCancellation(cts.Token))
{
result.MatchSnapshot();
result.MatchSnapshot();
cts.Cancel();
}
}
Expand Down

0 comments on commit 28415d8

Please sign in to comment.