question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 6 years ago
  • Comments:23 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
axe312gercommented, Jun 13, 2018

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?

2reactions
dganoffcommented, Dec 22, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CDA, DNR seek public input on draft of Natural and Working ...
The State of Colorado is seeking comment from the general public, producers and other members of land management and agricultural communities on ...
Read more >
Content Delivery API | Contentful
The Content Delivery API (CDA), is a read-only API for delivering content from Contentful to apps, websites and other media.
Read more >
Published or Draft? - Content Preview API
How can I find out whether content items are published or in draft status with the preview API?
Read more >
Coeur d'Alene Field Office - Bureau of Land Management
The field office includes recreation opportunities for hiking, biking, boating and wildlife viewing around the scenic Lake Coeur d' Alene. Notable sites include ......
Read more >
ISS Draft Review Process for Canadian Issuers
To ensure timely delivery of our analyses to our clients, we cannot provide a draft to any company that files its circular less...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found