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 fails to transform content #3374

Closed
mirshko opened this issue Dec 31, 2017 · 14 comments
Closed

gatsby-source-contentful fails to transform content #3374

mirshko opened this issue Dec 31, 2017 · 14 comments
Assignees

Comments

@mirshko
Copy link

mirshko commented Dec 31, 2017

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.

...

@KyleAMathews
Copy link
Contributor

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

@mirshko
Copy link
Author

mirshko commented Jan 1, 2018

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?

@KyleAMathews
Copy link
Contributor

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.

@mirshko
Copy link
Author

mirshko commented Jan 1, 2018

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.

@mirshko
Copy link
Author

mirshko commented Jan 2, 2018

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

@KyleAMathews
Copy link
Contributor

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

@mirshko
Copy link
Author

mirshko commented Jan 2, 2018

Heres the markup!

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

@mirshko
Copy link
Author

mirshko commented Jan 2, 2018

@Khaledgarbaya any thoughts?

@KyleAMathews
Copy link
Contributor

Ah, it's the same issue as this #2967 (comment)

@Khaledgarbaya
Copy link
Contributor

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

@Khaledgarbaya
Copy link
Contributor

Khaledgarbaya commented Jan 2, 2018

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

@flaviolivolsi
Copy link
Contributor

I sent a pull request for this issue

@martimarkov
Copy link
Contributor

martimarkov commented Aug 11, 2018

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?

@martimarkov
Copy link
Contributor

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. :)

@martimarkov martimarkov self-assigned this Aug 16, 2018
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

5 participants