-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue when required data was present in query. (#7536)
(cherry picked from commit 256dd07)
- Loading branch information
1 parent
f74e284
commit c9b50e4
Showing
7 changed files
with
180 additions
and
77 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/HotChocolate/Core/src/Execution/Projections/IPropertyNodeProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#if NET6_0_OR_GREATER | ||
using System.Reflection; | ||
|
||
namespace HotChocolate.Execution.Projections; | ||
|
||
internal interface IPropertyNodeProvider | ||
{ | ||
IReadOnlyList<PropertyNode> Nodes { get; } | ||
|
||
PropertyNode AddOrGetNode(PropertyInfo property); | ||
|
||
void TryAddNode(PropertyNode newNode); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/HotChocolate/Core/src/Execution/Projections/PropertyNodeContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#if NET6_0_OR_GREATER | ||
using System.Reflection; | ||
|
||
namespace HotChocolate.Execution.Projections; | ||
|
||
internal class PropertyNodeContainer( | ||
List<PropertyNode>? nodes = null) | ||
: IPropertyNodeProvider | ||
{ | ||
private static readonly IReadOnlyList<PropertyNode> _emptyNodes = Array.Empty<PropertyNode>(); | ||
private List<PropertyNode>? _nodes = nodes; | ||
private bool _sealed; | ||
|
||
public IReadOnlyList<PropertyNode> Nodes | ||
=> _nodes ?? _emptyNodes; | ||
|
||
public PropertyNode AddOrGetNode(PropertyInfo property) | ||
{ | ||
if (_sealed) | ||
{ | ||
throw new InvalidOperationException("The property node container is sealed."); | ||
} | ||
|
||
_nodes ??= new(); | ||
|
||
foreach (var node in Nodes) | ||
{ | ||
if (node.Property.Name.Equals(property.Name)) | ||
{ | ||
return node; | ||
} | ||
} | ||
|
||
var newNode = new PropertyNode(property); | ||
_nodes.Add(newNode); | ||
return newNode; | ||
} | ||
|
||
public void TryAddNode(PropertyNode newNode) | ||
{ | ||
if (_sealed) | ||
{ | ||
throw new InvalidOperationException("The property node container is sealed."); | ||
} | ||
|
||
_nodes ??= new(); | ||
|
||
foreach (var node in _nodes) | ||
{ | ||
if (node.Property.Name.Equals(newNode.Property.Name)) | ||
{ | ||
if (!node.Property.MetadataToken.Equals(newNode.Property.MetadataToken)) | ||
{ | ||
throw new InvalidOperationException("Duplicate property name."); | ||
} | ||
|
||
// we add the child nodes that are not already present | ||
foreach (var newChild in newNode.Nodes) | ||
{ | ||
node.TryAddNode(newChild); | ||
} | ||
} | ||
} | ||
|
||
_nodes.Add(newNode); | ||
} | ||
|
||
public void Seal() | ||
{ | ||
if (!_sealed) | ||
{ | ||
foreach (var node in Nodes) | ||
{ | ||
node.Seal(); | ||
} | ||
|
||
_sealed = true; | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...__snapshots__/ProjectableDataLoaderTests.Brand_Details_Requires_Brand_Name_2.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Brand_Details_Requires_Brand_Name_2 | ||
|
||
## SQL | ||
|
||
```text | ||
-- @__keys_0={ '1' } (DbType = Object) | ||
SELECT b."Name", b."Id" | ||
FROM "Brands" AS b | ||
WHERE b."Id" = ANY (@__keys_0) | ||
``` | ||
|
||
## Result | ||
|
||
```json | ||
{ | ||
"data": { | ||
"brandById": { | ||
"name": "Brand0", | ||
"details": "Brand Name:Brand0" | ||
} | ||
} | ||
} | ||
``` | ||
|
23 changes: 23 additions & 0 deletions
23
...hots__/ProjectableDataLoaderTests.Brand_Details_Requires_Brand_Name_2_NET7_0.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Brand_Details_Requires_Brand_Name_2 | ||
|
||
## SQL | ||
|
||
```text | ||
SELECT b."Name", b."Id" | ||
FROM "Brands" AS b | ||
WHERE b."Id" = 1 | ||
``` | ||
|
||
## Result | ||
|
||
```json | ||
{ | ||
"data": { | ||
"brandById": { | ||
"name": "Brand0", | ||
"details": "Brand Name:Brand0" | ||
} | ||
} | ||
} | ||
``` | ||
|