Currently, @ember/data does not handle support for JSONAPI fields. fields
allows you to serve a minimal payload, saving time on the wire. This will change in the future. However, the current system does not allow for a robust, drop in replacement for everyone. In the meantime, this addon exists!
- Ember.js v3.8 or above
- Ember CLI v2.13 or above
- Node.js v8 or above
ember install ember-data-jsonapi-fields
import { JSONAPIFieldsAdapter } from 'ember-data-jsonapi-fields';
export default class MyJSONAPIAdapter extends JSONAPIFieldsAdapter {
...
}
store.findRecord('post', 123, {
adapterOptions: { fields: { post: 'name,body' } }
});
// Note: @ember/data already includes support for `includes`.
store.findRecord('post', 123, {
adapterOptions: { fields: { post: 'name,body', comments: 'title' } }, include: 'comments'
});
You may not want to install this addon for a variety of reasons. One might be your visceral reaction to installing yet another library.
There is one case you might want to roll your own implementation. If you don't care about caching mechanisms, simply override buildQuery
.
import JSONAPIAdapter from '@ember-data/adapter/json-api';
export default ApplicationAdapter extends JSONAPIAdapter {
buildQuery(snapshot) {
let query = this._super(...arguments);
if (snapshot.adapterOptions) {
let { fields } = snapshot.adapterOptions;
if (fields) {
query.fields = fields;
}
}
return query;
},
}
See the Contributing guide for details.
This project is licensed under the MIT License.