Skip to content

Commit

Permalink
Ported: Fixed issue where mutating the result object would drop the C…
Browse files Browse the repository at this point in the history
…ontextData #5211
  • Loading branch information
michaelstaib committed Jan 31, 2023
1 parent 7f7f0d2 commit 3a21ba1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
Expand Up @@ -189,13 +189,15 @@ await using (section.Body)
public static async Task<ClientRawResult> PostRawAsync(
this TestServer testServer,
ClientQueryRequest request,
string path = "/graphql")
string path = "/graphql",
bool enableApolloTracing = false)
{
var response =
await SendPostRequestAsync(
testServer,
JsonConvert.SerializeObject(request),
path);
path,
enableApolloTracing: enableApolloTracing);

if (response.StatusCode == HttpStatusCode.NotFound)
{
Expand Down
@@ -1,14 +1,14 @@
using System.Net;
using System.Net.Http.Json;
using CookieCrumble;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using HotChocolate.AspNetCore.Instrumentation;
using HotChocolate.AspNetCore.Serialization;
using HotChocolate.AspNetCore.Tests.Utilities;
using HotChocolate.Execution;
using HotChocolate.Execution.Serialization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using static HotChocolate.Execution.Serialization.JsonNullIgnoreCondition;

Expand Down Expand Up @@ -194,7 +194,7 @@ public async Task Complexity_Exceeded()
{
// arrange
var server = CreateStarWarsServer(
configureServices: c => c.AddGraphQLServer().ModifyRequestOptions(o=>
configureServices: c => c.AddGraphQLServer().ModifyRequestOptions(o =>
{
o.Complexity.Enable = true;
o.Complexity.MaximumAllowed = 1;
Expand Down Expand Up @@ -369,6 +369,34 @@ public async Task Aggregate_Diagnostic_All_Listeners_Are_Triggered()
Assert.True(listenerB.Triggered);
}

[Fact]
public async Task Apollo_Tracing_Invalid_Field()
{
// arrange
var server = CreateStarWarsServer(
configureServices: s => s
.AddGraphQLServer()
.AddApolloTracing());

// act
var response = await server.PostRawAsync(
new ClientQueryRequest
{
Query =
@"{
hero123(episode: NEW_HOPE)
{
name
}
}"

},
enableApolloTracing: true);

// assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}

[Fact]
public async Task Ensure_Multipart_Format_Is_Correct_With_Defer()
{
Expand Down
Expand Up @@ -2,11 +2,9 @@
using System.Collections.Generic;
using System.Threading.Tasks;

#nullable enable

namespace HotChocolate.Execution;

public class QueryResultBuilder : IQueryResultBuilder
public sealed class QueryResultBuilder : IQueryResultBuilder
{
private IReadOnlyDictionary<string, object?>? _data;
private IReadOnlyList<object?>? _items;
Expand Down Expand Up @@ -191,9 +189,9 @@ public static QueryResultBuilder FromResult(IQueryResult result)
builder._errors = new List<IError>(result.Errors);
}

if (result.Extensions is ExtensionData d)
if (result.Extensions is ExtensionData ext)
{
builder._extensionData = new ExtensionData(d);
builder._extensionData = new ExtensionData(ext);
}
else if (result.Extensions is not null)
{
Expand All @@ -209,6 +207,10 @@ public static QueryResultBuilder FromResult(IQueryResult result)
builder._contextData = new ExtensionData(result.ContextData);
}

builder._label = result.Label;
builder._path = result.Path;
builder._hasNext = result.HasNext;

return builder;
}

Expand Down

0 comments on commit 3a21ba1

Please sign in to comment.