gatsby-source-contentful is duplicating nodes in GraphQL query

Created on 2 Jul 2018  路  10Comments  路  Source: gatsbyjs/gatsby

gatsby-source-contentful

Description

Hi guys! I love Gatsby so far, but I've been running into this consistent, repeated problem with the Contentful package. I've ran the basic setup of Contentful, but when I query the items in the GraphQL it creates duplicate nodes.

Steps to reproduce

  1. yarn add gatsby-source-contentful
  2. Signup for Contentful
  3. Add plugin to gatsby-config.js with appropriate keys
  4. Run gatsby dev
  5. Go to localhost:8000/__graphql.
  6. Add query for Contentful pages. See duplicates.

See API visualized output in Discovery tool

screen shot 2018-07-01 at 11 40 03 pm

See GraphQL query output

screen shot 2018-07-01 at 11 40 12 pm

Environment

  System:
    OS: macOS High Sierra 10.13.5
    CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 9.4.0 - ~/.nvm/versions/node/v9.4.0/bin/node
    Yarn: 1.5.0 - ~/.nvm/versions/node/v9.4.0/bin/yarn
    npm: 5.7.1 - ~/.nvm/versions/node/v9.4.0/bin/npm
  Browsers:
    Chrome: 67.0.3396.99
    Firefox: 58.0.2
    Safari: 11.1.1
  npmPackages:
    gatsby: ^1.9.247 => 1.9.273 
    gatsby-image: ^1.0.54 => 1.0.54 
    gatsby-link: ^1.6.40 => 1.6.45 
    gatsby-plugin-google-analytics: ^1.0.31 => 1.0.31 
    gatsby-plugin-react-helmet: ^2.0.10 => 2.0.11 
    gatsby-plugin-sass: ^1.0.26 => 1.0.26 
    gatsby-plugin-sharp: ^1.6.48 => 1.6.48 
    gatsby-plugin-sitemap: ^1.2.25 => 1.2.25 
    gatsby-remark-copy-linked-files: ^1.5.37 => 1.5.37 
    gatsby-remark-images: ^1.5.67 => 1.5.67 
    gatsby-remark-images-contentful: ^1.0.2 => 1.0.2 
    gatsby-source-contentful: ^1.3.54 => 1.3.54 
    gatsby-source-filesystem: ^1.5.39 => 1.5.39 
    gatsby-transformer-remark: ^1.7.44 => 1.7.44 
    gatsby-transformer-sharp: ^1.6.27 => 1.6.27 
  npmGlobalPackages:
    gatsby-cli: 1.1.58

File contents (if changed)

gatsby-config.js:

    {
      resolve: `gatsby-source-contentful`,
      options: {
        spaceId: 'igrkt2k5ieiw',
        accessToken:
          'e87b1eb41df29afc2d9860d2941b1ee0a9c1a8281b9c0259bc6c865172670911'
      }
    }

package.json:

"gatsby-remark-images-contentful": "^1.0.2",

gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

Most helpful comment

I've encountered the same problem and I'm pretty sure you received double data because of your localisation settings in Contentful. Without a language key in your query Contentful will deliver all languages given. Just make sure you check the field node_locale before trashing your whole Contentful space :)

{
  "data": {
    "allContentfulVerticals": {
      "edges": [
        {
          "node": {
            "node_locale": "en-US",
            "id": "5426f6c3-03e3-5fc1-b4b2-c365d6859024",
            "title": "Health",
          }
        },
        {
          "node": {
            "node_locale": "en-US",
            "id": "ed4bf2ef-3c02-594a-9e3f-f168142e70a1",
            "title": "Education",
          }
        },
        {
          "node": {
            "node_locale": "nl",
            "id": "6b5f35fc-ff4b-59ff-9dcc-8423e8aafbe7",
            "title": "Health",
          }
        },
        {
          "node": {
            "node_locale": "nl",
            "id": "6ffd7afa-64b9-5ac6-9373-45a9eb58b32e",
            "title": "Education",
          }
        }
      ]
    }
  }
}

All 10 comments

Interesting. I'm closing because I've managed to "fix it" by creating the Contentful space by scratch. In addition, I haven't found other occurrences mentioned elsewhere. Maybe someone can reopen it if they have idea what happened.

Huh, weird issue. Haven't heard this reported before. Perhaps Contentful's API was glitching for some reason. /cc @Khaledgarbaya

Hmm weird never seen something like this before and it wasn't reported anywhere, let me know if you can reproduce it I would love to check it out

I've encountered the same problem and I'm pretty sure you received double data because of your localisation settings in Contentful. Without a language key in your query Contentful will deliver all languages given. Just make sure you check the field node_locale before trashing your whole Contentful space :)

{
  "data": {
    "allContentfulVerticals": {
      "edges": [
        {
          "node": {
            "node_locale": "en-US",
            "id": "5426f6c3-03e3-5fc1-b4b2-c365d6859024",
            "title": "Health",
          }
        },
        {
          "node": {
            "node_locale": "en-US",
            "id": "ed4bf2ef-3c02-594a-9e3f-f168142e70a1",
            "title": "Education",
          }
        },
        {
          "node": {
            "node_locale": "nl",
            "id": "6b5f35fc-ff4b-59ff-9dcc-8423e8aafbe7",
            "title": "Health",
          }
        },
        {
          "node": {
            "node_locale": "nl",
            "id": "6ffd7afa-64b9-5ac6-9373-45a9eb58b32e",
            "title": "Education",
          }
        }
      ]
    }
  }
}

Thanks @jordyvanraaij for the useful advice. Otherwise either I was going to trash that space or would be looking for something like graphql de-duplicator plugins

For filtering only a specific locale (therefore filtering out duplicates from different locales), use an expression as something like this:

query {
  allContentfulStaff(filter: {node_locale: {eq: "nl-NL"}}) {
   edges {
      node {
        name
      }
    }
  }
}

Thank you. I trashed two content models and was tearing my hair out! Why does it do that in some cases and not others? I have created several content types for different clients and that is the first time that has happened. Seems like a bug that should not happen

thanks all!

Edit
I made my own issue relating to References Many fields and circular references: https://github.com/gatsbyjs/gatsby/issues/26668

thank you so much

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timbrandin picture timbrandin  路  3Comments

3CordGuy picture 3CordGuy  路  3Comments

ferMartz picture ferMartz  路  3Comments

rossPatton picture rossPatton  路  3Comments

benstr picture benstr  路  3Comments