3
votes

Store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push

I've just updated to ember 1.13.2 and ember-data 1.13.3 and I'm now receiving lots of the deprecation message mentioned in this post's title. I don't know what is causing it to appear and the Ember Inspector's Deprecations tab doesn't show me where in my code the issue is located.

If anyone can explain to me what the message means and what I need to do to resolve it I'd be grateful.

Thanks.

UPDATE:

My custom application adapter looks like this:

// app/adapters/application.js
import ActiveModelAdapter from 'active-model-adapter';

export default ActiveModelAdapter.extend({
    host: 'http://dev.mydomain.com',
    namespace: 'api/v1',
});

It uses the ActiveModelAdapter add-on as a different deprecation message explained that the ActiveModelAdapter will no longer be bundled with ember-data as of v2.0.0. However, I have tried my code with both the ember-data adapter and the add on and I get the same deprecation message about Store.push.

There are a few stack traces as there are multiple versions of the same deprecation but here are a couple:

DEPRECATION: store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push.
    at ember$data$lib$system$store$$Service.extend.push (http://localhost:4200/assets/vendor.js:81014:17)
    at http://localhost:4200/assets/vendor.js:83253:17
    at Array.forEach (native)
    at Ember.Mixin.create._extractEmbeddedHasMany (http://localhost:4200/assets/vendor.js:83251:68)
    at null.<anonymous> (http://localhost:4200/assets/vendor.js:83219:22)
    at http://localhost:4200/assets/vendor.js:84254:20
    at cb (http://localhost:4200/assets/vendor.js:27380:11)
    at OrderedSet.forEach (http://localhost:4200/assets/vendor.js:27163:11)
    at Map.forEach (http://localhost:4200/assets/vendor.js:27384:18)

DEPRECATION: store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push.
    at ember$data$lib$system$store$$Service.extend.push (http://localhost:4200/assets/vendor.js:81014:17)
    at Ember.Mixin.create._extractEmbeddedBelongsTo (http://localhost:4200/assets/vendor.js:83302:15)
    at null.<anonymous> (http://localhost:4200/assets/vendor.js:83226:22)
    at http://localhost:4200/assets/vendor.js:84254:20
    at cb (http://localhost:4200/assets/vendor.js:27380:11)
    at OrderedSet.forEach (http://localhost:4200/assets/vendor.js:27163:11)
    at Map.forEach (http://localhost:4200/assets/vendor.js:27384:18)
    at Function.ember$data$lib$system$model$$default.reopenClass.eachRelationship (http://localhost:4200/assets/vendor.js:84253:83)
    at Ember.Mixin.create._extractEmbeddedRecords (http://localhost:4200/assets/vendor.js:83212:19)

NEW ERROR AFTER ADDING isNewSerailizerAPI: true TO SERIALIZERS (see answers):

Error while processing route: elavonApplication.index Cannot read property 'id' of undefined TypeError: Cannot read property 'id' of undefined
at ember$data$lib$serializers$embedded$records$mixin$$_newExtractEmbeddedBelongsTo (http://localhost:4200/assets/vendor.js:83482:33)
at Ember.Mixin.create._extractEmbeddedBelongsTo (http://localhost:4200/assets/vendor.js:83349:98)
at null.<anonymous> (http://localhost:4200/assets/vendor.js:83419:19)
at http://localhost:4200/assets/vendor.js:84310:20
at Map.forEach.cb (http://localhost:4200/assets/vendor.js:27380:11)
at OrderedSet.forEach (http://localhost:4200/assets/vendor.js:27163:11)
at Map.forEach (http://localhost:4200/assets/vendor.js:27384:18)
at Function.ember$data$lib$system$model$$default.reopenClass.eachRelationship (http://localhost:4200/assets/vendor.js:84309:83)
at ember$data$lib$serializers$embedded$records$mixin$$_newExtractEmbeddedRecords (http://localhost:4200/assets/vendor.js:83413:17)
at Ember.Mixin.create._extractEmbeddedRecords (http://localhost:4200/assets/vendor.js:83265:96)

The JSON returned from the server does contain the "id" field but the serializer seems unable to find it as we get the error and the models are not populated to the Ember store.

The line that fails is:

// assets/vendor.js
var belongsTo = { id: data.id, type: data.type };

And after putting a watch on the "data" variable where the "id" is being looked for it is "undefined". The "data" variable is defined in the code as:

var data = _normalizeEmbeddedRelationship2.data;

So I don't know if this gives any clues considering all the ember-data changes recently?

I also have a deprecation that may be related to the problem which is:

Ember Inspector (Deprecation Trace): Your custom serializer uses the old version of the Serializer API, with `extract` hooks. Please upgrade your serializers to the new Serializer API using `normalizeResponse` hooks instead.
at ember$data$lib$system$store$serializer$response$$normalizeResponseHelper (http://localhost:4200/assets/vendor.js:74034:15)
    at http://localhost:4200/assets/vendor.js:75772:25
    at Object.Backburner.run (http://localhost:4200/assets/vendor.js:10776:25)
    at ember$data$lib$system$store$$Service.extend._adapterRun (http://localhost:4200/assets/vendor.js:81352:33)
    at http://localhost:4200/assets/vendor.js:75771:15
    at tryCatch (http://localhost:4200/assets/vendor.js:65295:14)
    at invokeCallback (http://localhost:4200/assets/vendor.js:65310:15)
    at publish (http://localhost:4200/assets/vendor.js:65278:9)
    at http://localhost:4200/assets/vendor.js:42094:7

Also, to reiterate I am now using the active-model-adapter add-on instead of the one bundled with ember-data as an earlier deprecation message recommended. Not sure if perhaps this add-on is not compatible with ember-data after all the recent updates to it? (just tested this by reverting back to the original bundled adapter and the same error still occurs).

3
Do you have any custom adapter?Daniel Kmak
Thanks for your quick response! Yes, I have a custom adapter because I use the ActiveRecordAdapter. I've updated my post to show the adapter.danr1979
Can you include stack trace of this deprecation from your developer console? It would help.Daniel Kmak
Ok, I've added a few stack traces as there is more than one instance of the same deprecation. Thanks.danr1979

3 Answers

6
votes

If you set:

isNewSerializerAPI: true

On your serialiser it should solve the issue.

1
votes

Ok, the issue seems to have been fixed by the recent ember-data 1.13.4 update. Once I removed our attempted earlier fix of using:

isNewSerializerAPI: true

on the serializers (which caused other issues) and updated to 1.13.4 everything works as it should again.

Thanks for the help offered.

0
votes

Per the release docs push() now takes a JSON API compatible payload as the only argument. The type that used to be passed into push is present in the JSON API format so that's not needed separately any more. To have this work "out of the box" your API source would have to return valid JSON API JSON data.

If that's not possible, you would need a custom serializer that implements the translation methods to convert your API's JSON format into JSON API format. I think you could do this largely in "normalizeResponse" in the Serializer. Details for making that transition from old Serializer API to new can be found here in the release docs