pasdo501 / gatsby-source-woocommerce

Gatsy Source Plugin for WooCommerce
34 stars 14 forks source link

GraphQL error when querying product variation images #36

Closed jack-of-blades closed 2 years ago

jack-of-blades commented 3 years ago

When querying for product variation image sourceURL or mediaItemURL the following error is presented:

There was an error in your GraphQL query:

Cannot read property 'includes' of undefined

> 184 |           image {
      |           ^
  185 |             mediaItemUrl
  186 |           }

The query works fine however when run in GraphiQL.

pasdo501 commented 3 years ago

Hi there,

Could you provide a bit more context? I haven't come across that issue before. Without knowing more about the rest of the query etc, could the issue be related to image rather than images?

jack-of-blades commented 3 years ago

Hi, @pasdo501

Here is the entire query:

    allWpVariableProduct(
      filter: {
        productCategories: {
          nodes: { elemMatch: { databaseId: { in: $categoryIds } } }
        }
      }
    ) {
      nodes {
        name
        productId
        shortDescription
        price
        regularPrice
        onSale
        averageRating
        slug
        image {
          sourceUrl
        }
        acf_product_information {
          productHoverImage {
            sourceUrl
          }
        }
        categories: productCategories {
          nodes {
            slug
            databaseId
          }
        }
        attributes {
          nodes {
            name
            variation
          }
        }
        paColours {
          nodes {
            attributeId: databaseId
          }
        }
        paSizes {
          nodes {
            attributeId: databaseId
          }
        }
        acf_product_tile_add_ons {
          squareMetresOfTilesPerBox
        }
        variations {
          nodes {
            variationId
            name
            onSale
            price
            regularPrice
            attributes {
              nodes {
                attributeId
                value
              }
            }
            image {
              mediaItemUrl
            }
            acf_product_tile_add_ons {
              squareMetresOfTilesPerBox
            }
          }
        }
      }
    }

Let me know if I need to provide more details. As mentioned, the issue only seems to occur when querying for the image url's for product variations and only on a live build. When I run this query in GraphiQL the data is retrieved perfectly.

When I remove the erroneous part the query works fine. Currently we're resorting to using a product variation's parent image for the variation.

pasdo501 commented 3 years ago

Are you using another plugin, e.g. wp-graphql? I don't believe the allWpVariableProduct data type is produced by this plugin. The types from this plugin would be, for example allWcProducts.

jack-of-blades commented 3 years ago

@pasdo501

Thanks for the response.

Yes we are using the wp-graphql plugin. I thought the problem might lie here but I'll log an issue over there.

Thanks!