Skip to content

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
Collaborator

@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
Copy link
Contributor Author

/azp run

@sourabh1007
Copy link
Contributor Author

/azp run

Copy link
Collaborator

@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
@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.

4 participants