Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/snewcomer/ember-data-jsonapi-fields
Querying for jsonapi fields through @ember/data JSONAPIAdapter
https://github.com/snewcomer/ember-data-jsonapi-fields
Last synced: 17 days ago
JSON representation
Querying for jsonapi fields through @ember/data JSONAPIAdapter
- Host: GitHub
- URL: https://github.com/snewcomer/ember-data-jsonapi-fields
- Owner: snewcomer
- License: mit
- Created: 2020-08-15T15:14:35.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-16T20:03:30.000Z (over 4 years ago)
- Last Synced: 2024-10-30T08:23:58.196Z (2 months ago)
- Language: JavaScript
- Size: 166 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
ember-data-jsonapi-fields
==============================================================================Currently, [@ember/data](https://github.com/emberjs/data) does not handle support for JSONAPI [fields](https://jsonapi.org/format/#document-resource-object-fields). [`fields`](https://jsonapi.org/format/#fetching-sparse-fieldsets) 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!
Compatibility
------------------------------------------------------------------------------* Ember.js v3.8 or above
* Ember CLI v2.13 or above
* Node.js v8 or aboveInstallation
------------------------------------------------------------------------------```
ember install ember-data-jsonapi-fields
```You want to use this
------------------------------------------------------------------------------```js
import { JSONAPIFieldsAdapter } from 'ember-data-jsonapi-fields';export default class MyJSONAPIAdapter extends JSONAPIFieldsAdapter {
...
}
```
```js
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 use this
------------------------------------------------------------------------------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`.
```js
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;
},
}
```Contributing
------------------------------------------------------------------------------See the [Contributing](CONTRIBUTING.md) guide for details.
License
------------------------------------------------------------------------------This project is licensed under the [MIT License](LICENSE.md).