Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

Fetching with included relationships #42

Closed
d-lamers opened this issue Jan 10, 2018 · 2 comments
Closed

Fetching with included relationships #42

d-lamers opened this issue Jan 10, 2018 · 2 comments

Comments

@d-lamers
Copy link

It seems it does not allow to fetch included relationships. As described here: http://jsonapi.org/format/#fetching-includes. Would you consider supporting it?

@srallen
Copy link
Contributor

srallen commented Jan 11, 2018

Include requests do work, but there was a design decision early on with caching that resulted in some quirky behavior with the include requests, see #34. There's also another related bug about inconsistent type used by the client for include requests: #35

You can make an include request by adding it to the options object. If it's a single include request, put it in an array as noted in #35:
apiClient.type('resource').get('1234', { include: ['otherResource'] })

Or multiple includes:
apiClient.type('resource').get('1234', { include: 'otherResource,anotherResource' })

Assuming there aren't any issue with the API you're requesting from, it should return a 200 response in your network tab in dev tools. The client, however, will only return the original requested resource in promise. The includes are put into the cache. You have to form another 'fake' request to get them out of the cache:

apiClient.type('otherResource').get() and this will return in the promise that included resource out of the client cache and won't form another network request.

It's a quirky design decision and not really helpful in real world application, imo. Just so you know, we're not really maintaining this client outside of critical bug fixes at the moment. We're likely moving toward using something like superagent directly rather than an abstraction like this client in the future.

@srallen srallen closed this as completed Jan 11, 2018
@d-lamers
Copy link
Author

Thanks for clearing this up. Makes sense.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants