Reputation: 3010
This is an example of a problem I'm trying to solve. Suppose I want to create a GraphQL schema that models administrative entities (countries, states, provinces etc, represented by type AdministrativeEntity
) of cities (type City
) around the world. Each city belongs to a list of entities that have hierarchical relationship to each other. However, the number of "levels" of a city's administrative entities may differ. For example, "Chicago" belongs to "United States" and "Illinois" (which has two levels) but Singapore only belongs to "Singapore" (only one level). How should I represent the type AdministrativeEntity
in my GraphQL schema? Should it be a scalar
, an Object
type or something else?
type City {
entity: AdministrativeEntity!
}
Upvotes: 1
Views: 484
Reputation: 8418
You can use recurrency - parent
property in AdministrativeEntity
type. This is the most universal, expandable, manageable.
... but for savings (on scale) you can use simple [ordered] array of names.
Of course you can use both solutions (2 properties) in the same time (2 resolvers operating on the same data/db).
Upvotes: 1