Gatsby: `gatsby-source-contentful` returns a string with a single whitespace character (`" "`) for empty "long text" fields

Created on 13 Jan 2020  路  5Comments  路  Source: gatsbyjs/gatsby

Description

gatsby-source-contentful returns a string with a single whitespace character (" ") for empty "long text" fields, rather than an empty string (""), or null like other fields. Seems to be fine and returns null for empty "short text" fields.

It looks like the problem stems is on this line, though not sure if this space is there for a reason or not 馃 - haven't had time to investigate that thoroughly yet.

image

Steps to reproduce

  1. Create new Gatsby project
  2. Install and configure gatsby-source-contentful
  3. Create an entry in Contentful with a "long text" field
  4. Leave "long text" field empty
  5. Run Gatsby site and query the entry/field in GraphiQL editor

Expected result

"description": null

is returned

Actual result

"description": {
  "description": " "
}

is returned

Environment

Run gatsby info --clipboard in your project directory and paste the output here.


  System:
    OS: macOS 10.15.2
    CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.16.2 - /var/folders/c6/zn3s5lkd09xf78n8tcylhyg00000gn/T/yarn--1578935140235-0.22327134046771624/node
    Yarn: 1.21.1 - /var/folders/c6/zn3s5lkd09xf78n8tcylhyg00000gn/T/yarn--1578935140235-0.22327134046771624/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 79.0.3945.117
    Firefox: 72.0.1
    Safari: 13.0.4
  npmPackages:
    gatsby: 2.16.3 => 2.16.3 
    gatsby-image: 2.2.29 => 2.2.29 
    gatsby-plugin-react-helmet: 3.1.11 => 3.1.11 
    gatsby-plugin-segment-js: 3.0.1 => 3.0.1 
    gatsby-plugin-styled-components: 3.1.14 => 3.1.14 
    gatsby-plugin-typescript: 2.1.12 => 2.1.12 
    gatsby-source-contentful: 2.1.47 => 2.1.47 
bug

Most helpful comment

Awesome! I can do that 馃檶

All 5 comments

@pieh Do you know why we have this? Looks pretty weird

Hiya!

This issue has gone quiet. Spooky quiet. 馃懟

We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 馃挭馃挏

So I tracked this down to https://github.com/gatsbyjs/gatsby/pull/1264/files#diff-02e206f053c7858936f4ee6d70bdecf0R68 (so it's been like that for a long time and wasn't changed since). As to why - this is lost in translation (at that point in time it was mostly Kyle working on code, so pull requests were not very detailed in explanations).

I think it should be safe to make it at least empty string instead of single whitespace (it should still be inferred as a string, so no regressions on that part). I suspect that schema inference back then had a lot more edge cases than we have now and we might have skip falsy values back then (which empty string is) and this was way to ensure that this is picked up as a string (?)

So I think we will accept PR that will change " " (single whitespace) to "" (empty string) fallback in https://github.com/gatsbyjs/gatsby/blob/1e2813ceb742a7ecdfb564084e0889cd4b3d748f/packages/gatsby-source-contentful/src/normalize.js#L224

If anyone is interested in working on that

Awesome! I can do that 馃檶

Was this page helpful?
0 / 5 - 0 ratings