Decorator to add support to Ember Data for the JSON:API Bulk Extension.
- Ember.js v3.24 or above
- Ember CLI v2.13 or above
- Node.js v12 or above
ember install ember-data-json-api-bulk-ext
If you have not yet created a subclass of the Ember Data Store, do so now. You will want to import and apply the decorator to this class.
// app/services/store.js
import Store from '@ember-data/store';
import { withBulkActions } from 'ember-data-json-api-bulk-ext';
@withBulkActions()
class CustomStore extends Store {}
export default CustomStore;
With the decorator applied to your Store subclass, you'll have new methods on the store available to you for dealing with bulk API actions.
const first = this.store.createRecord('post', { title: 'First Post' });
const second = this.store.createRecord('post', { title: 'Second Post' });
await this.store.bulkCreate([first, second]);
assert.ok(first.id, 'First record was given an ID');
assert.ok(second.id, 'First record was given an ID');
Note the following limitations:
- The models being operated on must use the
JSONAPIAdapter
andJSONAPISerializer
- All records must be of the same type (for now)
- Records can only be created in bulk (for now)
The bulk extension for JSON:API describes a custom MIME type for your requests. To override the default JSON:API MIME type and use the one from the extension, pass the following option to the withBulkActions
decorator:
@withBulkActions({ useExtensionMimeType: true })
class CustomStore extends Store {
See the Contributing guide for details.
This project is licensed under the MIT License.