#Getting an error during my first time using ember-data

1 messages · Page 1 of 1 (latest)

safe geode
#

I'm getting the error shown in the first image when I try to run findAll on a table-summaries model.
if I click on the stacktrace to find where the error is occurring it takes me to the breakpointed line in the next screenshot store._push(payload,isAsyncFlus);

This is what the payload I'm trying to serialize looks like:
https://pastebin.com/3GQdbdP1
And these are my two models:
https://pastebin.com/Eaun5WpP

alpine valve
#

cc @dark shoal ❤️

keen stone
#

@safe geode in the models, seems like you paste the same model twice

#

also the type name in the payload must match the type name in the relationship

#

ie: either you have an 's' everywhere, either you remove the 's' everywhere

safe geode
keen stone
#

I think the file name is also important

safe geode
# keen stone I think the file name is also important

Currently for TableSummariesModel the corresponding file name is table-summaries.ts

and for StaticDataTableColumnModel the corresponding filename is static-data-table-column.ts

both of these are under the models folder

keen stone
#

so the type in the payload must be ""type": "static-data-table-column"

#

(I guesse you are on ember-data 5.3.8 ?)

#

and since you have a belongsTo('table-summaries') defined in your table-column model, in your payload, I think you have to add the relationship {type,id}

safe geode
# keen stone (I guesse you are on ember-data 5.3.8 ?)

my package.json states that I'm on the following versions:

 "@types/ember-data": "^4.4.16",
    "@types/ember-data__adapter": "^4.0.6",
    "@types/ember-data__model": "^4.0.5",
    "@types/ember-data__serializer": "^4.0.6",
    "@types/ember-data__store": "^4.0.7",

do you think it's worth updating ?

keen stone
#

I don't know what to do with these types. I would say if you are with ember-data 5.3.8, you don't need these at all

safe geode
keen stone
#

no sorry, I mean you can remove "@types/ember-data" declarations in your package.json file

#

maybe you can replace them with pnpm install @warp-drive/core-types

safe geode
#

running pnpm install @warp-drive/core-types gave me a pretty big error:

Stack Trace and Error Report: /var/folders/d_/zgzh3z2j4s55w95pj614q3xw0000gq/T/error.dump.3fe26d9f0f678e227603d5cf4466bf03.log
Some V1 ember addons are resolving as incorrect peer dependencies. This makes it impossible for us to safely convert them to v2 format.
alpine valve
#

install doesn't print that error -- what command was ran? and is there more text?

#

(like, what file / addon is it complaining about?)

safe geode
alpine valve
#

ah, you have lots of peer violations from warp-drive

#

looks like you have competing versions

#

beta.4 vs beta.11

#

there can only be one!

safe geode
#

is there a way I can remove the beta.4? I think the beta.4 might just be there because of the packages that form ember-data

alpine valve
#

depends on your goals tho

#

like, TS? or just getting runtime working?

#

I'm not sure how much retrofit covers

#

This page doesn't have a "getting started" guide, so I don't know where to start haha

safe geode
safe geode
keen stone
#

I mean in the payload for the table columns:

            {
                "type": "static-data-table-columns",
                "id": 1,
                "attributes": {
                    "prettyName": "City ID",
                    "colIndex": 1,
                    "isKey": true
                },
                relationships: {
                    tableSummaries: {
                        data: { type: 'table-summaries', id: 1 }
                    }
                }
            },
#

Also, I've juste noted something weird in the model
@belongsTo('table-summaries') TableSummaries!: any;

#

the capitalized T looks weird

#

I'm sorry I have to go, I hope you could make it work. Can help you tomorrow though.

safe geode
#

Thank you so much for your help so far! I really appreciate it!

safe geode
#

Hello, I've since simplified everything a lot more. I've completely removed the array of columns and I'm still getting the error in the image.

I've included the updated files, payload and package.json in this link:
https://pastebin.com/5CYpQRuj

keen stone
#

Hello, indeed this is weird. I'm afraid I really don't see what's going on here. Maybe I'm missing something obvious, but can't find it. Maybe @dark shoal ?

#

Can you debug a bit putting a breakpoint in the cache handler file ?

safe geode
#

This would be index.js:636:11:

#

this would be q._push(cache-handler-C5ilAUZ5.js:5250:10)

#

it then goes to this function which is actually throwing the error:

#

if I evaluate CACHE_OWNER it shows Symbol(warpDriveCache)
So I'm guessing that the issue has something to do with the identifier being undefined

dark shoal
#

What’s your serializer do?

#

Seems like it’s doing something odd

safe geode
#

Hi runspired,

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

export default class ApplicationSerializer extends JSONAPISerializer {
  normalizeResponse(store, primaryModelClass, payload, id, requestType) {
    console.log('serializing at application level:', payload);
    // Parse the 'response' field
    payload.response = JSON.parse(payload.response);
    console.log('parsed payload:', payload);

    // Call the super method with the updated payload
    return super.normalizeResponse(store, primaryModelClass, payload, id, requestType);
  }
}

This is what my serializer looks like. I've just added some logging just to see what the payload looks like once I've parsed it to json

keen stone
#

🤔 why do you have to payload.response = JSON.parse(payload.response); ?

safe geode
#

I don't have to do it, I'm happy to remove it. It's something I added to make sure my backend wasn't sending just a string or something like that.

#

I've removed it but still getting the same error. The identifier I pointed out earlier in the screenshots is still undefined

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

export default class ApplicationSerializer extends JSONAPISerializer {
  normalizeResponse(store, primaryModelClass, payload, id, requestType) {
    console.log('serializing at application level:', payload);
    return super.normalizeResponse(store, primaryModelClass, payload, id, requestType);
  }
}
keen stone
#

I'm not sure, but the jsonApiDoc here looks wrong to me

#

looking what's going on in my app, it has the data object , not a response one

safe geode
#

Interesting, I’ll try using the Serializer to remove the “response” key so that it uses data instead

keen stone
#

maybe, but what I don't understand, is that the payload here looks well formed to me, I think that's why Chris was saying the serializer doing something odd

safe geode
#

that made the error go away!
Incoming payload:

{
    "error": null,
    "response": "{\"data\":[{\"type\":\"table-summary\",\"id\":\"2\",\"attributes\":{\"prettyName\":\"City lookup\",\"description\":\"Maps city codes to city names\"}},{\"type\":\"table-summary\",\"id\":\"1\",\"attributes\":{\"prettyName\":\"Hotel lookup\",\"description\":\"Maps hotel codes to hotel names\"}}]}"
}

After removing the response key:

{
    "data": [
        {
            "id": "2",
            "type": "table-summary",
            "attributes": {
                "description": "Maps city codes to city names"
            },
            "relationships": {}
        },
        {
            "id": "1",
            "type": "table-summary",
            "attributes": {
                "description": "Maps hotel codes to hotel names"
            },
            "relationships": {}
        }
    ]
}

Result: Error is gone and data identifier is now populated!

keen stone
#

Nice 🙂