holidayextras / jsonapi-server

A config driven NodeJS framework implementing json:api and GraphQL
MIT License
488 stars 115 forks source link

Ability to set page[limit] for included resources #260

Open zzztop opened 7 years ago

zzztop commented 7 years ago

Apologies if I've overlooked this, but I am wondering if it is possible to set page[limit] params for included resources.

st3xupery commented 7 years ago

I think according to the spec there should be no limit to what's included... as far as my readings tell me in the spec sheet for pagination. if a particular resource has a many "relationship" of 200 then technically it seems like it should include all of them.

However, the actual enactment of page limits occurs in the handlers, and if you are programming your own handler you have full control of what you manually trim before sending to the callback.

I faced a dilemma with my handler cutting off the includes at 50 which was the default page limit. This was not the behaviour I wanted as I needed all of the includes that were past the 50 limit per resource. My solution to this issue was to have my handler check if the resource being called was being called internally from the include processes in the JSON:API-Server code by running this condition:

const internalRouting = request.originalUrl.indexOf(route.base + route.path) === -1;

and then skipping past the include slicing.

That's my insight on the matter, let me know if that helps.