Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public override bool TryHandleLeave(
return false;
}

var memberInit = queryableScope.CreateMemberInit();

if (!context.TryGetQueryableScope(out var parentScope))
{
throw ThrowHelper.ProjectionVisitor_InvalidState_NoParentScope();
Expand All @@ -88,6 +86,21 @@ public override bool TryHandleLeave(
return true;
}

// If the nested scope has no projectable members we keep the original value.
// This happens for members like JsonDocument where selected subfields are read-only.
if (!queryableScope.HasAbstractTypes() && queryableScope.Level.Peek().Count == 0)
{
parentScope.Level
.Peek()
.Enqueue(Expression.Bind(field.Member, nestedProperty));

action = SelectionVisitor.Continue;

return true;
}

var memberInit = queryableScope.CreateMemberInit();

if (context.InMemory)
{
parentScope.Level
Expand Down
55 changes: 55 additions & 0 deletions src/HotChocolate/Data/test/Data.Tests/Issue5893Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Text.Json;
using HotChocolate.Execution;
using Microsoft.Extensions.DependencyInjection;

namespace HotChocolate.Data;

public class Issue5893Tests
{
[Fact]
public async Task UseProjection_With_JsonDocument_Should_Not_Error()
{
var executor = await new ServiceCollection()
.AddGraphQLServer()
.AddProjections()
.AddQueryType<Issue5893Query>()
.BuildRequestExecutorAsync();

var result = await executor.ExecuteAsync(
"""
{
tests {
codigo
data {
rootElement
}
}
}
""");

var operationResult = result.ExpectOperationResult();
Assert.Empty(operationResult.Errors ?? []);
}

public sealed class Issue5893Query
{
[UseProjection]
public IQueryable<Issue5893Model> GetTests()
=> new[]
{
new Issue5893Model
{
Codigo = "a",
Data = JsonDocument.Parse("""{"a":1}""")
}
}
.AsQueryable();
}

public sealed class Issue5893Model
{
public string Codigo { get; set; } = string.Empty;

public JsonDocument? Data { get; set; }
}
}
Loading