mst-gql icon indicating copy to clipboard operation
mst-gql copied to clipboard

Ability to use non-standard `id` field name

Open kidroca opened this issue 5 years ago • 2 comments

I'm getting an error when fetched data is saved to a root collection:

Error: [mobx-state-tree] A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '3', but expected: 'undefined'

Tracing it with the debugger here's what I've found:

image

  • data.id is undefined
  • at some point the code uses the id to store the created instance in a map and it fails with the error

I'm not sure if there's some logic that assigns the data.id the actual id for that particular structure is inside data.client_id this is correctly picked up in the scaffolded model

Is there a reason for using set instead of put there ? Using put would infer the id from the created instance and use the correct key

kidroca avatar Apr 20 '20 21:04 kidroca

I've never tried to use mst-gql without using id as my id field name. Looks like we might need to add a way to customize this and/or infer it.

chrisdrackett avatar Apr 21 '20 15:04 chrisdrackett

in my case the typeDef object has the identifierAttribute property link With the name of correct id property. Probably it could be used there

dmytro-shpak avatar Jul 04 '22 17:07 dmytro-shpak