Skip to content
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

Support multiple create mutation for self-referencing relationships. #2157

Open
Tracked by #1576
severussundar opened this issue Apr 10, 2024 · 0 comments
Open
Tracked by #1576
Labels
Multiple mutations Fixes/enhancements related to nested mutations.
Milestone

Comments

@severussundar
Copy link
Contributor

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.
@severussundar severussundar added the Multiple mutations Fixes/enhancements related to nested mutations. label Apr 10, 2024
@severussundar severussundar added this to the 1.1rc milestone Apr 10, 2024
@severussundar severussundar changed the title Support multiple create for self-referencing relationships Support multiple create mutation for self-referencing relationships. Apr 10, 2024
@seantleonard seantleonard modified the milestones: 1.1rc, 1.2rc Apr 30, 2024
ayush3797 added a commit that referenced this issue May 2, 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Multiple mutations Fixes/enhancements related to nested mutations.
Projects
None yet
Development

No branches or pull requests

2 participants