Skip to content
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] odd nesting of "LongText" field types... #3205

Closed
busticated opened this issue Dec 13, 2017 · 5 comments
Closed

Comments

@busticated
Copy link
Contributor

Description

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

@KyleAMathews
Copy link
Contributor

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.

The source plugins still exposes the raw markdown but generally you'd want to use the transformed HTML as in the above code sample.

@jserrao
Copy link
Contributor

jserrao commented Aug 21, 2018

@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.

@KyleAMathews
Copy link
Contributor

@jserrao that'd be great! Sorry it took so long! Could you out together a small PR for the readme explaining the difference?

@jserrao
Copy link
Contributor

jserrao commented Aug 21, 2018

@KyleAMathews - sure, can do. What's the appetite for me putting together something like the WordPress plugin tutorial, but for Contentful? I've learned a lot of little things building a Gatsby/Contentful site over the past couple weeks.

@jserrao
Copy link
Contributor

jserrao commented Aug 22, 2018

@KyleAMathews - PR is ready to go: #7533

slk333 added a commit that referenced this issue Jan 3, 2020
…by-transformer-remark

As shown here: #3205 (comment)
you cannot simply do 
```{
body{
 body}
}
since the body will be raw markdown, which is not html
laurieontech pushed a commit that referenced this issue Jan 15, 2020
…former (#20398)

* fix[gatsby-source-contentful] Contentful LongText fields require gatsby-transformer-remark

As shown here: #3205 (comment)
you cannot simply do 
```{
body{
 body}
}
since the body will be raw markdown, which is not html

* Update README.md

* Update packages/gatsby-source-contentful/README.md

Co-Authored-By: Vladimir Razuvaev <[email protected]>

* Rewrite for explaining the logic and add clarity

The text might not be perfect but it clearly explains what happens. Feel free to reuse it or change it.

* typo

* mention rich text as an alternative

* chore: format

* typo and polishing

* chore: format

Co-authored-by: Vladimir Razuvaev <[email protected]>
Co-authored-by: GatsbyJS Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants