postlight / lux

Build scalable, Node.js-powered REST JSON APIs with almost no code.
https://lux.postlight.com
MIT License
570 stars 60 forks source link

Relationships not present in included resources #640

Open nickschot opened 7 years ago

nickschot commented 7 years ago

When requesting to include records for relationships of the requested record (i.e. my-model?include=something1,something2, the relationships of those records are not included in the response.

I think this throws off at least ember-data a bit as it won't recognise any relationships for those records.

EDIT: some more information for this added below.

Example request: GET /my-model/1?include=something

Example response from Lux (with the missing relationships for the records in "included"):

{
  "data": {
    "id": "1",
    "type": "my-model",
    "attributes": {
         ...
    },
    "relationships": {
      "something": {
        "data": {
          "id": "30",
          "type": "something"
        },
        "links": {
          "self": "http://localhost:5000/something/30"
        }
      }
    }
  },
  "included": [
    {
      "id": "30",
      "type": "something",
      "attributes": {
        ...
      },
      "links": {
        "self": "http://localhost:5000/something/30"
      }
    }
  ],
  "links": {
    "self": "http://localhost:5000/my-model/1?include=something"
  },
  "jsonapi": {
    "version": "1.0"
  }
}
zacharygolba commented 7 years ago

I believe this is actually an error in the ember-data implementation, not Lux. See this section of the JSON API spec.

I'm going to close this issue for now.

nickschot commented 7 years ago

-- oops, thought it was another issue.

EDIT: improvements to the first post to better clarify what this specific feature request is.

nickschot commented 7 years ago

Can be enabled by toggling this boolean: https://github.com/postlight/lux/blob/7bf2478bd0305d65549f9b9fe98997f51dc07ae0/src/packages/serializer/index.js#L728

lehni commented 7 years ago

@nickschot I believe the lines have shifted since your link. Did you mean formatRelationships?

nickschot commented 7 years ago

They seem to have! And I do! Thanks for pointing that out. I modified the comment with a more resilient link.

lehni commented 7 years ago

How / where are you setting this value to true?

nickschot commented 7 years ago

I am not currently. It can be set to true in the lux codebase as pointed out in the comment as an initial fix for this issue, some tests would need to be added though.