-
Notifications
You must be signed in to change notification settings - Fork 127
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
GraphQL Queries - Entities with self-joining relationships get expected responses #2138
Conversation
Co-authored-by: Shyam Sundar J <shyamsundarj@microsoft.com>
Co-authored-by: Shyam Sundar J <shyamsundarj@microsoft.com>
Co-authored-by: Shyam Sundar J <shyamsundarj@microsoft.com>
…/Azure/data-api-builder into dev/agarwalayush/removingWrongFK
….com/Azure/data-api-builder into dev/sean/selfReferencingRelationship
/azp run |
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.
Posting comments so far. Few more files to go.
src/Service.Tests/SqlTests/GraphQLQueryTests/GraphQLQueryTestBase.cs
Outdated
Show resolved
Hide resolved
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 |
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.
Pending to look at QueryStructures.
…from databaseResolvedFkDefinition into configResolvedFkDefinition because configResolvedFkDefinition was missing that metadata, but did have the metadata ( the "more metadata" you called out) for relationshipName/sourceEntityName.
/azp run |
/azp run |
/azp run |
… the security advisory now correctly scopes in 7.0.7 as patched.
/azp run |
/azp run |
Self Join
Why this change?
When users defined self-joining relationships between entities (SourceEntity == TargetEntity), DAB couldn't properly process the relationship at request-time and returned null/unexpected results due to incorrectly generated sqltext.
What is this change?
Primary Changes
The primary changes:
Dictionary<EntityRelationshipKey, ForeignKeyDefinition>
)ReferencedEntityRole
-> indicates whether the entity in a self-joined relationship is the "Target" or "Source" entity.ReferencingEntityRole
-> indicates whether the entity in a self-joined relationship is the "Target" or "Source" entity.Example
dab-config.json
-> in-engine data structureBelow is an example translation between a dab-config.json relationship and the RelationshipToFkDefinition:
dab-config.json
in-engine data structure
The following table illustrates how the dictionary
RelationshipToFkDefinition
is populated.The enhanced metadata collection listed above enables DAB to pick out
ForeignKeyDefinition
created to represent a config relationshipleftColumnNames
(Source Fields) andrightColumnNames
(Target Fields).ForeignKeyDefinition
object (prior to this pr) only tracked "referencing" and "referenced" columns and DAB didn't know whether to mapReferencing - Source; Referenced - Target; OR Referencing - Target; Referenced - Source;
DAB startup uses the relationship cardinality value (
one
,many
) to determine whetherCardinality:
one
(many:one; one:one)Example: books(Many) - publisher(One) where books.publisher_id is referencing publisher.id
Cardinality:
many
(one:many)Example: publisher(One)-books(Many) where publisher.id is referenced by books.publisher_id
Example GraphQL Query
In a GraphQL query, the top level entity is always the source entity and the nested entity is the target entity.
ForeignKeyDefinition.ResolveSourceColumns()
-> checkReferencingEntityRole
to return expected columns (referencing/referenced)ForeignKeyDefinition.ResolveTargetColumns()
-> checksReferencedEntityRole
to return expected columns (referencing/referenced)The following example requires DAB to utilize both entries in the
RelationshipToFkDefinition
table above:parent_account
field configured with relationship cardinatlity (one
) which means:child_accounts
field configured with relationship cardinality (many
) which means:How was this tested?
-[] Unit tests
-[x] Integration tests
Sample Request(s)
GraphQL Parent and Child Self-Join with tsql
sample data