samedi 21 août 2021

Cannot read property 'type' of undefined ember and firebase

I am trying to retrieve data from my firestore using ember.js and emberfire.

i have a simple movie database. All that is in it right now is 1 document but for some reason when i try and retrieve the data, i keep getting "Cannot read property 'type' of undefined"! i understand that this is a JSONAPI issue but nothing seems to fix it.

My Route:

import Route from '@ember/routing/route';

export default class MovieRoute extends Route {
  async model() {
    this.store.findAll('movies').then(function(movie) {
      console.log(movie);
    });
  }
}

My Model:

import Model, { attr } from '@ember-data/model';

export default class MoviesModel extends Model {
  @attr('string') title;

}

Now it was my understanding that the default JSONAPISerializer is the default one but i tried adding a serializer anyway and my error changes to: Assertion Failed: normalizeResponse must return a valid JSON API document.

My adapter:

import FirestoreAdapter from 'emberfire/adapters/firestore';

export default FirestoreAdapter.extend({
  // Uncomment the following lines to enable offline persistence and multi-tab support
  // enablePersistence: true,
  // persistenceSettings: { synchronizeTabs: true },
});

My Serializer:

import JSONAPISerializer from '@ember-data/serializer/json-api';

export default class ApplicationSerializer extends JSONAPISerializer {}

it is also my understanding that the way the JSON is to be accepted is:

{
  data {
    type: 'movies',
    id: 1,
    attributes {
      title: 'ghostbusters'
    }
  }
}

so i also created a new document in the firestore, following this same format. Still no luck.

Can anyone point me in the right direction as to how to get the correct data returning from the firestore?




Aucun commentaire:

Enregistrer un commentaire