Fix nested filter on self-referencing relationships#3038
Open
Fix nested filter on self-referencing relationships#3038
Conversation
…ion test Co-authored-by: Aniruddh25 <[email protected]>
Co-authored-by: Aniruddh25 <[email protected]>
Copilot
AI
changed the title
[WIP] Fix nested filter on self-referencing relationships
Fix nested filter on self-referencing relationships
Jan 6, 2026
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends GraphQL nested-filter handling to correctly support self-referencing relationships (e.g., parent/child hierarchies) for SQL-backed entities, and adds a regression test for the scenario on MSSQL.
Changes:
- Update SQL nested-filter join predicate generation to use relationship-name-based FK lookup (supports self-joins).
- Add an MSSQL integration test validating nested filters on the
DimAccountself-referencing relationship.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Service.Tests/SqlTests/GraphQLFilterTests/MsSqlGQLFilterTests.cs | Adds a new MSSQL test covering nested filtering through a self-referencing relationship (parent_account). |
| src/Core/Models/GraphQLFilterParsers.cs | Adjusts nested-filter SQL join predicate creation to use relationship-aware FK lookup, enabling self-referencing relationship filters. |
Aniruddh25
approved these changes
Mar 12, 2026
2 tasks
Co-authored-by: Aniruddh25 <[email protected]>
Aniruddh25
approved these changes
Mar 12, 2026
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Nested Filter on Self-Referencing Relationships
Completed Tasks:
AddJoinPredicatesForRelatedEntitywhich doesn't handle self-referencing relationships correctlyHandleNestedFilterForSqlin GraphQLFilterParsers.cs to useAddJoinPredicatesForRelationshipinsteadEntityRelationshipKeyusing the relationship name (filter field name)AddJoinPredicatesForRelationshipon the parent query structure with correct parametersChanges Summary:
HandleNestedFilterForSqlto properly handle self-referencing relationships by using the relationship name to look up foreign key definitionsTestNestedFilterSelfReferencingintegration test to validate the fixSecurity Summary:
✅ CodeQL scan completed with 0 alerts
✅ Code review completed with only minor style nitpicks
✅ All builds successful
✅ Formatting verified with
dotnet format --verify-no-changesOriginal prompt
This section details on the original issue you should resolve
<issue_title>[Bug]: Nested filter on Self-Referencing Relationships returns incorrect results</issue_title>
<issue_description>### What happened?
Problem
When using GraphQL nested filters on self-referencing relationships (e.g., parent/child hierarchy), the filter returns incorrect results.
This query gives incorrect results
Expected Behavior
Returns book items with categories whose parent's name contains "Classic".
Proposed Solution
HandleNestedFilterForSql, useAddJoinPredicatesForRelationshipinstead ofAddJoinPredicatesForRelatedEntityEntityRelationshipKeyusing the relationship name (filter field name) to look up the correct FK definitionfkLookupKey:{queryStructure.EntityName, filterField.Name}targetEntityName: the nested filter entity namesubqueryTargetTableAlias: the EXISTS subquery's source aliasIn
BaseGraphQLFilterParsers.cs: