Skip to content

Commit

Permalink
Fixed issue with composite type detection on select (#7376)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Aug 16, 2024
1 parent 0f437f5 commit 7b81b8c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ public bool IsSelected(string fieldName)

while (Unsafe.IsAddressLessThan(ref start, ref end))
{
if (!start.Type.IsCompositeType())
var namedType = start.Type.NamedType();

if (!namedType.IsCompositeType())
{
return false;
}

var namedType = start.Type.NamedType();

if (namedType.IsAbstractType())
{
foreach (var possibleType in _schema.GetPossibleTypes(namedType))
Expand Down Expand Up @@ -428,13 +428,13 @@ private bool CollectSelections(

while (Unsafe.IsAddressLessThan(ref start, ref end))
{
if (!start.Type.IsCompositeType())
var namedType = start.Type.NamedType();

if (!namedType.IsCompositeType())
{
goto NEXT;
}

var namedType = start.Type.NamedType();

if (namedType.IsAbstractType())
{
foreach (var possibleType in _schema.GetPossibleTypes(namedType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,59 @@ public async Task Select_Category_Level_1()
result.MatchMarkdownSnapshot();
}

[Fact]
public async Task Traverse_With_Select()
{
var result =
await new ServiceCollection()
.AddGraphQL()
.AddQueryType(
c =>
{
c.Name("Query");
c.Field("user")
.Resolve(
ctx =>
{
var isTagsOnContext = ctx.IsSelected("tags");
var collection = ctx.Select("tags");
var isAuditOnTagsCollection = collection.IsSelected("audit");
collection = collection.Select("audit");
var isEditedByOnAudiCollection = collection.IsSelected("editedBy");
var operationResult = ((IMiddlewareContext)ctx).OperationResult;

operationResult.SetExtension(
nameof(isTagsOnContext),
isTagsOnContext);
operationResult.SetExtension(
nameof(isAuditOnTagsCollection),
isAuditOnTagsCollection);
operationResult.SetExtension(
nameof(isEditedByOnAudiCollection),
isEditedByOnAudiCollection);

return Query.DummyUser;
});
})
.ExecuteRequestAsync(
"""
query {
user {
name
tags {
value
name
audit {
editedBy
}
}
}
}
""");

result.MatchMarkdownSnapshot();
}

[Fact]
public async Task Select_Category_Level_2()
{
Expand Down Expand Up @@ -996,6 +1049,7 @@ public class User
public string City { get; set; }

public Category Category { get; set; }
public List<UserTag> Tags { get; set; }
}

public class Category
Expand All @@ -1004,4 +1058,17 @@ public class Category

public Category Next { get; set; }
}

public class UserTag
{
public string Name { get; set; }
public int Value { get; set; }
public Audit Audit { get; set; }
}

public class Audit
{
public string EditedBy { get; set; }
public string EditedAt { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Traverse_With_Select

```json
{
"data": {
"user": {
"name": "a",
"tags": null
}
},
"extensions": {
"isTagsOnContext": true,
"isAuditOnTagsCollection": true,
"isEditedByOnAudiCollection": true
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public static class ResolverContextSelectionExtensions
/// <param name="context">The resolver context</param>
/// Returns the <see cref="ISelectedField"/> of the current resolver.
public static ISelectedField GetSelectedField(this IResolverContext context)
=> new SelectedField(context, (ISelection)context.Selection);
=> new SelectedField(context, context.Selection);
}

0 comments on commit 7b81b8c

Please sign in to comment.