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
10 changes: 10 additions & 0 deletions src/Linq2GraphQL.Client.AI/Schema/QueryValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ private SchemaType FragmentType(SchemaType parent, string typeName, string path)
parent.PossibleTypes.Contains(type.Name) ||
type.PossibleTypes.Contains(parent.Name) ||
type.PossibleTypes.Intersect(parent.PossibleTypes).Any();
if (!applies && shape.ConnectionOf(parent.Name) is { } connection &&
(connection.NodeType == type.Name || model.Type(connection.NodeType)?.PossibleTypes.Contains(type.Name) == true))
{
var pageField = connection.HasNodes ? "nodes" : "edges { node";
var close = connection.HasNodes ? "}" : "} }";
Error(path, $"This field is paged; put `... on {type.Name}` inside `{pageField} {{ ... on {type.Name} {{ ... }} {close}`, " +
"for example `{ nodes { __typename ... on " + type.Name + " { ... } } pageInfo { hasNextPage endCursor } }`.");
return null;
}

if (!applies)
{
Error(path, $"A fragment on {type.Name} cannot apply to {parent.Name}.");
Expand Down
3 changes: 2 additions & 1 deletion test/Linq2GraphQL.Agent.Sample/questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
{ "question": "Which customer has an order delivered to Garden Inc?", "expected": ["Universal Ltd"] },
{ "question": "What is the price of item 12345 on Universal Ltd's orders?", "expected": ["56.4"] },
{ "question": "What is the name of the spider, and how many legs does it have?", "expected": ["Imse", "8"] },
{ "question": "Which animal has the most legs?", "expected": ["Imse"] }
{ "question": "What is the name of the animal with the most legs?", "expected": ["Imse"] },
{ "question": "What is the speed of each animal?", "expected": ["Kalle", "5", "Imse", "11"] }
]
9 changes: 9 additions & 0 deletions test/Linq2GraphQL.Tests/QueryValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ public void PagedField_SelectedDirectly_GetsTheFix()
.ShouldContain("orders.orderId: This field is paged; select orderId inside `nodes { orderId }`");
}

[Fact]
public void PagedField_FragmentOnTheNodeType_GetsTheFix()
{
var errors = ShouldFail("{ animals { ... on Spider { name } } }");

errors.ShouldContain("animals: This field is paged; put `... on Spider` inside `nodes { ... on Spider { ... } }`");
errors.ShouldNotContain("cannot apply");
}

[Fact]
public void LeafAndCompositeSelections_AreChecked()
{
Expand Down
Loading