v0.4.0
Update notes:
-
There is one primary change in 0.4 that could break your 0.3 app.
In 0.3.x, Mirage's JSONAPISerializer included all related foreign keys whenever serializing a model or collection, even if those relationships were not being
includedin the payload.This actually goes against JSON:API's design. Foreign keys in the payload are known as Resource Linkage and are intended to be used by API clients to link together all resources in a JSON:API compound document. In fact, most server-side JSON:API libraries do not automatically serialize all related foreign keys, and only return linkage data for related resources when they are being included in the current document.
By including linkage data for every relationship in 0.3, it was easy to develop Ember apps that would work with Mirage but would behave differently when hooked up to a standard JSON:API server. Since Mirage always included linkage data, an Ember app might automatically be able to fetch related resources using the ids from that linkage data plus its knowledge about the API. For example, if a
postcame back like this:// GET /posts/1 { data: { type: 'posts', id: '1', attributes: { ... }, relationships: { author: { data: { type: 'users', id: '1' } } } } }
and you forgot to
?include=authorin your GET request, Ember Data would potentially use theuser:1foreign key and lazily fetch theauthorby making a request toGET /authors/1. This is problematic because- This is not how foreign keys are intended to be used
- It'd be better to see no data and fix the problem by going back up to your data-loading code and add
?include=authorto your GET request, or - If you do want your interface to lazily load the author, use resource
linksinstead of the resource linkagedata:
// GET /posts/1 { data: { type: 'posts', id: '1', attributes: { ... }, relationships: { author: { links: { related: '/api/users/1' } } } } }
Resource links can be defined on Mirage serializers using the links method (though
includingis likely the far more simpler and common approach to fetching related data).So, Mirage 0.4 changed this behavior and by default, the JSONAPISerializer only includes linkage data for relationships that are being included in the current payload (i.e. within the same compound document).
This behavior is configurable via the
alwaysIncludeLinkageDatakey on your JSONAPISerializers. It is set tofalseby default, but if you want to opt-in to 0.3 behavior and always include linkage data, set it totrue:// mirage/serializers/application.js import { JSONAPISerializer } from 'ember-cli-mirage'; export default JSONAPISerializer.extend({ alwaysIncludeLinkageData: true });
If you do this, I would recommend looking closely at how your real server behaves when serializing resources' relationships and whether it uses resource
linksor resource linkagedata, and to update your Mirage code accordingly to give you the most faithful representation of your server. -
Support for Node 0.12 has been explicitly dropped from some of our dependencies
-
If you are using a version of Pretender that supports tracking requests, you'll need to enable it in Mirage. This is the first version of Mirage that ships with a version of Pretender that has tracking support, and we disable it by due to the feature’s memory footprint. To enable Pretender’s request tracking, set
ENV['ember-cli-mirage'].trackRequests = true.
Special thanks to @Turbo87 and @kellyselden for all their work on this release.
Changes:
- [ENHANCEMENT]#1150 Change default JSONAPI data linkage behavior (reference #1146) @samselikoff
- [BUGFIX]#1148 Foreign key ids were being muted by collection creation @lukemelia
- [BUGFIX]#1078 Ensure #update works on associations @ivanvanderbyl
- [BUGFIX]#1112 Fix query in disassociateAllDepentsFromTarget @omghax
- [BUGFIX]#0176 Fix using
associationhelper in a dasherized factory @ignatius-j - [ENHANCEMENT]#1138 Unlock and upgrade ember-get-config @dfreeman
- [ENHANCEMENT] #b99717 Serializer blueprint should extend the application serializer @ChrisBarthol
- [ENHANCEMENT]#1187 Use native ES class syntax for base Class.extend @cowboyd
- [ENHANCEMENT]#1137 Bump pretender and disable request tracking in pretender @bekzod
- General enhancements @HeroicEric, @Turbo87, @kellyselden, @bekzod, @timhaines, @wismer, @mixonic, @rwjblue