angeloashmore / gatsby-source-shopify

Source plugin for pulling product data into Gatsby from a Shopify store
36 stars 19 forks source link

Gatsby Build Error #8

Closed gil-- closed 6 years ago

gil-- commented 6 years ago

Having issues getting gatsby to build without errors w/ v1.0.0 or v1.0.1

For reference, v0.1.9 works fine for me.

Just tried to add this source plugin to a fresh gatsby new site but having the following error on build: gatsby develop:

gatsby-source-shopify/gatsbyjs starting to fetch data from Shopify
⡀ source and transform nodes
error an error occured while sourcing data
error Plugin gatsby-source-shopify returned an error

  TypeError: Cannot convert undefined or null to object

  - Function.keys

  - index.js:59 prefixConflictingKeys
    [PWA]/[gatsby-node-helpers]/dist/index.js:59:12

  - index.js:82
    [PWA]/[gatsby-node-helpers]/dist/index.js:82:21

  - gatsby-node.js:386
    [PWA]/[gatsby-source-shopify]/gatsby-node.js:386:48

  - lodash.min.js:49
    [PWA]/[lodash]/lodash.min.js:49:114

  - Array.forEach

  - gatsby-node.js:381 _callee10$
    [PWA]/[gatsby-source-shopify]/gatsby-node.js:381:46

  - next_tick.js:131 _combinedTickCallback
    internal/process/next_tick.js:131:7

  - next_tick.js:180 process._tickCallback
    internal/process/next_tick.js:180:9

⢀ source and transform nodes
gatsby-source-shopify/gatsbyjs fetched and processed articles: 249.258ms

gatsby-source-shopify/gatsbyjs fetched and processed blogs: 231.650ms

gatsby-source-shopify/gatsbyjs fetched and processed collections: 230.297ms
⠄ source and transform nodes
gatsby-source-shopify/gatsbyjs fetched and processed products: 3308.861ms
⠂ source and transform nodes

gatsby-config.js

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-source-shopify',
      options: {
        shopName: 'gatsbyjs',
        accessToken: 'redacted',
        verbose: true,
      },
    },
  ]
}

And here are the Shopify Private app settings:

screen shot 2018-06-05 at 9 49 49 pm

And verified the token and store url are correct via graphiql:

screen shot 2018-06-05 at 9 55 52 pm

It then seems to hang on 'source and transform nodes' unless I should be waiting 15+ minutes? ...

angeloashmore commented 6 years ago

The plugin should be very quick to fetch and process data. Using my small test shop, it took about 10 seconds.

I think this may be a result of not having any store policies since every other type of node processes successfully. Can you confirm you do not have a Return Policy, Terms & Conditions, or Privacy Policy in your store?

gil-- commented 6 years ago

It's a brand new store with just some Shopify sample data so no policies were setup yet:

screen shot 2018-06-05 at 11 09 34 pm
gil-- commented 6 years ago

I generated sample data for each 3 and it now works on v1.0.1. I assume this is a bug? Otherwise we may want to document on the readme that these three fields must be generated in order to successfully use the plugin.

angeloashmore commented 6 years ago

Ok, thanks, definitely a bug. If you have no products, this error will not show up since it iterates over an array. If the array is empty, nothing is created.

Shop policies, however, are done more directly and tries to make a node for each type of policy. If the policy is not set, the data from the API is empty, i.e. null, thus the error.

We'll have to add a check here: https://github.com/angeloashmore/gatsby-source-shopify/blob/be1880cdb8de4155bd67ef4d82c6c9751877ad5b/src/gatsby-node.js#L117-L123

type is defined in the function, since it is hardcoded, but policy could be null if the policy doesn't exist.

For reference, this is the GraphQL query used to get the policies: https://github.com/angeloashmore/gatsby-source-shopify/blob/be1880cdb8de4155bd67ef4d82c6c9751877ad5b/src/queries.js#L176-L199

coreyward commented 6 years ago

Getting bit by this as well. Why are you fetching my store policies by default anyways? As a source plugin shouldn't you just be providing me the connection to fetch what I'd like to fetch? Seems like default policy page generation would be something in a gatsby-plugin-shopify or similar, no?

angeloashmore commented 6 years ago

@coreyward Gatsby source plugins generally fetch all available data at compile time and make the data available via the GraphQL interface. So in order to make policy data available to query, the plugin needs to fetch it and create nodes containing the data.

Note that this means the data is available for you to query where ever you see fit. It does not create any pages for you.

In the future, gatsby-source-graphql will hopefully deprecate this source plugin and allow you to use the Shopify GraphQL API directly, which sounds more inline with that you're expecting the plugin to do.

Thanks for bumping this up. I'll push out a fix for this issue. 👍

angeloashmore commented 6 years ago

Just published v1.1.1 to NPM. Could you give it a try and see if it fixes the issue? Thanks!

coreyward commented 6 years ago

@angeloashmore I was able to pull down 1.1.1 and get past the error. Thank you!

angeloashmore commented 6 years ago

Nice, thanks for testing it out! I'll close this issue, but let me know if you run into other issues.