Kinotic-Foundation / structures

Structures is an open-source framework for data storage and retrieval, supporting schema evolution, data management, and providing a user-friendly GUI and OpenAPI interface.
https://kinotic-foundation.github.io/structures/
Other
2 stars 1 forks source link

Make sure Entites that share a Model between differnet properties does not break GraphQL or OpenAPI mapping. #11

Open NavidMitchell opened 11 months ago

NavidMitchell commented 11 months ago

Currently Structures does not play nice when a Model is shared between different Entities.

Example below will throw errors when GraphQL dashboard is loaded.

class Style {
    public color: string
    public trim: string
}

@Entity
class Motorcycle {
    public type: string
    public style: Style
}

@Entity
class Car {
    public type: string
    public style: Style
}

It turns out this also breaks OpenAPI if a Model on two unrelated Entities where the Model has the same name but the definitions are different.

To solve this we need to support inside of Structures Models as a first class citizen. This can be done by adding a new Table to store Models. Will be stored with a Name, Namespace, potentially a version and the C3Type. Then the Entity C3Type will have a Reference to the Model. This will allow verification during saving.

Additionally, we can add in the Model a reverse reference to the Entity that uses the Model. This will allow the Model to be automatically deleted if it is not referenced by any Entity.

In the future we may support sharing Models across Namespaces.

NavidMitchell commented 8 months ago

This has been partially fixed. The first case listed above is fixed. But if you use the same name across different projects in the same namespace you will have the same problem.

NavidMitchell commented 5 months ago

I have fixed all cases where the object is shared. There is still a problem if multiple models that are different but have the same name. This is talked about in the description.