Description
- Start Date: (2016-07-13)
- RFC PR: n/a (yet)
Summary
The goal here is to redesign the serializer <-> adapter interaction such that there is minimum effort in formatting the output. Adapters would then only really be responisble for formatting, and it may be more appropriate to name them Formatters
Motivation
There is inconsistency with what adapters implement what features. I feel like this is confusing for people.
Current Issues with adapters:
- repeated code:
- include logic
- building relationships
- building the attributes hash (from fields whitelisting, for example)
- all the logic for retrieving fields from the cache is different per adapter
JSON
andAttributes
are missing features thatJSON API
offers- If adapters are what we intend them to be, they'll all be just formatters... sort of...
Detailed design
in-progress, needs discussion.
Adapters should have an API modeled after JSON API
data
- primary serializer / resource(s)
included
- flat list -- these objects would have the AR integration that doesn't make DB queries to belongs_to records... but in here is where the include logic would be handled, so we don't have to deal with it in the individual adapters.
meta
links
errors
A lot of these are already accessible to the serializer, but we've been relying on the adapter to traverse all of it.
All of the relationships and everything should already be traversed before getting to the adapter, so the adapter can just focus on how to format the output
An adapter would be responsible for converting each of these structures into whatever format it wishes.
Drawbacks
a lot of work, would invalidate / cause major conflicts for nearly all outstanding PRs.
Alternatives
deal with things as they are.
Unresolved questions
- what needs to happen first?
- why is caching so much of a problem?
- disadvatages of not evaluating values of anything in the serializer (lazy evaluation of attributes, relationships, etc)?