yury-dymov / json-api-normalizer

Normalize JSON API data for redux applications
MIT License
576 stars 40 forks source link

Relationships without data #2

Closed eiktyrner closed 7 years ago

eiktyrner commented 7 years ago

This throws Cannot read property 'id' of undefined

      "relationships": {
        "movie": {
          "links": {
            "self": "http://localhost:3000/api/v1/actor/1c9d234b-66c4-411e-b785-955d57db5536/relationships/movie",
            "related": "http://localhost:3000/api/v1/actor/1c9d234b-66c4-411e-b785-955d57db5536/movie"
          }
        }
      }

While this works.

      "relationships": {
        "movie": {
          "data": { "type": "movie", "id": "9" },
          "links": {
            "self": "http://localhost:3000/api/v1/actor/1c9d234b-66c4-411e-b785-955d57db5536/relationships/movie",
            "related": "http://localhost:3000/api/v1/actor/1c9d234b-66c4-411e-b785-955d57db5536/movie"
          }
        }
      }

It seems that a data object is assumed for each relationship even though the spec says it's not required.

yury-dymov commented 7 years ago

@eiktyrner, thank you for the feedback. Before diving into the implementation, I would like to discuss more business side of the issue.

Are we talking about lazy loading here? We know that movie object exists and related to the parent object, but we will load it only at the time we really need it?

eiktyrner commented 7 years ago

@yury-dymov That is indeed one case where this could happen. The point is that this library needs to follow the whole spec before it's usable, regardless of business case.

yury-dymov commented 7 years ago

@eiktyrner, I agree with you regarding the spec. The point here is that I need to understand exact business cases for the optimal implementation.

Well, for json-api-normalizer it would be easy but for redux-object there would be no "easy fix" as far as I can see.

yury-dymov commented 7 years ago

Should be resolved via https://github.com/yury-dymov/json-api-normalizer/commit/9eba58b7cf7aad488fa67129fcd494a1043ee0a2, please check.

redux-object will not support lazy loading as for now. I need to think regarding a good API for such occasion.

Update: implementation details: https://github.com/yury-dymov/json-api-normalizer#lazy-loading

eiktyrner commented 7 years ago

Thanks for the quick help, that seems to solve my issue.