njosefbeck / gatsby-source-stripe

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

Cannot query product field on price object #64

Closed spikyjt closed 3 years ago

spikyjt commented 3 years ago

Prerequisites

[X] Put an X between the brackets on this line if you have done all of the following:

Describe the bug GrapghQL query for the product field as a property of a price object (allStripePrice) errors with:

Cannot query field "product" on type "Query"

This includes a suggestion that the field cannot be queried if it is optional, as Gatsby can't infer the type in the schema.

To Reproduce Steps to reproduce the behavior:

  1. Configure gatsby-source-stripe to use objects: ['Product', 'Price']
  2. Set up a page query similar to: (simplified for brevity)
    query Shop {
      allStripePrice(filter: {active: {eq: true}}) {
        edges {
          node {
            unit_amount
            product {
              id
            }
          }
        }
      }
    }
  3. Run in develop mode or build site
  4. Error is displayed

Expected behavior product field can be queried on price objects as it always present on responses from the Stripe API (expandable).

Screenshots If applicable, add screenshots to help explain your problem.

Versions (please complete the following information):

os: macOS 10.15.7 node: 14.15.5 npm: 6.14.11 gatsby: 2.32.3 gatsby-source-stripe: 3.2.1

Gatsby config:

Copy the portion of your Gatsby config for this plugin here. Do not include your secretKey.

{
  resolve: `gatsby-source-stripe`,
  options: {
    objects: ['Product', 'Price'],
    secretKey: '...',
    downloadFiles: false,
  },
}

Additional context If I run this query in the GraphiQL explorer, it works fine!

spikyjt commented 3 years ago

Additionally, I've tried this in a static query as well as a page query and neither work.

njosefbeck commented 3 years ago

@spikyjt I noticed that you mentioned that you're able to run the query successfully in the GraphiQL explorer. Is that the case? If so, that makes me think that Gatsby is getting the data just fine from the Stripe API, and there's an issue with how you're querying it in your code. Can you share a screenshot of the results you get when you do the query in the explorer as well as can you share the full query you're using in code?

Thanks!

spikyjt commented 3 years ago

@njosefbeck I'm an idiot! The problem was actually in another query on an individual product page, that hadn't been updated to use the stripe objects yet, but queried a resource called product. I got confused because I wasn't viewing that page, but of course it get's rendered at build time, so the query was still being run.

Sorry to waste your time.

njosefbeck commented 3 years ago

No worries! Glad you figured it out!