0

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?

**edited --

error message:

enter image description here

James
  • 13
  • 5
  • I don't see any code that tried to read a property `type`. Can you share that as well? Also what is output of `console.log(movie)` – Dharmaraj Aug 22 '21 at 08:18
  • Thanks for replying @Dharmaraj. So that just it, there isn't any code that tries to read property 'type' and I am not getting the console log, I assume because of the error. – James Aug 22 '21 at 10:27
  • The error clearly says that there's a `(undefined.type)` situation. Can you share a complete screenshot off that error from terminal? It may have some clue where the error is coming from. Also try adding `console.log()` statements to check where the code is throwing the error – Dharmaraj Aug 22 '21 at 10:29
  • I have added a screenshot of the error message. its erroring at store. _pushInternalModel and if I go into the message it say "You tried to push data with a type '${modelName}' but no model could be found with that name.". Which is strange. – James Aug 22 '21 at 10:53
  • Just curious what's the name of your model, i.e. the file name. Is it `movies.js` or `movie.js`? – Andrey Stukalin Aug 23 '21 at 04:08
  • If you're encountering issues on your serializer, I suggest checking this [guide](https://davidtang.io/2015-12-05-which-ember-data-serializer-should-i-use/) for choosing your Ember Data Serializer. Also, you may refer to this [link](https://firebaseopensource.com/projects/firebaseextended/emberfire) for additional guides on using Emberfire to retrieve data from your Firestore. – RJC Aug 23 '21 at 06:23

0 Answers0