lotas / contentful-graph

Visual representation of contentful content models in form of graphs
https://www.contentful.com/blog/2017/08/08/how-to-quickly-visualize-your-content-model/
MIT License
59 stars 6 forks source link

throws TypeError if multiple reference field contains validation for non-existent content type #6

Closed cachrisman closed 5 years ago

cachrisman commented 6 years ago

Consider the example of a content type which has a multiple reference field and that field has a validation to only accept entries of certain content types with the ids: series, season, video. The model has since changed and series has been deleted and replaced with show. The validation on that multiple reference field is now invalid.

When I use this tool in the above mentioned situation I get

(node:31538) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'name' of undefined
(node:31538) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I think this tool could deal with that invalid reference by either labeling it as invalid (with the benefit of alerting the user to this error) or by excluding it quietly.

Happy to provide a PR with a fix.

lotas commented 6 years ago

Thank you for reporting this. I haven't encountered this before, and am wondering now how this could have happened? Can you please provide an example of model to debug? Is Contentful keeping references to the non-existing model?

Also, PR is more then welcome and appreciated! :)

Thanks!

cachrisman commented 6 years ago

Here is an example content model:

https://gist.github.com/cachrisman/f641b8988c328582878f56f6138a43a7

or see this image

image

Now imagine I delete the series content type and add a new content type called show which does exactly the same thing as series. Essentially I've renamed series to show. Here is an updated content model

https://gist.github.com/cachrisman/0b550dffef61ba5e4fed81d91f5c2626

lotas commented 5 years ago

Hey @cachrisman terribly sorry for the slightly delayed reply .. I think I've slept for a year :)

Anyways, the issue has been solved in a recent commit https://github.com/lotas/contentful-graph/commit/eab85ea1b8a87b1b5602ed472db5bf3fb3390b79 and a new version was published 1.2.0

Thank you once again for the detailed bug report, attached model helped. I also added support to run against local file, without even using contentful API. npx contentful-graph ./your-model.json which does the same locally.

If this is still relevant, please check, if not, sorry for the delayed response. Cheers