WebAPI-DBIC icon indicating copy to clipboard operation
WebAPI-DBIC copied to clipboard

Include requested entities in returned JSON when using a complex prefetch~json parameter

Open lohengrin332 opened this issue 11 years ago • 5 comments

Given the following query string: /artists?prefetch~json={"cds":"tracks"} I would expect a response similar to this:

{
    "linked": {
        "cds": [...],
        "tracks": [...],
    },
    "links": {
        "cds": {...},
        "tracks": {...}
    },
    "artists": [...]
}

But I am instead getting this, without tracks in the results:

{
    "linked": {
        "cds": [...],
    },
    "links": {
        "cds": {...},
    },
    "artists": [...]
}

lohengrin332 avatar Jan 07 '15 01:01 lohengrin332

That seems covered by an existing test that appears to produce what you're looking for. Could you try reproducing the problem in the WPID test suite?

timbunce avatar Jan 08 '15 20:01 timbunce

@timbunce Thats not actually an example of the type of prefetch asked in the OP. see https://github.com/timbunce/WebAPI-DBIC/blob/master/t/media-jsonapi/40-prefetch-req.exp#L399-L421 for the test. Though this output doesn't even look remotely correct.

I am not sure how JSON-API output should look for this sort of nested prefetch. The HALJSON format tests however outputs correctly.

ungrim97 avatar Jan 09 '15 09:01 ungrim97

Oh, right. Thanks @ungrim97! I'd only taken a quick look and was read the prefetch like it was a simple comma list. This is likely caused by Result class TestSchema::Result::CD_to_Producer has has multiple keys so relations like cd_to_producer won't have links generated.

timbunce avatar Jan 09 '15 13:01 timbunce

@lohengrin332 this is a better example of a complex prefetch that seems to be doing the right thing.

timbunce avatar Jan 09 '15 13:01 timbunce

@timbunce Based on the prefetch supplied and the response shown by the application/hal+json format, I would expect the cd_to_producer and producer to be returned in the response.

Is this therefor a limitation of application/api+json?

ungrim97 avatar Jan 14 '15 08:01 ungrim97