gatsby-source-contentful fails to transform content

Created on 31 Dec 2017  Â·  14Comments  Â·  Source: gatsbyjs/gatsby

Description

The issue is that when importing contentful from my space we get the error Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/. However, there is no content with this name, so I'm not sure what is causing this issue.

Environment

Gatsby version: v1.9.145
Node.js version: v9.3.0
Operating System: v10.13.2 (17C88)

File contents (if changed):

gatsby-config.js:

module.exports = {
  siteMetadata: {
    title: `Gatsby Default Starter`,
  },
  plugins: [
    {
      resolve: `gatsby-source-contentful`,
      options: {
        spaceId: `...`,
        accessToken: `...`,
        host: `preview.contentful.com`
      }
    },
    `gatsby-plugin-react-helmet`
  ]
}

Actual result

Fetch Contentful data: 32571.432ms
success source and transform nodes — 37.496 s
error UNHANDLED REJECTION


  Error: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "0___name" does not.

  - Array.map

  - create-sort-field.js:19 createSortField
    [marketing-website-gatsby]/[gatsby]/dist/schema/create-sort-field.js:19:20

  - build-node-connections.js:62
    [marketing-website-gatsby]/[gatsby]/dist/schema/build-node-connections.js:62:16

  - lodash.js:537 arrayEach
    [marketing-website-gatsby]/[lodash]/lodash.js:537:11

  - lodash.js:9359 Function.forEach
    [marketing-website-gatsby]/[lodash]/lodash.js:9359:14

  - build-node-connections.js:33 module.exports
    [marketing-website-gatsby]/[gatsby]/dist/schema/build-node-connections.js:33:5

  - index.js:42 _callee$
    [marketing-website-gatsby]/[gatsby]/dist/schema/index.js:42:25


error Command failed with exit code 1.

Expected behavior

Content should be imported and transformed cleanly.

Steps to reproduce

Other less-full spaces are fine, just this space 700+ entires, 1500+ assets, aren't being imported cleanly.

...

Most helpful comment

I sent a pull request for this issue

All 14 comments

Looks like one of your fields in Contentful starts with 0 which graphql doesn't allow.

Doesn't seem to be it, I checked the Content Model manually and there is no field id that starts with 0, could it be an asset name?

Also is there any way to selectively choose which content types to retrieve?

Could you add some console.logs to the source plugin where types are being defined to find out where this one is coming from? It could be a bug and would love your help finding the source.

Here is the culprit, it came from a JSON field data that had an array of objects, the 0 was coming from the array index of the JSON field data.

contentfulContactFormSalesHiddenFieldsJsonNodeConnection [ '0___name',
  '0___dev-oid',
  '0___prod-oid',

Added a log to create-sort-field.js like below

module.exports = function createSortField(typeName, fieldNames) {
  var enumValues = {};
  fieldNames.forEach(function (field) {
    enumValues[createKey(field)] = { value: field };
  });

  console.log(typeName, fieldNames); // Find the culprit

  var SortByType = new GraphQLEnumType({
    name: `${typeName}SortByFieldsEnum`,
    values: enumValues
  });

Which fired the content types. It seems to be fixed now as that data wasn't used as it is anyways.

@KyleAMathews would this be a bug with my JSON structure or the way the Gatsby Contentful Source is parsing in the data?

Neither. Sorry for the slow reply and thanks for the investigation! What you found I think is a core bug. Will need time to investigate it. If you or someone wants to do more investigating that'd be great!

If you still have it, could you paste the json data you had (if it's sensitive, swap it out for other data -- it's the structure that matters).

Heres the markup!

[
  {
    "name": "field-name",
    "dev-oid": "1234567890",
    "prod-oid": "4567891011"
  }
]

@Khaledgarbaya any thoughts?

Ah, it's the same issue as this https://github.com/gatsbyjs/gatsby/pull/2967#issuecomment-351891183

hey, @mirshko we can pair on this and try to investigate the problem.

I think maybe the problem is in the spread of the content here but not sure. BEcause when you spread an array into an object the key will be the index of the array which is 0 which is not allowed by graphql.

I will take a look at it tomorrow @mirshko ping me when you are in the office

I sent a pull request for this issue

I have the same issue using the next version of the plugin.

I have a JSON object field containing:
['vis 1', 'vis 2', 'vis3']

I agree with @Khaledgarbaya that the spread causes the problem.

Is going to be a problem if we check if the content parameter is a string and just not expand it?

I'm closing this issue. If the problem happens again feel free to open a new issue and link this one or reopen this one and ping me. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

theduke picture theduke  Â·  3Comments

timbrandin picture timbrandin  Â·  3Comments

kalinchernev picture kalinchernev  Â·  3Comments

benstr picture benstr  Â·  3Comments

signalwerk picture signalwerk  Â·  3Comments