[backport release/2.0] fix: don't enforce many-to-one/one-to-many relationships for DWSQL (#3770) - #3775
Merged
Ritika Dhawan (ritikadhawan) merged 2 commits intoAug 18, 2026
Conversation
Ritika Dhawan (ritikadhawan)
marked this pull request as ready for review
August 17, 2026 18:08
Copilot started reviewing on behalf of
Ritika Dhawan (ritikadhawan)
August 17, 2026 18:09
View session
Ritika Dhawan (ritikadhawan)
enabled auto-merge (squash)
August 17, 2026 18:10
Contributor
There was a problem hiding this comment.
Pull request overview
This backport fixes an incorrect GraphQL schema nullability assumption for Fabric Warehouse (DWSQL): because DWSQL does not enforce foreign keys, relationship fields must not be marked non-nullable based solely on NOT NULL FK metadata, otherwise valid queries can fail with HC0018 (“Cannot return null for non-nullable field.”).
Changes:
- Thread
DatabaseTypethrough SQL GraphQL schema generation so relationship nullability decisions can be database-specific. - For
DatabaseType.DWSQL, force relationship fields to be nullable when generating the GraphQL schema. - Add/extend unit tests to validate DWSQL vs MSSQL relationship-field nullability behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Service.Tests/GraphQLBuilder/Sql/SchemaConverterTests.cs | Adds coverage asserting DWSQL relationship fields become nullable even when FK metadata indicates NOT NULL, while MSSQL remains unchanged. |
| src/Service.GraphQLBuilder/Sql/SchemaConverter.cs | Adds databaseType plumbing and makes FindNullabilityOfRelationship return nullable for DWSQL relationships. |
| src/Core/Services/GraphQLSchemaCreator.cs | Passes the metadata provider’s DatabaseType into SchemaConverter during schema construction (including linking entities). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Author
|
/azp run |
1 similar comment
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 6 pipeline(s). |
Aniruddh Munde (Aniruddh25)
approved these changes
Aug 17, 2026
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 6 pipeline(s). |
naxing123
approved these changes
Aug 18, 2026
Ritika Dhawan (ritikadhawan)
disabled auto-merge
August 18, 2026 04:02
Ritika Dhawan (ritikadhawan)
force-pushed
the
dev/ritikadhawan/backport-3770-to-2.0
branch
from
August 18, 2026 04:06
19a7e14 to
581da8f
Compare
…3770) ## What's the problem? When Data API builder serves a Fabric Warehouse (DWSQL) database, a GraphQL query that follows a relationship between two tables could fail with this error: ``` "Cannot return null for non-nullable field." (HC0018) ``` ...even when the query was perfectly valid and the data was fine. Instead of returning the row, the whole query blew up. ## Why does it happen? Most databases guarantee that if a row points to a "parent" row (a foreign key), that parent actually exists. DAB relies on that guarantee: if a foreign-key column is marked "required" (NOT NULL), DAB assumes the related object is always there, and tells GraphQL "this related field will never be null." **Fabric Warehouse is different — it does not enforce foreign keys.** So a child row can happily point at a parent that doesn't exist (an "orphaned" row). When GraphQL asks for that missing parent, DAB has nothing to return, but it already promised the field would never be null. GraphQL sees a broken promise and throws HC0018. Example: an `Enrollment` row has a `studentId` that no `Student` matches. Asking for `enrollment.student` returns nothing, and the query fails. ## What does this change do? For Fabric Warehouse (DWSQL) only, DAB no longer assumes related rows always exist. It marks the related fields on many-to-one and one-to-many relationships as nullable. That way, when a related row is genuinely missing, the query simply returns `null` for that field instead of failing the entire request. Behavior for all other databases (SQL Server, PostgreSQL, MySQL) is unchanged, since they do enforce foreign keys. ## How was it verified? - Added unit tests covering both DWSQL (field is now nullable) and SQL Server (field stays non-nullable) for both relationship directions. - Manually validated end-to-end against a Fabric Warehouse: the query that previously failed now returns the row with `student: null`. #### Before <img width="854" height="730" alt="Screenshot 2026-08-12 143540" src="https://github.com/user-attachments/assets/9b4585e5-5cb8-456f-8efb-0eda22f68994" /> #### After <img width="1053" height="514" alt="Screenshot 2026-08-12 141456" src="https://github.com/user-attachments/assets/cbb42b63-c867-4804-bc10-6d7a4c1c643b" /> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: aaronburtle <93220300+aaronburtle@users.noreply.github.com>
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 6 pipeline(s). |
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 6 pipeline(s). |
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 6 pipeline(s). |
…3770) ## What's the problem? When Data API builder serves a Fabric Warehouse (DWSQL) database, a GraphQL query that follows a relationship between two tables could fail with this error: ``` "Cannot return null for non-nullable field." (HC0018) ``` ...even when the query was perfectly valid and the data was fine. Instead of returning the row, the whole query blew up. ## Why does it happen? Most databases guarantee that if a row points to a "parent" row (a foreign key), that parent actually exists. DAB relies on that guarantee: if a foreign-key column is marked "required" (NOT NULL), DAB assumes the related object is always there, and tells GraphQL "this related field will never be null." **Fabric Warehouse is different — it does not enforce foreign keys.** So a child row can happily point at a parent that doesn't exist (an "orphaned" row). When GraphQL asks for that missing parent, DAB has nothing to return, but it already promised the field would never be null. GraphQL sees a broken promise and throws HC0018. Example: an `Enrollment` row has a `studentId` that no `Student` matches. Asking for `enrollment.student` returns nothing, and the query fails. ## What does this change do? For Fabric Warehouse (DWSQL) only, DAB no longer assumes related rows always exist. It marks the related fields on many-to-one and one-to-many relationships as nullable. That way, when a related row is genuinely missing, the query simply returns `null` for that field instead of failing the entire request. Behavior for all other databases (SQL Server, PostgreSQL, MySQL) is unchanged, since they do enforce foreign keys. ## How was it verified? - Added unit tests covering both DWSQL (field is now nullable) and SQL Server (field stays non-nullable) for both relationship directions. - Manually validated end-to-end against a Fabric Warehouse: the query that previously failed now returns the row with `student: null`. #### Before <img width="854" height="730" alt="Screenshot 2026-08-12 143540" src="https://github.com/user-attachments/assets/9b4585e5-5cb8-456f-8efb-0eda22f68994" /> #### After <img width="1053" height="514" alt="Screenshot 2026-08-12 141456" src="https://github.com/user-attachments/assets/cbb42b63-c867-4804-bc10-6d7a4c1c643b" /> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: aaronburtle <93220300+aaronburtle@users.noreply.github.com> Backport of #3770 to release/2.0.
Contributor
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 6 pipeline(s). |
Ritika Dhawan (ritikadhawan)
deleted the
dev/ritikadhawan/backport-3770-to-2.0
branch
August 18, 2026 05:27
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.
What's the problem?
When Data API builder serves a Fabric Warehouse (DWSQL) database, a GraphQL query that follows a relationship between two tables could fail with this error:
...even when the query was perfectly valid and the data was fine. Instead of returning the row, the whole query blew up.
Why does it happen?
Most databases guarantee that if a row points to a "parent" row (a foreign key), that parent actually exists. DAB relies on that guarantee: if a foreign-key column is marked "required" (NOT NULL), DAB assumes the related object is always there, and tells GraphQL "this related field will never be null."
Fabric Warehouse is different — it does not enforce foreign keys. So a child row can happily point at a parent that doesn't exist (an "orphaned" row). When GraphQL asks for that missing parent, DAB has nothing to return, but it already promised the field would never be null. GraphQL sees a broken promise and throws HC0018.
Example: an
Enrollmentrow has astudentIdthat noStudentmatches. Asking forenrollment.studentreturns nothing, and the query fails.What does this change do?
For Fabric Warehouse (DWSQL) only, DAB no longer assumes related rows always exist. It marks the related fields on many-to-one and one-to-many relationships as nullable. That way, when a related row is genuinely missing, the query simply returns
nullfor that field instead of failing the entire request.Behavior for all other databases (SQL Server, PostgreSQL, MySQL) is unchanged, since they do enforce foreign keys.
How was it verified?
student: null.Before
After