contentful-resolve-response
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/contentful-resolve-response package

1.8.1 • Public • Published

contentful-resolve-response

npm

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:

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!!

Readme

Keywords

none

Package Sidebar

Install

npm i contentful-resolve-response

Weekly Downloads

504,219

Version

1.8.1

License

MIT

Unpacked Size

20.1 kB

Total Files

5

Last publish

Collaborators

  • hungryblank
  • zcei
  • cf-admin
  • whydah-gally