-
-
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)
- Loading branch information
1 parent
17a0b77
commit 256dd07
Showing
6 changed files
with
149 additions
and
77 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
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,12 @@ | ||
using System.Reflection; | ||
|
||
namespace HotChocolate.Execution.Projections; | ||
|
||
internal interface IPropertyNodeProvider | ||
{ | ||
IReadOnlyList<PropertyNode> Nodes { get; } | ||
|
||
PropertyNode AddOrGetNode(PropertyInfo property); | ||
|
||
void TryAddNode(PropertyNode newNode); | ||
} |
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
79 changes: 79 additions & 0 deletions
79
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,79 @@ | ||
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; | ||
} | ||
} | ||
} |
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" | ||
} | ||
} | ||
} | ||
``` | ||
|