Repository navigation
Commit 93e8232
fix: don't enforce many-to-one/one-to-many relationships for DWSQL (#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>1 parent a795a1a commit 93e8232
3 files changed
Lines changed: 41 additions & 11 deletions
File tree
- src
- Core/Services
- Service.GraphQLBuilder/Sql
- Service.Tests/GraphQLBuilder/Sql
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
| 321 | + | |
| 322 | + | |
322 | 323 | | |
323 | 324 | | |
324 | 325 | | |
| |||
560 | 561 | | |
561 | 562 | | |
562 | 563 | | |
563 | | - | |
| 564 | + | |
| 565 | + | |
564 | 566 | | |
565 | 567 | | |
566 | 568 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
| 73 | + | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
170 | 172 | | |
171 | 173 | | |
172 | 174 | | |
173 | | - | |
| 175 | + | |
| 176 | + | |
174 | 177 | | |
175 | 178 | | |
176 | 179 | | |
| |||
225 | 228 | | |
226 | 229 | | |
227 | 230 | | |
228 | | - | |
| 231 | + | |
| 232 | + | |
229 | 233 | | |
230 | 234 | | |
231 | 235 | | |
| |||
474 | 478 | | |
475 | 479 | | |
476 | 480 | | |
477 | | - | |
| 481 | + | |
| 482 | + | |
478 | 483 | | |
479 | 484 | | |
480 | 485 | | |
481 | 486 | | |
482 | 487 | | |
483 | | - | |
| 488 | + | |
484 | 489 | | |
485 | 490 | | |
486 | 491 | | |
| |||
631 | 636 | | |
632 | 637 | | |
633 | 638 | | |
634 | | - | |
| 639 | + | |
| 640 | + | |
635 | 641 | | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
636 | 648 | | |
637 | 649 | | |
638 | 650 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
364 | 379 | | |
365 | 380 | | |
366 | 381 | | |
| |||
756 | 771 | | |
757 | 772 | | |
758 | 773 | | |
759 | | - | |
| 774 | + | |
760 | 775 | | |
761 | 776 | | |
762 | 777 | | |
| |||
786 | 801 | | |
787 | 802 | | |
788 | 803 | | |
789 | | - | |
| 804 | + | |
| 805 | + | |
790 | 806 | | |
791 | 807 | | |
792 | 808 | | |
| |||
0 commit comments