Azure / data-api-builder

Data API builder provides modern REST and GraphQL endpoints to your Azure Databases and on-prem stores.
https://aka.ms/dab/docs
MIT License
786 stars 142 forks source link

Validation to disallow multiple create on related entities backed by same database table #2189

Closed ayush3797 closed 2 months ago

ayush3797 commented 2 months ago

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?

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?

Sample Request(s)

  1. Config:

image

Request:

image

ayush3797 commented 2 months ago

/azp run

ayush3797 commented 2 months ago

are tests dependent on #2138

Are not dependent. But will require additional entities in the config and some more changes. Keeping bug-bash in mind, trying to get the logic changes in and test can follow.

ayush3797 commented 2 months ago

Now I'm onto adding test.

ayush3797 commented 2 months ago

/azp run

ayush3797 commented 2 months ago

/azp run

ayush3797 commented 2 months ago

/azp run

ayush3797 commented 2 months ago

/azp run

ayush3797 commented 2 months ago

/azp run