0

I wanted to get data and show it in UI. Here's how i write to get the "movies" data.

let movies= yield this.store.findAll('movie');

And I log the "movies". As the picture below shows that there's no data for "photos".

enter image description here

Here's the network: enter image description here

I'm getting data back from hasura like this:

{
  "data": {
    "movies": [
      {
        "id": "584db434-5caa-475e-b3ec-e98e742f0030",
        "movieid": "abc123",
        "description": "Penquins dancing in antactica",
        "photos": [
          {
            "id": "c4d2833a-4896-42b0-ae8b-0ab9fe71d1d4"
          },
          {
            "id": "e04697e3-21fe-4f0e-8012-443f26293340"
          }
        ]
      }
    ]
  }
} 

But Ember.js can't read and render the relationship data (photos). Is it the "photos" data should be like this?

"photos": [c4d2833a-4896-42b0-ae8b-0ab9fe71d1d4, e04697e3-21fe-4f0e-8012-443f26293340]

How can I convert it in Ember? or in Hasura?

ELsssss
  • 216
  • 2
  • 11
  • Can you clarify what you're trying to do? Are you just trying to show the data in the UI/Handlebars? Are you grabbing information through the model hook? – Cameron Nov 01 '21 at 01:58
  • what adapter are you using? do have a way to interpret hasura-formatted data into the `{json:api}` standard format (what ember-data uses)? are you using ember-data? or are you using fetch? – NullVoxPopuli Nov 01 '21 at 18:44
  • @Cameron I've edited the question. Hope thats clearer – ELsssss Nov 02 '21 at 10:12
  • @NullVoxPopuli Im using restadapter. im not sure is there a way to format the data. – ELsssss Nov 02 '21 at 10:14

1 Answers1

0

Thanks for updating your question!

Since you're using ember-data, you'll need a custom adapter and serializer to form your data into the format that ember-data is expecting (since there are infinite numbers of ways APIs decide how to structure data).

More information on that can be found here: https://guides.emberjs.com/release/models/customizing-adapters/ and here: https://guides.emberjs.com/release/models/customizing-serializers/

Your data is fairly well structured already, so conversion should hopefully go well. Comment back if you have issues <3

NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352
  • Hi, I'm using RestAdapter and RestSerializer. But im not sure how to implement it. Should I convert the photos data to `"photos": [c4d2833a-4896-42b0-ae8b-0ab9fe71d1d4, e04697e3-21fe-4f0e-8012-443f26293340]`? So that ember can read that? – ELsssss Nov 03 '21 at 01:39
  • can you add your adapter and serializer code to your question? – NullVoxPopuli Nov 03 '21 at 03:33