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

removeUnresolved Flag removes Link field

Open florian-milky opened this issue 4 years ago • 6 comments

Expected Behavior

Similar to #444 I expect the removeUnresolved to only remove draft entries. I tried tried latest version 8.2.1 I use include to fetch linked entries. At the level where includes stop, my field internalRef which is a link to another entry should be present:

fields: { identifier: 'Link to homepage', internalRef: { sys: { type: 'Link', linkType: 'Entry', id: '2uuZHGPFnGBsRnuJ6GYosL' } } }

Actual Behavior

The field just vanishes fields: { identifier: 'Link to homepage' }

Possible Solution

I am stuck now because with removeUnresolved: false I get errors all around the place because of draft entries and fields that is undefined (the ts type for fields does not include undefined #350 )

Context

A month ago when implementing Preview feature, I realized removeUnresolved is great to remove draft and deleted entries and get rid of potential errors due to lack of checking undefined fields (misleading type in TS). I started to use it and removed guards for undefined fields. Now I realize it is actually causing me this unexpected issue.

Environment

  • Language Version: v14.13.1
  • Package Manager Version: 6.14.8
  • Package Version: [email protected]
  • Which API are you using?: Delivery

florian-milky avatar Apr 08 '21 15:04 florian-milky

Note to Contentful team: I created at ticket in Contentful support, you may find additional information there

florian-milky avatar Apr 12 '21 08:04 florian-milky

Hi @florian-milky 👋 Thanks for the feedback!

For the content Delivery API, removeUnresolved will remove all draft/unpublished entries from the response. For the Preview API, removeUnresolved will still return draft/unpublished entries.

Based on that, the current behavior you described is expected.

Please let me know if I misunderstood your described scenario!

marcolink avatar Apr 16 '21 10:04 marcolink

Hi @marcolink , sorry I was unclear. The linked entity I want to fetch is published. It reaches the level where because of include configuration it just returns the id of the entity and not the full one. However the behavior I'm seeing is that with removeUnresolved set to true the field simply disappear. With false the field is there and I can manually fetch the entity that is not included.

florian-milky avatar Apr 16 '21 12:04 florian-milky

Hi @florian-milky , I am sorry for the misunderstanding of the removeUnresolved flag, I'll escalate this in order to provide a better explanation and some examples in our documentation, below I described how the flag works.

The removeUnresolved flag is mainly used when you need to remove unresolved links, they might appear when you reach a maximum level of nested related content (10 levels), in the case that you want to fetch more related content you might want to keep the unresolved links.

I want to clarify that the only way to get draft content is through our Preview API, therefore if the removeUnresolved flag is set to false, you could get some errors. By using the Delivery API you can be sure that you only will receive published content.

Vinz93 avatar Apr 26 '21 15:04 Vinz93

By using the Delivery API you can be sure that you only will receive published content

@Vinz93 That's true but there is a still a different behavior regarding unpublished content depending on removeUnresolved. See #350 for example. So either I need you to fix that unexpected behavior, or I need to handle this case everywhere in the code (fields undefined) before I can turn removeUnresolved back to false

florian-milky avatar Apr 27 '21 07:04 florian-milky

The removeUnresolved flag is mainly used when you need to remove unresolved links, they might appear when you reach a maximum level of nested related content (10 levels)

In my case, it's when I reach the level specified by the include option.

florian-milky avatar Apr 27 '21 07:04 florian-milky

This ticket has been closed due to inactivity. If you still need help resolving your issue, please reach out through our community Slack, or contact Contentful support directly.

mayakarabula avatar Jun 13 '23 15:06 mayakarabula