I have been at it for a week now trying to implement JSON API to spec. I am going to try to describe my frustrations with it, and hopefully they resonate with someone else.
The problem is that the spec is brutal about how data relationships are supposed to be handled. I feel as if it’s a never-ending rabbit hole where an unending number of scenarios are possible. Any data can be filtered, sorted, paginated, sparsely queried, had nested data joined in, etc…
As I get further and further into this, I feel as if I will never be able to find all the issues. I’ve been trying to have our data models and relationships be uncovered dynamically. This has worked to an extent, but the number of edge cases grows continually.
Here is an example:
- A person HasOne profile photo
- type: person, id: 1
- A profile photo BelongsToOne person
- type: photo, id: 10, (foreign key: personId: 1)
Each of these has a data model, and a set of routes.
Querying for an items requires you to go back and generate the appropriate route. I don’t know what strategies other people are using for this. It’s a strange situation where the model depends on the router depends on the model (which model goes with which routes? how do I generate them again?)
In one case, we are querying for:
Photo WHERE PersonId = 1
In the other case we are querying for:
Person JOIN Photo WHERE Photo.id = 10
This doesn’t even include more cases where I could have more complex query relationships.
I know these must sound like madman ramblings, but I feel like I’m climbing a hill I can never get to the top of. If I try to handle everything dynamically, I can never catch all the edge cases. If I try to do everything manually, I can never implement the infinite number of query combinations and paths that are possible.
Does anyone have strategies for dealing with this?