Wikodit / js-data-jsonapi-light

JSData adapter which serialize and deserialize JSONApi response and requests.
MIT License
8 stars 4 forks source link

nested included fields not respected? #33

Closed phortx closed 6 years ago

phortx commented 6 years ago

I'm requesting a comment from the api, which belongs to a post which belongs to a user (author).

The API response is

{
  "data": {
    "id": "2",
    "type": "comments",
    "attributes": {
      "text": "Hello world!",
    },
    "relationships": {
      "post": {
        "data": {
          "id": "1",
          "type": "posts"
        }
      }
    }
  },
  "included": [
    {
      "id": "1",
      "type": "posts",
      "attributes": {
        "name": "Example post"
      },
      "relationships": {
        "user": {
          "data": {
            "id": "1",
            "type": "users"
          }
        }
      },
      "included": [
        {
          "id": "1",
          "type": "users",
          "attributes": {
            "email": "example@example.net"
          }
        }
      ]
    }
  ]
}

Then I'm accessing comment.post.user, but the user is undefined. When I load the post from the API and calling post.user, the user is available.

When I make the API to include the user directly in the root included field, everything works.

Could it be that this adapter can't handle nested included fields?

phortx commented 6 years ago

Ok seems like this is specification conform and I have a bug in my API: https://github.com/trailblazer/roar-jsonapi/issues/26

Nevermind ;)

Tronix117 commented 6 years ago

Yep, it is going against the concept of jsonapi, and should not be implemented.