farmOS / farmOS.js

A JavaScript library for working with farmOS data structures and interacting with farmOS servers.
MIT License
17 stars 13 forks source link

Handling the `type` field in resource identifiers. #58

Closed jgaehring closed 2 years ago

jgaehring commented 2 years ago

I've come to realize while dealing with caching and syncing in Field Kit that I haven't really addressed the issue of the type field in resource identifiers, with regard to how its defined in the JSON:API spec. This is somewhat complicated by [how Drupal implements the spec]() to accommodate its entity/bundle model:

The type member is always required. The value for the type member is derived from the entity type name and bundle, where applicable. The type for an entity resource always follows the pattern entity_type--bundle. As an example, the core article and basic page node types will be represented as: node--article and node--page.

I've already departed from the Drupal convention insofar as I've transformed the type member of resource objects themselves, removing the entity type and hyphens and just leaving the bundle name, via the transformRemoteEntity function used by the adapter. But I've refrained doing something similar to the type member in resource identifier objects, which are used primarily in relationships, because without the bundle and the entity name, it could be hard if not impossible to definitively identify which entity/bundle is being referenced, at least without querying every entity by its UUID.

A few possible solutions:

That last option, to leave it as is, is what I will do for now, and it's probably sufficient for now, at least where farmOS.js is being used in Field Kit, but I could see this as being critical to the development of more robust functionality in the future.

jgaehring commented 2 years ago

Resolved by #67.