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.

[gatsby-source-contentful] odd nesting of "LongText" field types...

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
KyleAMathewscommented, Dec 14, 2017

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.

4reactions
jserraocommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use The Contentful Rich Text Field with Gatsby
There are two types of nodes available on richText , the first is called raw , the second is references , i'll come...
Read more >
100DaysOfGatsby - Paul Scanlon
I'm currently developing a demo using the Gatsby starter blog and it works ok but it doesn't implement theme-ui so i'm not sure...
Read more >
Re-open a thread - Community Water Cooler - Prismic People
Dynamic queries with gatsby-source-prismic ... Rich Text field - Nested Lists ... Prismic type not displaying type tab data in GraphQL.
Read more >
Contentful vs DatoCMS: An in-depth comparison
It is a fact that Contentful has been the forerunner of this type of ... the most peculiar features of both products, grouping...
Read more >
Graphql query array of strings - Caritas Castellaneta
GraphQL schema documents are text documents that define the types available in ... allow us to pass in arguments into query fields and...
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