Js-buy-sdk: Not able to access collection metafields

Created on 25 Feb 2020  路  3Comments  路  Source: Shopify/js-buy-sdk

Bug details

Describe the bug
I expected that I'd be able to create metafields on collections and then access them via a custom Storefront API GraphQL query. Is this something I should be able to do? I created some collection metafields using a third party app and can access them via Shopify's GraphiQL app, but not via a custom Storefront API query.

To Reproduce
Steps to reproduce the behaviour:

  • Add metafields to a collection
  • Whitelist those metafields using a GraphQL mutation
  • See that you can view the collection metafields using the Shopify GraphiQL app -- using a query like this:
{
  shop {
    collectionByHandle(handle: "my-products") {
      id
      title
      metafields(first:7 ) {
        edges {
          node {
            id
            key
            value
          }
        }
      }
      products(first:10) {
        edges {
          node {
            id
            title
            collections(first: 10) {
              edges {
                node {
                  id
                  title
                }
              }
            }
          }
        }
      }
    }
  }
}
  • See that in a custom storefront API query, you'll get Error: No field of name "metafields" found on type "Collection" in schema:
export const queryCollectionByHandle = (handle) => {
  const query = ApiClient.getShopify().graphQLClient.query((root) => {
    root.add('shop', shop => {
      shop.add(
        'collectionByHandle',
        { args: { handle } },
        collection => {
          collection.add('title')
          collection.add('description')
          collection.addConnection('metafields', { args: { first: 10 } },
            field => {
              field.add('key')
              field.add('value')
            })
...

Expected behavior
I expected the collection metafields to be returned as they are in the Shopify GraphiQL app.

Environment (please complete the following information):

  • OS: Mac OS
  • Browser: Firefox
  • SDK Version v2019-10 (tested later releases also)

Additional context
Add any other context about the problem here.

Bug Report Checklist

  • [x] I have read and agree to the CODE_OF_CONDUCT.md
  • [x] I have read the CONTRIBUTING.md guidelines.
  • [x] I have provided a detailed description of the bug, including code samples, and/or network data.
  • [x] I have provided information about my development environment, including SDK version.

All 3 comments

Hi @sheelah,
this repo uses Shopify storefront API, metafields only live on these types for the storefront.

Is it possible you added metafields in GraphiQL on an Admin API instead?

@StefanSlehta I see - thanks for the info! I had added the collection metafields via a third party app which must use the admin API & was expecting them to not show in the GraphiQL app either if they weren't supported in the Storefront API.

It is a real bummer that it is not possible to access metafields on Collection resource types via the Shopify storefront API.

Are there any plans for this functionality to be added or are there any sort of workarounds for accessing this information?

Was this page helpful?
0 / 5 - 0 ratings