[gatsby-source-contentful] odd nesting of "LongText" field types...
See original GitHub issueDescription
hi there 👋 thanks for the awesome lib! 👏👍
something i ran in to recently: i’m getting oddly nested / awkward graphQL data - ex: node.title.title
(vs. node.title
) after syncing with the contentful API.
Environment
Gatsby version: v1.9.127 Node.js version: v8.9.3 Operating System: macOS 10.12.6
Actual result
given an api response from https://cdn.contentful.com like:
{
"sys": {
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "..."
}
},
"id": "1ywsMB0CakekKucSkUS6Ee",
"type": "Entry",
"createdAt": "2017-12-11T19:54:49.991Z",
"updatedAt": "2017-12-13T22:18:58.292Z",
"revision": 6,
"contentType": {
"sys": {
"type": "Link",
"linkType": "ContentType",
"id": "page"
}
},
"locale": "en-US"
},
"fields": {
"name": "whitepapers",
"title": "Whitepapers",
...
}
}
and a graphQL query like:
{
allContentfulPage {
edges {
node {
id
name
title {
title
}
}
}
}
}
i end up with data like:
{
"data": {
"allContentfulPage": {
"edges": [
{
"node": {
"id": "c1ywsMB0CakekKucSkUS6Ee",
"name": "whitepapers",
"title": {
"title": "Whitepapers",
}
}
}
]
}
}
}
note the difference between the name and title fields. in contentful, “name” is a ShortText
field while “title” is LongText
Expected behavior
ideally, both “name” and "title would be represented in the same way - that is, like the “name” data, un-nested (instead of node.title.title
, just plain old node.title
)
Steps to reproduce
1. configure gatsby-source-contentful
to point to a recently populated space & content model
2. run gatsby develop
3. visit http://localhost:8000/___graphql and query your data
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top GitHub Comments
This is deliberate — long text fields are markdown so to be able to easily compile those, this field type is created as a child node so then gatsby-transformer-remark can compile it to HTML e.g. https://github.com/gatsbyjs/gatsby/blob/971c4af38a588cd54c18cb9645d60d50856fd9ea/examples/using-contentful/src/templates/product.js#L72
The source plugins still exposes the raw markdown but generally you’d want to use the transformed HTML as in the above code sample.
@KyleAMathews - it would make good sense to add this information into https://www.npmjs.com/package/gatsby-source-contentful and the Gatsby 2.0 docs. This took me hours to figure out.