Skip to content

fix: don't enforce many-to-one/one-to-many relationships for DWSQL - #3770

Open
Ritika Dhawan (ritikadhawan) wants to merge 2 commits into
Azure:mainfrom
ritikadhawan:dev/ritikadhawan/fix-dwsql-relationship-query
Open

fix: don't enforce many-to-one/one-to-many relationships for DWSQL#3770
Ritika Dhawan (ritikadhawan) wants to merge 2 commits into
Azure:mainfrom
ritikadhawan:dev/ritikadhawan/fix-dwsql-relationship-query

Conversation

@ritikadhawan

@ritikadhawan Ritika Dhawan (ritikadhawan) commented Aug 12, 2026

Copy link
Copy Markdown

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

Screenshot 2026-08-12 143540

After

Screenshot 2026-08-12 141456

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts GraphQL schema generation for Fabric Warehouse (DWSQL) so relationship fields are not incorrectly marked non-nullable when foreign keys aren’t enforced, preventing HC0018 failures on orphaned rows.

Changes:

  • Threads DatabaseType through SQL GraphQL schema generation to inform nullability decisions.
  • Treats DWSQL relationship fields as nullable during schema conversion to avoid non-null GraphQL contract violations.
  • Adds/extends unit tests to validate relationship-field nullability behavior for DWSQL vs. SQL Server.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Service.Tests/GraphQLBuilder/Sql/SchemaConverterTests.cs Adds tests asserting relationship field nullability differs for DWSQL vs MSSQL.
src/Service.GraphQLBuilder/Sql/SchemaConverter.cs Introduces DWSQL-aware relationship nullability handling during schema conversion.
src/Core/Services/GraphQLSchemaCreator.cs Passes the runtime database type into schema conversion so DWSQL behavior is applied.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Service.Tests/GraphQLBuilder/Sql/SchemaConverterTests.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@ar-guptaar

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants