-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[gatsby-source-contentful] Add stringified internal.content
prop to JSON objects
#2967
[gatsby-source-contentful] Add stringified internal.content
prop to JSON objects
#2967
Conversation
Deploy preview ready! Built with commit 2e06c19 |
Deploy preview ready! Built with commit 2e06c19 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Great job 👏
Sorry for the slow reply — was out most of last week for Thanksgiving. I added a new content model w/ a json field and created a new content item w/ the package.json for Gatsby :-) I thought that appropriate. @sarahatwork if you'd like to redownload the content and update the test this seems ready to go! |
@KyleAMathews Thanks for making the update - all set! |
Awesome! Merging + publishing |
Thanks for tackling this issue @sarahatwork! I'm using JSON object fields and ran into that just yesterday. A quick update to When your JSON object field actually contains a collection... ... which according to contentful is valid. However
/cc @KyleAMathews |
@crtvhd Ah, good find. Unfortunately I don't think I'll be able to look into this (if I have spare time, #2037 is a more pressing issue to my current project). Maybe in the case of an array we'd want to manually nest it under a property - something like:
|
The issue is located in the line My solution for a fix that doesn't break anything is nesting the JSON only if it's an array. I'll shoot a PR soon. --EDIT-- I sent a PR here |
This is a potential solution to #1703. The issue is that right now you can only query JSON data types if you know all the keys.
This PR adds an
internal.content
property to nodes with typeObject
with a stringified version of the object. With this, we're supporting both uses cases:My use case is that I'm using a JSON object in a
translations
field to store translations for my site.It's entered in Contentful like this (kindly ignore my placeholder Chinese 🙈 ):
I don't want to have to update my queries every time I add a new translation, so being able to grab a stringified property works best for me.
Here's all the data (explicit keys and
internal.content
) on Graphiql:Another common use case for JSON objects where this solution might help is to store library settings.
One issue 🛑: I updated the data on
packages/gatsby-source-contentful/src/__tests__/data.json
manually with some data from my app. Before this is merged, it would be best to add a JSON field in the Gatsby test Contentful space, run the download script (to regenerate data.json), and update the test snapshots.