-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make relationship fields in referenced entities nullable #1958
Conversation
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
…/data-api-builder into fixNonNullableRelationship
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 5 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-authored-by: Sean Leonard <sean.leonard@microsoft.com>
/azp run |
Azure Pipelines successfully started running 5 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 5 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 5 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 5 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 5 pipeline(s). |
@Aniruddh25 Hoping you can help :) I updated my dab.config using the following: And my schema.graphql shows this as PaymentProviderSettings: PaymentProviderSetting! (non nullable). When I query the following: website_by_pk(WebsiteId: $input) This returns, "Cannot return null for non-nullable field". |
I just ended up making it a list of one, but I'm curious if there is a better way. Thanks! |
Why make this change?
book-websiteplacement
relationship, not allbooks
(referenced entity) may have awebsiteplacement
(referencing) yet. This change is to ensure we get all records of the referenced entity including the ones that DON'T have any relationships.What is this change?
Previously, we used to rely on the nullability of the referenced fields to determine whether the relationship field in the referenced entity should be nullable or not. While this is applicable when we are considering the relationship fields of a referencing entity, it is actually restricting when used for a referenced entity.
For example, the referencing entity (BookWebsitePlacement) should have a nullable
books
(relationship field) based on whether the foreign keybook_id
inbook_website_placements
is nullable or not -> indicating whether a website placement MUST have a book or not.On the other hand, the referenced entity
books
should always have a NULLABLEwebsiteplacement
relationship field in order to include those books that don't have anywebsiteplacement
published yet. Relying on the nullability of theid
- the referenced field in the book->book_website_placement foreign key would make the relationship NON-NULLABLE but this restricts inclusion of those books that don't have any website placements hence theerror: "Cannot return null for non-nullable field"
. We need to make the relationship field nullable in such cases.The source entity could be both the referencing and referenced entity
in case of missing foreign keys in the db or self referencing relationships.
Use the nullability of referencing columns to determine the nullability of the relationship field only if
DAB doesn't support multiple relationships at the moment.
and
true
.How was this tested?
Sample Request(s)
BEFORE:
AFTER FIX:
There are no more errors and note that we now actually return
null
as the relationship field value(here,websiteplacement
) when querying the referenced entity (here,book
) which doesn't have any relationship with the referencing entity.NOTE
The issue is only exposed in a 1:1 relationship. This is because the only other scenario for querying a referenced entity is a 1:many relationship. And for records in the referenced entity(e.g. publisher) which are NOT related to the referencing entity(e.g. book), we explicitly check for nulls and return an empty array. See here:
data-api-builder/src/Core/Resolvers/SqlQueryEngine.cs
Line 123 in dacf3bc
E.g.
Expected Response
NOTE:
When DAB supports multiple relationships, nullability of each relationship field should be determined based on foreign keys associated with each relationship.