CDA delivers Draft Links without `fields` property
See original GitHub issue- Node Version: 7.10.1
- Npm Version: 4.2.0
- Platform: MacOS
- Package Version: 5.0.5
Is there a way to tell the Content Delivery API to not include Draft reference links?
I have a contentful site where some of the published content has reference links to content that is not published (aka in Draft status). When the API returns data for this content, it resolves the links, but only includes the sys
property and no fields
property which breaks my app. I would have expected the link reference to be undefined
or simply not be included in the response since the content it refers to is not yet published.
I considered using the select
query to only return the fields
, but that doesn’t seem possible when I am using getEntries
that searches by sys.id
for a specific entry ID. Also, I do need the sys
property for some of my content, so filtering our the sys
property entirely isn’t really an option.
It seems like there should be any easy way around this rather than adding a bunch of logic in my application that accounts for content with sys
property, but no fields
property.
Thanks.
Issue Analytics
- State:
- Created 6 years ago
- Comments:23 (11 by maintainers)
I am not exactly sure what you want to workaround.
If
resolveLinks
is turned off, the SDK will return the API result untouched aka with Link entities to represent the relation between two entries.If enable
removeUnresolved
, it will remove these Link Entities.If you combine both, it will resolve everything that is resolveable and remove only links that link to draft entries or deleted entries.
If you resolve on your own, you have to take care of your own to delete unresolveable entries. https://github.com/contentful/contentful-resolve-response might help, but this is exactly what we do internally in the SDK.
Does this help?
Thanks @Khaledgarbaya for the quick response. Your filter function only goes one level deep. I actually wrote a recursive function that loops through all the nested linked entries and removes those without the
fields
property, however that function sometimes exceeds the maximum call stack because of how many nested references there are.Perhaps I’ve implemented an anti-pattern, but my site has page content types that basically have nested references for all the sections of the page. This results in me having to use the
include: 10
query to get all the nested references. I did this so I’d have all the content for the page in one request, otherwise I’d have to make many separate API requests to retrieve all the linked content on the page.Thanks for any advice you can provide on this topic.