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

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

Closed sourabh1007 closed 1 month ago

sourabh1007 commented 2 months ago

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?

sourabh1007 commented 2 months ago

/azp run

sourabh1007 commented 2 months ago

/azp run

sourabh1007 commented 2 months ago

/azp run

sourabh1007 commented 2 months ago

/azp run

sourabh1007 commented 1 month ago

/azp run

sourabh1007 commented 1 month ago

/azp run