https://github.com/contentful/contentful-resolve-response
Resolve items & includes of a Contentful API response into a proper object graph
https://github.com/contentful/contentful-resolve-response
Last synced: about 1 year ago
JSON representation
Resolve items & includes of a Contentful API response into a proper object graph
- Host: GitHub
- URL: https://github.com/contentful/contentful-resolve-response
- Owner: contentful
- License: mit
- Created: 2014-06-06T11:19:47.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2025-05-09T00:34:05.000Z (about 1 year ago)
- Last Synced: 2025-05-09T01:29:29.391Z (about 1 year ago)
- Language: JavaScript
- Size: 2.23 MB
- Stars: 55
- Watchers: 33
- Forks: 15
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# contentful-resolve-response
[](https://www.npmjs.com/package/contentful-resolve-response)
Suppose you have a Contentful query's response JSON. The links are
nice, but what we really usually need is the response with a resolved
object graph.
`contentful-resolve-response` does just that:
``` js
var resolveResponse = require('contentful-resolve-response');
var response = {
items: [
{
someValue: 'wow',
someLink: { sys: { type: 'Link', linkType: 'Entry', id: 'suchId' } }
}
],
includes: {
Entry: [
{ sys: { type: 'Entry', id: 'suchId' }, very: 'doge' }
]
}
};
var items = resolveResponse(response)
// Responds with the resolved array of items.
console.log(items);
// produces:
// re`solved` object [Array] of items.
[
{
// Value stays the same
someValue: 'wow',
// Link gets replaced by the actual object from `includes.Entry`
someLink: {sys: {type: 'Entry', id: 'suchId'}, very: 'doge'}
}
]
```
Note that:
- Multiple links to the same resource will point to the same object
- Circular references are possible, still!!