contentful.js icon indicating copy to clipboard operation
contentful.js copied to clipboard

SyncAPI not resolving links

Open oliverstr opened this issue 5 years ago • 3 comments

Expected Behavior

The sync function, when performing a call passing the nextSyncToken, the results should have the links resolved.

Actual Behavior

The links are coming only with the id reference:

"variations": {
                "en-US": [
                    {
                        "sys": {
                            "type": "Link",
                            "linkType": "Entry",
                            "id": "3PdSw4YLgRNVhSNKIJMOOa"
                        }
                    }
                ]
            },

Steps to Reproduce

Create a client with the Preview API data, and then call:

client.sync({
   nextSyncToken: <stored-token>,
   resolveLinks: true
})
  • Package Version: 7.7.0
  • Which API are you using?: Preview

oliverstr avatar Jun 14 '19 15:06 oliverstr

I am currently wrestling with this, too. It's actually documented in the API docs:

Important note: The the sync api endpoint does not support include or link resolution. However contentful.js is doing link resolution client side if you only make an initial sync. For the delta sync (using nextSyncToken) it is not possible since the sdk wont have access to all the data to make such an operation.

It seems to me that a nice addition would be the possibility of initializing the client with the current data before sync, and then have it resolve links using the current data and the sync deltas.

There is also a parseEntries method which seems useful, but it also seems to expect and deliver the data in a different format than the other methods (it has entries under items instead of entries, and I can't figure out how/if it handles assets).

linus avatar Jun 27 '19 14:06 linus

I agree with @linus . Currently I'm not 100% sure how to make use of the Sync API followup calls. Links are not resolved, and fetching again the updated entry directly from the Entry endpoint won't work as:

The include array is not applicable while retrieving a single entry.

So in the scenario where I have a page with multiple Linked entries, and I update the page title - so the delta update just returns the page entry (? correct?) - how can I get the rest of the unchanged linked items as well in order to correctly rebuild my page?

Worth mentioning the approach gatsby engineers are suggesting in https://github.com/gatsbyjs/gatsby/commit/a660d327d2b5ab4a054d690421ae8940d7ba54fe makes sense, but sync() response doesn't look cacheable, probably because the internal references and the inability to string-ify without toPlainObject method or stringifySafe?

A working example in the documentation would be also nice.

gambry avatar Jan 10 '20 15:01 gambry

Agreed this should be something that we can add to the recursive requests when syncing, in our specific case we're using the sync api to reduce rate limiting, if the deltas provided to us fail to resolve our links, it breaks the logic of storing data in an additional middle layer.

Especially avatar Nov 15 '21 01:11 Especially

closing the issue, if you still need help with this please reach out to Contentful support

mayakarabula avatar Jun 13 '23 14:06 mayakarabula