Git Product home page Git Product logo

contentful-resolve-response's Introduction

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

contentful-resolve-response's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

contentful-resolve-response's Issues

Performance problems with 100k+ entries

We are trying to build our website with gatsby using gatsby-source-contentful. I've identified a performance problem in the way links are looked up. By using an array as datastructure and doing liniar search, it takes 20-30 mins extra to resolve links.

return findNormalizableLinkInArray(allEntries, predicate);

In my POC I put all the entries in an object with id as key which allowed it to resolve the links immediately.

Looking at the code today it seems like it can support entries and assets with the same id. I don't know if this is a use case that needs to be supported.

Error 'TypeError: Cannot read property 'type' of undefined' in 1.2.2 version

Hello
I've tried upgrade contentful-resolve-response from version 1.1.4 to 1.2.2 and I get an error in console: TypeError: Cannot read property 'type' of undefined
I get response from contentful like that:
{ "sys": { "type": "Array" }, "total": 1, "skip": 0, "limit": 100, "items": [ { "fields": { "internalTitle": "Page", "slug": "b", "title": "B", "description": "test", "metaTitle": "B", "metaDescription": "" } } ] }
I think the problem is in lines:
https://github.com/contentful/contentful-resolve-response/blob/master/index.js#L120
and
https://github.com/contentful/contentful-resolve-response/blob/master/index.js#L122
My response responseClone.items doesn't have sys key so it will be undefined.
Can you check it?
In old version, everything works perfectly.

License missing from project

Hey guys, I have a project that copied/modified your code for internal use but couldn't find the license for it.

I see it's MIT, but since MIT usually asks for The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. could you add such a license in this repo ?

Thank you !

UglifyJS being thrown during build

Hi there, just thought I should flag something I encountered today. I'm not sure if its a problem with my setup or a general problem.

  • Project runs fine in development, with webpack-dev-server
  • Rails/Webpacker project being pushed to Heroku
  • Heroku runs build/compile, is using Uglify to compile JS
  • Uglify can't resolve because of an "unexpected token"
Unexpected token: operator (>) [./node_modules/contentful-resolve-response/index.js:8,0]

Large bundle size due to lodash-contrib

Hey there.

We're using webpack as our module bundler, and are pulling in your contentful package in through npm.

I just ran a analyzation of the size of my final JS bundle, and I noticed contentful (and it's dependencies) were the cause of 17.2% of my bundle (616.87 kB) unminified.

After looking into it a bit deeper, contentful-resolve-response is using lodash-contrib, which is probably unnecessary, given the fact that you guys are only using 5 of lodash-contrib's functions.

I'm wondering if you'd be willing to slim down the dependencies here for the sake of bundle sizes everywhere.

Thanks!
-Adam

v1.8.0 Browser Compatibility

Hello - the 1.8.0 release uses the regex /.*:spaces\/(?<spaceId>[^/]+)(?:\/environments\/(?<environmentId>[^/]+))?\/entries\/(?<entityId>[^/]+)$/ which has named capture groups. These are only compatible with browsers that support ES2018 and up. Was wondering if the browser support change was intentional? If not would it be possible to remove the group names since they aren't being used currently? The matching code is just using string.match. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.