Skip to content

Commit

Permalink
Fixed issues with IsSelected and composite lists. (#7941)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Jan 22, 2025
1 parent 2d9d70e commit 40af4af
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,13 @@ public static bool IsSelected(this IResolverContext context, string fieldName)
nameof(fieldName));
}

if (!context.Selection.Type.IsCompositeType())
var namedType = context.Selection.Type.NamedType();

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

var namedType = context.Selection.Type.NamedType();

if (namedType.IsAbstractType())
{
foreach (var possibleType in context.Schema.GetPossibleTypes(namedType))
Expand Down Expand Up @@ -741,13 +741,13 @@ public static bool IsSelected(this IResolverContext context, string fieldName1,
nameof(fieldName2));
}

if (!context.Selection.Type.IsCompositeType())
var namedType = context.Selection.Type.NamedType();

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

var namedType = context.Selection.Type.NamedType();

if (namedType.IsAbstractType())
{
foreach (var possibleType in context.Schema.GetPossibleTypes(namedType))
Expand Down Expand Up @@ -839,13 +839,13 @@ public static bool IsSelected(
nameof(fieldName3));
}

if (!context.Selection.Type.IsCompositeType())
var namedType = context.Selection.Type.NamedType();

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

var namedType = context.Selection.Type.NamedType();

if (namedType.IsAbstractType())
{
foreach (var possibleType in context.Schema.GetPossibleTypes(namedType))
Expand Down Expand Up @@ -913,13 +913,13 @@ public static bool IsSelected(
throw new ArgumentNullException(nameof(fieldNames));
}

if (!context.Selection.Type.IsCompositeType())
var namedType = context.Selection.Type.NamedType();

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

var namedType = context.Selection.Type.NamedType();

if (namedType.IsAbstractType())
{
foreach (var possibleType in context.Schema.GetPossibleTypes(namedType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,49 @@ public async Task Select_Category_Level_2()
result.MatchMarkdownSnapshot();
}

[Fact]
public async Task IsSelected_Pattern_Lists()
{
var result =
await new ServiceCollection()
.AddGraphQL()
.AddQueryType<Query>()
.ExecuteRequestAsync(
"""
query {
user_Attribute_List {
email
tags {
name
}
}
}
""");


result.MatchMarkdownSnapshot();
}

[Fact]
public async Task IsSelected_Pattern_Root_Lists()
{
var result =
await new ServiceCollection()
.AddGraphQL()
.AddQueryType<Query>()
.ExecuteRequestAsync(
"""
query {
books {
author { name }
}
}
""");


result.MatchMarkdownSnapshot();
}

public class Query
{
public static User DummyUser { get; } =
Expand Down Expand Up @@ -984,6 +1027,32 @@ public User GetUser_Context_4(IResolverContext context)
City = "f",
};
}

public User GetUser_Attribute_List(
[IsSelected("tags { name }")]
bool isSelected,
IResolverContext context)
{
((IMiddlewareContext)context).OperationResult.SetExtension("isSelected", isSelected);
return new User
{
Name = "a",
Email = "b",
Password = "c",
PhoneNumber = "d",
Address = "e",
City = "f",
};
}

public List<Book> GetBooks(
[IsSelected("author")]
bool isSelected,
IResolverContext context)
{
((IMiddlewareContext)context).OperationResult.SetExtension("isSelected", isSelected);
return new List<Book>();
}
}

public class BrokenQuery
Expand Down Expand Up @@ -1071,4 +1140,8 @@ public class Audit
public string EditedBy { get; set; }
public string EditedAt { get; set; }
}

public record Book(string Title, Author Author);

public record Author(string Name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# IsSelected_Pattern_Lists

```json
{
"data": {
"user_Attribute_List": {
"email": "b",
"tags": null
}
},
"extensions": {
"isSelected": true
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# IsSelected_Pattern_Root_Lists

```json
{
"data": {
"books": []
},
"extensions": {
"isSelected": true
}
}
```

0 comments on commit 40af4af

Please sign in to comment.