You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PR #2138 adds support for querying relationships that reference the same entity (self-join tables).
Extend multiple create functionality to support relationships that reference itself.
Some things to consider are:
Accurate determination of referencing/referenced entity. Though, referenced and referencing entity are both the same, we need to be able to identify whether top level item (or) related item should be created first.
The current data structure maintains the relationship metadata at the entity level. PR GraphQL Queries - Entities with self-joining relationships get expected responses #2138 introduces changes to maintain the relationship metadata at the granularity level of relationship. This new data structure should be used during query generation and rest of the mutation flows.
The text was updated successfully, but these errors were encountered:
severussundar
changed the title
Support multiple create for self-referencing relationships
Support multiple create mutation for self-referencing relationships.
Apr 10, 2024
…same database table (#2189)
## Why make this change?
DAB doesn't support multiple-create on related entities which are backed
by same database table. This PR adds a validation to catch that scenario
and throw a meaningful exception to the end user. Issue to track
support: #2157
## What is this change?
- Adds a validation during order determination logic in
`MultipleCreateOrderHelper.GetReferencingEntityName()` method to catch
the scenario.
- In the method signature for
`MultipleCreateOrderHelper.GetReferencingEntityName()`, a new parameter
isMNRelationship is added with default value of false. The reasoning is
explained in the section.
#### Reason for why
`MultipleCreateOrderHelper.GetReferencingEntityName()` is called even
for M:N relationships when we know that we are always going to return an
empty string?
1. For M:N relationships, we assume one of the source/target entity as
the referencing entity when we do insertion during query execution
because any of the entity can be considered as the
referencing/referenced entity. However this does not hold true when the
source and target entities are backed by same database tables - in which
case we cannot consider any of the entity as the referenced/referencing
entity.
2. The not-supported use case - that of not allowing multiple-create via
relationships in which source and target entities are backed by same
database tables is because DAB cannot determine a valid order of
insertion. Since this concerns order determination, it is better to keep
the code inside the
`MultipleCreateOrderHelper.GetReferencingEntityName()` method.
3. Keeping this in `MultipleCreateOrderHelper` provides unit test
coverage even for the other 2 db types i.e. PgSql,MySql.
## How was this tested?
- Added test
MultipleCreateOrderHelperUnitTests.TestExceptionForSelfReferencingRelationships()
to test the change for the 3 dbs - MySql/MsSql/PgSql.
## Sample Request(s)
1. Config:
![image](https://github.com/Azure/data-api-builder/assets/34566234/262f5816-87e3-4a0c-acc6-291f56d3c213)
Request:
![image](https://github.com/Azure/data-api-builder/assets/34566234/c8007c11-51d3-4029-a2e6-a3197d86d582)
---------
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
Co-authored-by: Sean Leonard <sean.leonard@microsoft.com>
PR #2138 adds support for querying relationships that reference the same entity (self-join tables).
Extend multiple create functionality to support relationships that reference itself.
Some things to consider are:
The text was updated successfully, but these errors were encountered: