Shopify / theme-extension-getting-started

A theme app extension boilerplate that highlights the basic structure and features that are available to developers who want to integrate their apps with Shopify Online Stores.
https://shopify.dev/apps/online-store/theme-app-extensions/getting-started
MIT License
105 stars 45 forks source link

add conditional app block #12

Closed veken1199 closed 2 years ago

veken1199 commented 2 years ago

We are introducing a sample app block that uses available_if property. This block is conditionally enabled on storefronts only when the referenced app-owned metafield has a value of true.

A partner can create an app-owned metafield using metafieldSet mutation of the 2022-04 Admin API or above.

Example mutation:

mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
  metafieldsSet(metafields: $metafields) {
    metafields {
      # Metafield fields
    }
    userErrors {
      field
      message
    }
  }
}

Mutation Variables:

{
  "metafields": {
    "key": "feature1",
    "namespace": "sample_app",
    "ownerId": "<App installation ID>",
    "type": "boolean",
    "value": "true"
  }
}

In order to get app installation ID, use the following Admin API GraphQL query:

{
  appInstallation {
        id
  }
}
veken1199 commented 2 years ago

/shipit