njosefbeck / gatsby-source-stripe

Gatsby source plugin for building websites using Stripe as a data source
74 stars 17 forks source link

Cannot query field "allStripeSku" on type "Query" even with a valid secret key #45

Closed develo-pera closed 4 years ago

develo-pera commented 4 years ago

Prerequisites

Description

I read in one closed issue in the repo of the tutorial I followed that this can happen because of the wrong Stripe secret key, but I don't think that's the reason in my case. I've added the right secret key exactly as described here: https://www.gatsbyjs.org/tutorial/ecommerce-tutorial/, I've even hardcoded it and it still doesn't work, I rolled the secret key and tried with the new one and I have the same problem. I even created a new account and still the same.

Steps to Reproduce

  1. Just add gatsby-source-stripe to your project
  2. Add what's needed to be added to the gatsby-config.js
  3. Try example query allStripeSku

Expected behavior: To have that query

Actual behavior: Graphql error Unknown field 'allStripeSku' on type 'Query'.

Reproduces how often: Every time

Versions

os: macOs Mojave 10.14.5 node: 10.16.0 npm: 6.9.0 gatsby: 2.17.11 gatsby-source-stripe: 3.0.4

Additional Information

Here's the full log. Maybe this line can tell something warn The gatsby-source-stripe plugin has generated no Gatsby nodes. Do you need it?

> gatsby-starter-default@0.1.0 develop /Users/developera/moje/ecommerce-gatsby-tutorial
> gatsby develop

success open and validate gatsby-configs - 0.040s
success load plugins - 2.058s
success onPreInit - 0.006s
success initialize cache - 0.029s
success copy gatsby files - 0.213s
success onPreBootstrap - 0.020s
warn The gatsby-source-stripe plugin has generated no Gatsby nodes. Do you need it?
success source and transform nodes - 0.733s
success building schema - 0.382s
success createPages - 0.002s
success createPagesStatefully - 0.052s
success onPreExtractQueries - 0.011s
success update schema - 0.023s

 ERROR #85907  GRAPHQL

There was an error in your GraphQL query:

- Unknown field 'allStripeSku' on type 'Query'.

File: src/components/Skus.js

failed extract queries from components - 0.343s
success write out requires - 0.033s
success write out redirect data - 0.002s
success Build manifest and related icons - 0.125s
success onPostBootstrap - 0.148s
⠀
info bootstrap finished - 14.662 s
⠀
success run queries - 0.055s - 5/5 91.65/s

 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

/Users/developera/moje/ecommerce-gatsby-tutorial/src/components/Skus.js
  8:9  error  Cannot query field "allStripeSku" on type "Query". Did you mean "allSite"?  graphql/template-strings

✖ 1 problem (1 error, 0 warnings)

File: src/components/Skus.js

failed Building development bundle - 6.482s

————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
5 pages                                                                                   Failed                                                                                  gatsby-starter-default
njosefbeck commented 4 years ago

Hi Petar! Thanks for reaching out. Hopefully I can help! Two things:

develo-pera commented 4 years ago

@njosefbeck thanks for the quick reply. Yes, the problem was that I didn't have products with SKUs in Stripe :( As soon as I added them everything was fine, so I'm going to close this issue.

What do you think about adding that information to the README.md?

njosefbeck commented 4 years ago

I’m glad that resolved the issue! And yeah, adding this to the README seems like a good idea. If you want to do that and create a PR that’d be great! Otherwise I’ll get to it in a week or so. Thanks again! :)

Sent from my iPhone

On Nov 20, 2019, at 7:37 AM, Petar Popovic notifications@github.com wrote:

 @njosefbeck thanks for the quick reply. Yes, the problem was that I didn't have products with SKUs in Stripe :( As soon as I added them everything was fine, so I'm going to close this issue.

What do you think about adding that information to the README.md?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

develo-pera commented 4 years ago

Thanks @njosefbeck, I just opened a PR request #46 :)

D0m3- commented 4 years ago

@njosefbeck it would be nice to create the nodes even if there is not sku or no product. So the site can build fine

njosefbeck commented 4 years ago

@D0m3- Hmm, my first thought is: why should nodes be created if there are no products or skus to create nodes from? If you have no products or skus, then remove them from the object array for this plugin in your gatsby config. When you do have products / skus, add it back in.

Maybe I'm not considering your use case properly, so more details would probably help!

D0m3- commented 4 years ago

I have made some research and actually it seems like it's more a general Gatsby issue. The use case is when you don't have any product then this error pops up at build time. It's a valid use case that a site doesn't have any product. The easiest workaround is to create a dummy product, to make sure the api returns something, but filter it out in your queries. You can also use createTypes like that:

actions.createTypes(
      `type StripeProduct implements Node { 
      id: ID!, 
      active: Boolean, 
      shippable: Boolean, 
      name: String, 
      created: Int, 
      metadata:Metadata, 
      images: [String], 
      description: String 
    }
`)

But you need to define all the fields that you are using and when you actually have products you might have conflicts. See my workaround there

njosefbeck commented 4 years ago

Thanks for your response! After thinking about this for a day or so I had a couple of follow up thoughts:

I'm still not convinced that we need to make any updates to the plugin, but happy to discuss further. Thanks!

rynoV commented 4 years ago

Thanks for your response! After thinking about this for a day or so I had a couple of follow up thoughts:

* If you're making an online store, you'll realistically have at least one product in Stripe, and thus when you query for products, you'll get something back.

* If you're just testing out functionality and/or want a dummy product, you can also create one easily in the Stripe dashboard, that could be filtered out when querying. This would prevent you from having to do the above code-based workaround.

I'm still not convinced that we need to make any updates to the plugin, but happy to discuss further. Thanks!

I would like nodes to be created even if there is no data available in Stripe so that the build completes, and then I can handle the case of lacking data in my code. For my use case we have a shop that will usually only have a few items in it at a time and sometimes there may not be any items. Additionally, the shop is only one part of the website, but as it is right now if the shop doesn't have any products the entire website will fail to build. Ideally the shop would be able to handle this case on it's own without affecting the rest of the site.

njosefbeck commented 4 years ago

Hello!

If someone in the community wants to attempt to tackle this issue, that works for me. I don't have the bandwidth at the moment. This also still might be a limitation of Gatby's?

Also, as stated above, you can still create a dummy product in Stripe and then filter it out when doing your graphql queries, to avoid any issues around building when you don't have any real products in your shop.

Apologies for not being able to dig into this further at the moment, but welcome further discussion / PRs!

brxck commented 4 years ago

I am also lacking bandwidth but I just came across a potential solution and thought of this issue.

Usually Gatsby infers GraphQL schema from the data. Without data Gatsby cannot add to the schema, and you can't query for something absent from the schema. Thus Cannot query...

Types can be created explicitly to work around this, see: Handle empty results in a Gatsby source plug-in & Customizing the GraphQL Schema

My understanding is that we would have to create types for every Stripe object (and all their attributes) in the case that there is no data to infer types from. stripe/openapi could be used for this purpose.