Skip to content

Include paths and fieldsets #105

@neomerx

Description

@neomerx

This issue is about the following questions

  • what should we do if include contradicts fieldset
  • removing relationship with resource identities breaks full linkage and might make the data non-sense.

The question above will be explained in details and illustrated by examples below

The test data have the following structure

`Site` (1)
  |_ `Posts` (1)
        |_ `Author` (1)
        |_ `Comment` (2) + each comment has a relationship with the same `Author` above

in JSON API format those data look like this

1-level deep include paths (filter attributes and relationships)

We are trying to emulate the following resource request and the question is what should be in output

GET /sites/1?include=posts&fields[sites]=name&fields[posts]=title,comments

In the URL above there is a contradiction. From one side we say we want field name in output but not field posts for Site. On another side we expect posts to be in output.
The request above will produce

{
    "data":{
        "type":"sites",
        "id":"2",
        "attributes":{
            "name":"site name"
        },
        "links":{
            "self":"http://example.com/sites/2"
        }
    }
}

if field posts is in URL

GET /sites/1?include=posts&fields[sites]=name,posts&fields[posts]=title,comments

it will produce

{
    "data" : {
        "type" : "sites",
        "id"   : "2",
        "attributes" : {
            "name" : "site name"
        },
        "relationships" : {
            "posts" : {
                "data" : [
                    { "type" : "posts", "id" : "1" }
                ]
            }
        },
        "links" : {
            "self" : "http://example.com/sites/2"
        }
    },
    "included" : [
        {
            "type" : "posts",
            "id"   : "1",
            "attributes" : {
                "title" : "JSON API paints my bikeshed!"
            },
            "relationships" : {
                "comments" : {
                    "data" : [
                        { "type" : "comments", "id" : "5" },
                        { "type" : "comments", "id" : "12" }
                    ]
                }
            }
        }
    ]
}

Possible solution for the contradiction in

GET /sites/1?include=posts&fields[sites]=name&fields[posts]=title,comments

would be something like (relationship posts disappear but posts present in included, but would it mean if we have relationships as my-posts, favorite-posts, friends-posts or just relationships with polymorphic data...)

{
    "data" : {
        "type" : "sites",
        "id"   : "2",
        "attributes" : {
            "name" : "site name"
        },
        "links" : {
            "self" : "http://example.com/sites/2"
        }
    },
    "included" : [
        {
            "type" : "posts",
            "id"   : "1",
            "attributes" : {
                "title" : "JSON API paints my bikeshed!"
            },
            "relationships" : {
                "comments" : {
                    "data" : [
                        { "type" : "comments", "id" : "5" },
                        { "type" : "comments", "id" : "12" }
                    ]
                }
            }
        }
    ]
}

Test code is here

2-level deep include paths

It has the same set of open questions

  • what should we do if include says include but fieldset says not to include or vice versa
  • removing relationship with resource identities breaks full linkage and might make the data non-sense.

An example of 2 level include could be found here

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions