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

Cosmos DB: Adds circular reference check for entities in graphQL schema #2192

Merged
merged 12 commits into from May 3, 2024

Conversation

sourabh1007
Copy link
Contributor

@sourabh1007 sourabh1007 commented Apr 29, 2024

Why make this change?

Today, if graphQL schema has circular reference of entities, DAB won't be able to load the schema and die with stackoverflow exception when it tries to traverse the schema.
With JSON data, it can get very complicated to handle all the scenarios with circular reference.

What is this change?

Adding a proper exception during the load, if DAB identifies that schema has circular reference.

If schema is found with circular reference, DAB will throw below exception.

DAB Exception

DataApiBuilderException(
                        message: $"Circular reference detected in the schema for entity '{entityType}'.",
                        statusCode: System.Net.HttpStatusCode.InternalServerError,
                        subStatusCode: DataApiBuilderException.SubStatusCodes.ErrorInInitialization);

Schema with circular reference

type Character {
    id : ID,
    name : String,
    moons: [Moon],    // Character has Moon Reference 
}
type Planet @model(name:""Planet"") {
    id : ID!,
    name : String,
    character: Character
}
type Moon {
    id : ID,
    name : String,
    details : String,
    character: Character // Moon has Character Reference
}

How was this tested?

  • Integration Tests
  • Unit Tests

@sourabh1007
Copy link
Contributor Author

/azp run

Copy link
Contributor

@seantleonard seantleonard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some questions before merging.

@sourabh1007 sourabh1007 force-pushed the users/sourabhjain/circularreferenceCheck branch from cf2fd29 to 47264b2 Compare April 30, 2024 06:30
@sourabh1007 sourabh1007 enabled auto-merge (squash) April 30, 2024 06:30
@sourabh1007
Copy link
Contributor Author

/azp run

@sourabh1007
Copy link
Contributor Author

/azp run

Copy link
Contributor

@neeraj-sharma2592 neeraj-sharma2592 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sourabh1007
Copy link
Contributor Author

/azp run

Copy link
Contributor

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires circular condition check even if runtime config doesnt contain the entity

sourabh1007 and others added 3 commits May 3, 2024 11:26
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
@sourabh1007
Copy link
Contributor Author

/azp run

@sourabh1007
Copy link
Contributor Author

/azp run

Copy link
Contributor

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for addressing all comments!

@sourabh1007 sourabh1007 merged commit 196fed9 into main May 3, 2024
7 checks passed
@sourabh1007 sourabh1007 deleted the users/sourabhjain/circularreferenceCheck branch May 3, 2024 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants