{"id":17325,"date":"0202-01-16T18:52:33","date_gmt":"0202-01-16T18:52:33","guid":{"rendered":"https:\/\/ecommerce.folio3.com\/blog\/?p=17325"},"modified":"2026-01-16T17:35:02","modified_gmt":"2026-01-16T17:35:02","slug":"shopify-graphql-best-practices","status":"publish","type":"post","link":"https:\/\/ecommerce.folio3.com\/blog\/shopify-graphql-best-practices\/","title":{"rendered":"Shopify GraphQL Metafields Guide Using the GraphQL Admin API"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Managing custom data in Shopify often means wrestling with limited fields and inflexible data structures. Shopify GraphQL metafields solve this by letting you store, query, and update custom attributes across products, variants, orders, and customers using a unified API approach.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This guide walks you through working with Shopify GraphQL metafields using the GraphQL Admin API. You&#8217;ll learn how to query existing metafields, create new ones with proper mutations, update values efficiently, and implement best practices that prevent common data integrity issues.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Summary<\/span><\/h2>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Understanding GraphQL Fundamentals<\/b><span style=\"font-weight: 400;\">: How the Shopify GraphQL API differs from REST and why it matters for metafield management<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Metafield Structure &amp; Types<\/b><span style=\"font-weight: 400;\">: Core metafield components including namespaces, keys, types, and ownership models<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Query Implementation<\/b><span style=\"font-weight: 400;\">: Practical examples for retrieving metafields across products, variants, collections, and customers<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Mutation Operations<\/b><span style=\"font-weight: 400;\">: Step-by-step instructions for creating, updating, and deleting metafields through the GraphQL Admin API<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Advanced Techniques<\/b><span style=\"font-weight: 400;\">: Batch operations, error handling, and performance optimization strategies<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Real-World Applications<\/b><span style=\"font-weight: 400;\">: Industry-specific use cases and integration patterns for scalable implementations<\/span><\/li>\n<\/ul>\n<h2><span style=\"font-weight: 400;\">What Is the Shopify GraphQL Admin API?<\/span><\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/ecommerce.folio3.com\/blog\/wp-content\/uploads\/2023\/03\/Climbing-the-Shopify-Ladder_-Empower-Your-eCommerce-with-GraphQL-Best-Practices.jpg\" alt=\"Climbing the Shopify Ladder_ Empower Your eCommerce with GraphQL Best Practices\" \/><\/p>\n<p><span style=\"font-weight: 400;\">The Shopify GraphQL Admin API represents a modern approach to store management, allowing you to request exactly the data you need in a single query. Unlike REST APIs that return complete resource objects, GraphQL lets you specify which fields to retrieve.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">How GraphQL Differs From REST<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">REST APIs require multiple endpoints for related data. Fetching a product with metafields, variants, and images might need three separate requests. The Shopify GraphQL API consolidates this into one query, reducing network overhead and improving response times.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">GraphQL uses a strongly-typed schema. Every field has a defined type, making it easier to validate queries before execution. This structure prevents common errors and provides clear documentation through introspection.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Core Benefits for Metafield Management<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Working with Shopify GraphQL metafields offers several advantages:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Precision<\/b><span style=\"font-weight: 400;\">: Request only the metafield namespaces and keys you need, avoiding unnecessary data transfer.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Efficiency<\/b><span style=\"font-weight: 400;\">: Retrieve metafields alongside parent resources in single queries, eliminating the N+1 query problem common in REST implementations.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Flexibility<\/b><span style=\"font-weight: 400;\">: The<\/span> <span style=\"font-weight: 400;\">Shopify GraphQL <a href=\"https:\/\/ecommerce.folio3.com\/blog\/shopify-storefront-mcp-how-ai-shopping-assistants-convert-more-customers\/\">Storefront<\/a> API<\/span><span style=\"font-weight: 400;\"> complements the Admin API, letting you expose specific metafields to your storefront without security concerns.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Authentication and Access Requirements<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The Shopify Admin GraphQL API requires an access token with appropriate scopes. For metafield operations, you&#8217;ll need:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">read_metaobjects<\/span><span style=\"font-weight: 400;\"> for querying metafields<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">write_metaobjects<\/span><span style=\"font-weight: 400;\"> for creating or modifying metafields<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\"><a href=\"https:\/\/ecommerce.folio3.com\/blog\/shopify-custom-app-vs-private-app\/\">Private apps and custom apps<\/a> can generate these tokens through your Shopify admin panel. Each request includes this token in the <\/span><span style=\"font-weight: 400;\">X-Shopify-Access-Token<\/span><span style=\"font-weight: 400;\"> header.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Understanding Shopify Metafield Architecture<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Metafields extend Shopify&#8217;s data model by attaching custom information to resources like products, customers, orders, and collections. Each metafield consists of four core components that determine how data is stored and retrieved.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Namespace and Key Structure<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Namespaces organize metafields into logical groups, preventing naming conflicts when multiple apps or integrations add custom data. A namespace might be <\/span><span style=\"font-weight: 400;\">specifications<\/span><span style=\"font-weight: 400;\"> for technical details or <\/span><span style=\"font-weight: 400;\">marketing<\/span><span style=\"font-weight: 400;\"> for promotional content.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Keys identify specific metafields within a namespace. The combination of namespace and key creates a unique identifier. For example, <\/span><span style=\"font-weight: 400;\">specifications.material<\/span><span style=\"font-weight: 400;\"> is distinct from <\/span><span style=\"font-weight: 400;\">care.material<\/span><span style=\"font-weight: 400;\">, even though both use the same key.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Component<\/b><\/td>\n<td><b>Purpose<\/b><\/td>\n<td><b>Example<\/b><\/td>\n<td><b>Requirements<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Namespace<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Groups related metafields<\/span><\/td>\n<td><span style=\"font-weight: 400;\">product_specs<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3-20 alphanumeric characters, underscores allowed<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Key<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Identifies specific field<\/span><\/td>\n<td><span style=\"font-weight: 400;\">fabric_weight<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3-30 alphanumeric characters, underscores allowed<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Value<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Stores actual data<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8220;8.5 oz&#8221;<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Varies by type, max 65,535 characters for single_line_text_field<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Type<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Defines data structure<\/span><\/td>\n<td><span style=\"font-weight: 400;\">single_line_text_field<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Must match<\/span><a href=\"https:\/\/ecommerce.folio3.com\/blog\/shopify-metafields\/\"> <span style=\"font-weight: 400;\">Shopify&#8217;s supported types<\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span style=\"font-weight: 400;\">Metafield Value Types<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The Shopify GraphQL API supports multiple value types, each suited for different data structures:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Single Line Text Field<\/b><span style=\"font-weight: 400;\">: Simple strings for short content like SKUs or model numbers. Most common for basic customizations.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Multi-Line Text Field<\/b><span style=\"font-weight: 400;\">: Longer text content including formatting. Ideal for descriptions, care instructions, or technical documentation.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Number (Integer\/Decimal)<\/b><span style=\"font-weight: 400;\">: Numeric values for quantities, measurements, or calculations. Use integers for counts and decimals for precise measurements.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>JSON<\/b><span style=\"font-weight: 400;\">: Complex nested data structures. Useful when storing arrays, objects, or structured datasets that need programmatic parsing.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Boolean<\/b><span style=\"font-weight: 400;\">: True\/false values for feature flags or binary attributes like &#8220;is_featured&#8221; or &#8220;requires_shipping_insurance&#8221;.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Date\/Date Time<\/b><span style=\"font-weight: 400;\">: Temporal data for expiration dates, release schedules, or time-sensitive information.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Owner Resources and Relationships<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Metafields attach to specific Shopify resources called owners. Understanding ownership is crucial for querying and managing custom data effectively.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Products own metafields at both product and variant levels. Product-level metafields apply to all variants, while variant-specific metafields override or supplement product data.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Collections, customers, orders, and even the shop itself can own metafields. The Shopify GraphQL Admin API requires specifying the owner type and ID when creating or updating metafields.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Metafield Definitions and Validation<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Metafield definitions establish schema-level rules for custom data. Creating a definition before adding metafields enables validation, default values, and automatic input generation in the Shopify admin.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Definitions specify the namespace, key, type, and validation rules. Once defined, all metafields using that namespace-key combination must conform to the specified type.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The GraphQL Shopify API validates metafield values against definitions automatically. This prevents data corruption and ensures consistency across your store&#8217;s custom data.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Setting Up Your GraphQL Environment<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Before executing Shopify GraphQL queries, you need the proper development environment and authentication. This setup applies whether you&#8217;re building a custom app, private integration, or testing queries manually.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Using the Shopify GraphQL Explorer<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The Shopify GraphQL Explorer provides an interactive interface for testing queries without writing code. Access it through your Shopify admin under Apps &gt; Develop apps &gt; [Your App] &gt; API credentials.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The explorer includes:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Auto-complete for field names and types<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Real-time syntax validation<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Query history for revisiting previous requests<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Documentation browser showing all available fields and mutations<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">This tool is essential for prototyping queries before implementing them in your application. It authenticates automatically using your app&#8217;s credentials.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Authentication Headers and Endpoints<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Production implementations require proper authentication headers. The Shopify GraphQL API endpoint follows this format:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">https:\/\/{shop-name}.myshopify.com\/admin\/api\/2024-01\/graphql.json<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Replace <\/span><span style=\"font-weight: 400;\">{shop-name}<\/span><span style=\"font-weight: 400;\"> with your store&#8217;s subdomain and use the current API version. Each request must include:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">X-Shopify-Access-Token: {your-access-token}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Content-Type: application\/json<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The access token comes from your app installation or private app credentials. Store this securely and never expose it in client-side code.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Rate Limits and Best Practices<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The Shopify Admin GraphQL API implements bucket-based rate limiting, different from REST&#8217;s call-counting approach. Each query consumes points based on complexity, not just the number of requests.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Cost Calculation<\/b><span style=\"font-weight: 400;\">: Simple field requests cost 1 point, while connection fields with pagination cost more. The <\/span><span style=\"font-weight: 400;\">cost<\/span><span style=\"font-weight: 400;\"> field in query responses shows your consumption.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Throttling Strategy<\/b><span style=\"font-weight: 400;\">: Monitor the <\/span><span style=\"font-weight: 400;\">throttleStatus<\/span><span style=\"font-weight: 400;\"> object returned with each response. It includes <\/span><span style=\"font-weight: 400;\">maximumAvailable<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">currentlyAvailable<\/span><span style=\"font-weight: 400;\">, and <\/span><span style=\"font-weight: 400;\">restoreRate<\/span><span style=\"font-weight: 400;\"> values.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Batch Operations<\/b><span style=\"font-weight: 400;\">: Group related operations into single queries when possible. Creating multiple metafields in one mutation is more efficient than separate requests.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">The default bucket size is 1000 points, restoring at 50 points per second. Design your integration to stay well below these limits, especially during bulk operations.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Testing Connections<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Verify your setup with a simple query before diving into metafield operations:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0shop {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">name<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">email<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A successful response confirms your authentication and endpoint configuration. This basic test helps isolate connection issues from query-specific problems.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Querying Shopify GraphQL Metafields<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Retrieving metafields through the Shopify GraphQL API requires understanding query structure and field selection. The following examples demonstrate practical patterns for common scenarios.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Basic Metafield Query Structure<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">A simple product query with metafields looks like this:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0product(<\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">title<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafield(<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;specifications&#8221;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;material&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This query fetches a single metafield by namespace and key. The <\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\"> field contains the stored data, while <\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\"> indicates the data structure.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Retrieving Multiple Metafields<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">For multiple metafields on a single resource, use the <\/span><span style=\"font-weight: 400;\">metafields<\/span><span style=\"font-weight: 400;\"> connection with pagination:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0product(<\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">title<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafields(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">10<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;specifications&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The <\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\"> argument limits results, while the <\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\"> filter targets specific metafield groups. This pattern works across all owner types in the GraphQL Shopify implementation.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Querying Metafields Across Products<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Bulk queries retrieve metafields for multiple products efficiently:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0products(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">50<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">title<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafield(<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;marketing&#8221;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;highlight&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0variants(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafield(<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;specifications&#8221;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;size&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This single query fetches products, their marketing highlights, and variant-specific size information. Nested connections let you traverse relationships without additional requests.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Advanced Query Patterns<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Complex scenarios often require combining filters, sorting, and conditional logic:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0products(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">25<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">query<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;tag:premium&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">title<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafields(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">20<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">createdAt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">updatedAt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The <\/span><span style=\"font-weight: 400;\">query<\/span><span style=\"font-weight: 400;\"> parameter filters products before retrieving metafields, reducing unnecessary data transfer. Include timestamp fields when you need to track data freshness or changes.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Working With Variant Metafields<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Product variants support independent metafields, useful for size-specific details or variant-level customizations:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0productVariant(<\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/ProductVariant\/42875641651374&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">title<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafield(<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;inventory&#8221;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;supplier_code&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Variant metafields supplement or override product-level data. When both exist, variant metafields take precedence in most storefront implementations.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Filtering and Pagination Strategies<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Large metafield collections require pagination to avoid timeouts:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0product(<\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafields(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">50<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">after<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;eyJsYXN0X2lkIjo4OTU&#8230;&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pageInfo {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">hasNextPage<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">endCursor<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The <\/span><span style=\"font-weight: 400;\">after<\/span><span style=\"font-weight: 400;\"> argument uses the <\/span><span style=\"font-weight: 400;\">endCursor<\/span><span style=\"font-weight: 400;\"> from previous responses to fetch subsequent pages. Check <\/span><span style=\"font-weight: 400;\">hasNextPage<\/span><span style=\"font-weight: 400;\"> to determine when you&#8217;ve retrieved all metafields.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Query Pattern<\/b><\/td>\n<td><b>Use Case<\/b><\/td>\n<td><b>Performance Impact<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Single metafield<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Targeted data retrieval<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Minimal &#8211; 1-2 points<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Metafields connection<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Full namespace exploration<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Moderate &#8211; scales with count<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Nested product + metafields<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Bulk data export<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Higher &#8211; depends on depth<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Filtered product queries<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Conditional metafield access<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Variable &#8211; filter efficiency matters<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span style=\"font-weight: 400;\">Creating and Updating Metafields With Mutations<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Mutations modify data in the Shopify GraphQL API, including creating, updating, and deleting metafields. Understanding mutation structure and error handling is essential for reliable implementations.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Creating New Metafields<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The <\/span><span style=\"font-weight: 400;\">metafieldsSet<\/span><span style=\"font-weight: 400;\"> mutation handles metafield creation and updates:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">CreateProductMetafield<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metafieldsSet(<\/span><span style=\"font-weight: 400;\">metafields<\/span><span style=\"font-weight: 400;\">: [<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">ownerId<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;specifications&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;care_instructions&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;Machine wash cold, tumble dry low&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;single_line_text_field&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0]) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafields {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The mutation returns created metafields and any validation errors. Always check <\/span><span style=\"font-weight: 400;\">userErrors<\/span><span style=\"font-weight: 400;\"> before assuming success.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Updating Existing Metafields<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Updates use the same <\/span><span style=\"font-weight: 400;\">metafieldsSet<\/span><span style=\"font-weight: 400;\"> mutation. Include the metafield ID or let Shopify match by owner, namespace, and key:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">UpdateMetafield<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metafieldsSet(<\/span><span style=\"font-weight: 400;\">metafields<\/span><span style=\"font-weight: 400;\">: [<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">ownerId<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;specifications&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;care_instructions&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;Machine wash cold, hang dry&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;single_line_text_field&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0]) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafields {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">updatedAt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Shopify updates the existing metafield when owner, namespace, and key match. Include <\/span><span style=\"font-weight: 400;\">updatedAt<\/span><span style=\"font-weight: 400;\"> in the response to verify the change.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Batch Metafield Operations<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Creating multiple metafields in one mutation improves efficiency:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">BatchCreateMetafields<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metafieldsSet(<\/span><span style=\"font-weight: 400;\">metafields<\/span><span style=\"font-weight: 400;\">: [<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">ownerId<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;specifications&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;material&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;100% Cotton&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;single_line_text_field&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0},<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">ownerId<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;specifications&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;weight&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;8.5&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;number_decimal&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0},<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">ownerId<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;marketing&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;featured&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;true&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;boolean&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0]) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafields {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The Shopify GraphQL Admin API processes these atomically. If one fails validation, check <\/span><span style=\"font-weight: 400;\">userErrors<\/span><span style=\"font-weight: 400;\"> to identify which metafield caused the issue.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Working With Complex Value Types<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">JSON metafields store structured data:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">CreateJsonMetafield<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metafieldsSet(<\/span><span style=\"font-weight: 400;\">metafields<\/span><span style=\"font-weight: 400;\">: [<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">ownerId<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;technical&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;dimensions&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;{\\&#8221;length\\&#8221;: 24, \\&#8221;width\\&#8221;: 18, \\&#8221;height\\&#8221;: 6, \\&#8221;unit\\&#8221;: \\&#8221;inches\\&#8221;}&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;json&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0]) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafields {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Stringify JSON objects before passing them as values. The GraphQL Shopify implementation validates JSON structure automatically.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Deleting Metafields<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Remove metafields using the <\/span><span style=\"font-weight: 400;\">metafieldDelete<\/span><span style=\"font-weight: 400;\"> mutation:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">DeleteMetafield<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metafieldDelete(<\/span><span style=\"font-weight: 400;\">input<\/span><span style=\"font-weight: 400;\">: {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Metafield\/23847592837465&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">deletedId<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Deletion requires the metafield&#8217;s global ID. Query the metafield first if you only have namespace and key.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Error Handling and Validation<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Every mutation response includes a <\/span><span style=\"font-weight: 400;\">userErrors<\/span><span style=\"font-weight: 400;\"> array. Common errors include:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Type Mismatch<\/b><span style=\"font-weight: 400;\">: Providing a string value for a number type field\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Invalid Namespace\/Key<\/b><span style=\"font-weight: 400;\">: Using characters outside allowed ranges\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Missing Required Fields<\/b><span style=\"font-weight: 400;\">: Omitting owner ID or type specification\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Permission Issues<\/b><span style=\"font-weight: 400;\">: Insufficient API scopes for the operation<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Implement retry logic for transient failures but log validation errors for investigation:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">javascript<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> response <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">await<\/span><span style=\"font-weight: 400;\"> shopify.<\/span><span style=\"font-weight: 400;\">graphql<\/span><span style=\"font-weight: 400;\">(mutation);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (response.userErrors <\/span><span style=\"font-weight: 400;\">&amp;&amp;<\/span><span style=\"font-weight: 400;\"> response.userErrors.length <\/span><span style=\"font-weight: 400;\">&gt;<\/span> <span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">console<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">error<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;Metafield errors:&#8217;<\/span><span style=\"font-weight: 400;\">, response.userErrors);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><i><span style=\"font-weight: 400;\">\/\/ Handle appropriately &#8211; don&#8217;t retry validation errors<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Advanced Metafield Techniques<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Beyond basic CRUD operations, the Shopify GraphQL API supports sophisticated patterns for managing metafields at scale. These techniques improve performance, maintainability, and code quality.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Creating Metafield Definitions<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Metafield definitions establish schemas that validate data and enable admin UI customization:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">CreateMetafieldDefinition<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metafieldDefinitionCreate(<\/span><span style=\"font-weight: 400;\">definition<\/span><span style=\"font-weight: 400;\">: {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">name<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;Product Warranty Period&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;product_info&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;warranty_months&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;number_integer&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">description<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;Warranty coverage in months&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">ownerType<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">PRODUCT<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">validations<\/span><span style=\"font-weight: 400;\">: [<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">name<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;min&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;0&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">name<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;max&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;120&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0createdDefinition {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">name<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Definitions support validation rules, defaults, and access controls. Once created, all metafields using that namespace-key must conform.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Implementing Access Control<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Control metafield visibility using definition access settings:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">UpdateMetafieldDefinitionAccess<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metafieldDefinitionUpdate(<\/span><span style=\"font-weight: 400;\">definition<\/span><span style=\"font-weight: 400;\">: {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;product_info&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;warranty_months&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">access<\/span><span style=\"font-weight: 400;\">: {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">admin<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">MERCHANT_READ_WRITE<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">storefront<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">PUBLIC_READ<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0updatedDefinition {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This pattern protects sensitive data while exposing necessary information to storefronts. The<\/span><a href=\"https:\/\/ecommerce.folio3.com\/shopify-integration\/\"> <span style=\"font-weight: 400;\">Shopify API integration<\/span><\/a><span style=\"font-weight: 400;\"> guide covers additional security considerations.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Bulk Operations for Large Datasets<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The Shopify GraphQL API includes bulk operation endpoints for processing thousands of metafields:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0bulkOperationRunQuery(<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">query<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;&#8221;&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0products {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafields {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0namespace<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0key<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0&#8220;&#8221;&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0bulkOperation {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">status<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bulk operations run asynchronously. Poll the operation status and download results via the provided URL when complete.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Optimizing Query Performance<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Strategic field selection reduces response time and cost:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Request Only Necessary Fields<\/b><span style=\"font-weight: 400;\">: Avoid selecting unused metafield properties like <\/span><span style=\"font-weight: 400;\">createdAt<\/span><span style=\"font-weight: 400;\"> unless needed.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Limit Connection Depth<\/b><span style=\"font-weight: 400;\">: Each nested level increases query cost. Fetch related resources separately when depth exceeds three levels.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Use Fragments<\/b><span style=\"font-weight: 400;\">: Define reusable field sets for consistent metafield selection across queries.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fragment<\/span> <span style=\"font-weight: 400;\">MetafieldDetails<\/span> <span style=\"font-weight: 400;\">on<\/span> <span style=\"font-weight: 400;\">Metafield<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">query<\/span> <span style=\"font-weight: 400;\">ProductsWithMetafields<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0products(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">20<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafields(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">&#8230;MetafieldDetails<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Handling Concurrent Updates<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Multiple processes modifying the same metafields can cause conflicts. Implement optimistic locking by checking <\/span><span style=\"font-weight: 400;\">updatedAt<\/span><span style=\"font-weight: 400;\">:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">query<\/span> <span style=\"font-weight: 400;\">GetMetafieldVersion<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0product(<\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafield(<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;inventory&#8221;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;stock_count&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">updatedAt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Compare <\/span><span style=\"font-weight: 400;\">updatedAt<\/span><span style=\"font-weight: 400;\"> before updates. If changed, refetch current value and retry your modification logic.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Metaobjects and Relationship Patterns<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Metaobjects provide structured content models similar to traditional CMS entries. They relate to metafields through references:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">CreateMetaobject<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metaobjectCreate(<\/span><span style=\"font-weight: 400;\">metaobject<\/span><span style=\"font-weight: 400;\">: {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;size_chart&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">fields<\/span><span style=\"font-weight: 400;\">: [<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;title&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;Standard T-Shirt Sizing&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;chart_data&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;[{\\&#8221;size\\&#8221;: \\&#8221;S\\&#8221;, \\&#8221;chest\\&#8221;: \\&#8221;34-36\\&#8221;}]&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metaobject {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">handle<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Reference metaobjects from product metafields to maintain separation between static content and dynamic product data.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Technique<\/b><\/td>\n<td><b>Best For<\/b><\/td>\n<td><b>Complexity<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Metafield definitions<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Schema validation, admin UI<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Low<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Bulk operations<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Processing &gt;1000 records<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Medium<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Query fragments<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Code reusability<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Low<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Metaobject references<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Complex content structures<\/span><\/td>\n<td><span style=\"font-weight: 400;\">High<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span style=\"font-weight: 400;\">Real-World Use Cases and Examples<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Understanding practical applications helps translate GraphQL metafield concepts into business solutions. These scenarios demonstrate common implementation patterns across industries.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">E-Commerce Product Customization<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Fashion retailers use metafields to store detailed product specifications beyond Shopify&#8217;s standard fields:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Care Instructions<\/b><span style=\"font-weight: 400;\">: Store washing, drying, and ironing guidelines in multi-line text metafields. Display these on <a href=\"https:\/\/ecommerce.folio3.com\/blog\/high-converting-product-pages\/\">product pages<\/a> to reduce return rates.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Material Composition<\/b><span style=\"font-weight: 400;\">: Track fabric percentages using JSON metafields: <\/span><span style=\"font-weight: 400;\">{&#8220;cotton&#8221;: 60, &#8220;polyester&#8221;: 40}<\/span><span style=\"font-weight: 400;\">. Filter products by material type in collections.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Size Guide References<\/b><span style=\"font-weight: 400;\">: Link products to metaobject-based size charts, enabling centralized size guide management across product families.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Inventory and Supply Chain Management<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Distributors extend Shopify&#8217;s inventory system with custom tracking:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Supplier Information<\/b><span style=\"font-weight: 400;\">: Store vendor codes, reorder levels, and lead times in namespaced metafields. Integrate with procurement systems via the Shopify GraphQL API.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Batch Tracking<\/b><span style=\"font-weight: 400;\">: Add lot numbers and expiration dates to variant metafields for industries requiring traceability like food or pharmaceuticals.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Multi-Warehouse Data<\/b><span style=\"font-weight: 400;\">: Track location-specific inventory attributes that Shopify&#8217;s native system doesn&#8217;t support, syncing data through scheduled GraphQL mutations.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Marketing and SEO Optimization<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Content teams leverage metafields for enhanced marketing capabilities:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Featured Product Badges<\/b><span style=\"font-weight: 400;\">: Boolean metafields flag products as &#8220;New Arrival&#8221; or &#8220;Staff Pick&#8221;. Query these in the<\/span> <span style=\"font-weight: 400;\">Shopify Storefront API<\/span><span style=\"font-weight: 400;\"> for dynamic collection filtering.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Social Media Assets<\/b><span style=\"font-weight: 400;\">: Store platform-specific image URLs and caption templates in JSON metafields. Automate social posts by querying these alongside product data.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>SEO Schema Markup<\/b><span style=\"font-weight: 400;\">: Add structured data like brand, GTIN, or review ratings to metafields. Render this as JSON-LD on product pages for rich search results.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Customer Data Extensions<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">B2B stores customize customer profiles with industry-specific information:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Tax Exemption Status<\/b><span style=\"font-weight: 400;\">: Track tax-exempt customers with boolean metafields. Reference these during checkout calculations via webhooks.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Account Representatives<\/b><span style=\"font-weight: 400;\">: Store assigned sales rep IDs in customer metafields. Display rep contact information in customer portal templates.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Credit Terms<\/b><span style=\"font-weight: 400;\">: Define payment terms and credit limits using number and date metafields. Integrate with order management systems through the GraphQL Shopify Admin API.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Integration Patterns<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Third-party systems sync data bidirectionally using metafields as the integration layer:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>ERP Synchronization<\/b><span style=\"font-weight: 400;\">: Map ERP product IDs to Shopify products using metafields. Query by ERP ID to <a href=\"https:\/\/ecommerce.folio3.com\/blog\/shopify-bulk-inventory-update\/\">update inventory<\/a> without managing separate SKU databases.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>PIM Systems<\/b><span style=\"font-weight: 400;\">: Import rich product content from Product Information Management platforms into structured metafields. Schedule bulk operations during off-peak hours.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Analytics Platforms<\/b><span style=\"font-weight: 400;\">: Store conversion tracking IDs in metafields for enhanced attribution. Expose these through the Shopify GraphQL Storefront API for client-side tracking scripts.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Subscription Commerce<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Subscription apps use metafields to store plan configurations and customer preferences:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Delivery Schedules<\/b><span style=\"font-weight: 400;\">: Customer metafields store preferred delivery days and frequencies. Query these when generating subscription orders.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Product Substitution Rules<\/b><span style=\"font-weight: 400;\">: Store acceptable product alternatives in JSON metafields. Reference during out-of-stock scenarios in fulfillment workflows.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Plan Pricing Overrides<\/b><span style=\"font-weight: 400;\">: Track customer-specific pricing in metafields for grandfathered subscriptions or negotiated contracts.<\/span><\/li>\n<\/ul>\n<h2><span style=\"font-weight: 400;\">Shopify GraphQL Examples and Code Snippets<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Practical implementation requires understanding common patterns and edge cases. These examples demonstrate production-ready code for typical metafield operations.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Complete Product Creation With Metafields<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Creating products and metafields simultaneously streamlines data import:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">CreateProductWithMetafields<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0productCreate(<\/span><span style=\"font-weight: 400;\">input<\/span><span style=\"font-weight: 400;\">: {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">title<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;Premium Cotton T-Shirt&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">productType<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;Apparel&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">vendor<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;House Brand&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">metafields<\/span><span style=\"font-weight: 400;\">: [<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;specifications&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;material&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;100% Organic Cotton&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;single_line_text_field&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;specifications&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;weight&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;8.5&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;number_decimal&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;care&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;instructions&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;Machine wash cold\\nTumble dry low\\nDo not bleach&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;multi_line_text_field&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0product {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">title<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafields(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">10<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This approach eliminates subsequent mutation calls, reducing API overhead during bulk imports.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Conditional Metafield Updates<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Update metafields only when values change:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">javascript<\/span><\/p>\n<p><span style=\"font-weight: 400;\">async<\/span> <span style=\"font-weight: 400;\">function<\/span> <span style=\"font-weight: 400;\">updateMetafieldIfChanged<\/span><span style=\"font-weight: 400;\">(productId, namespace, key, newValue) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><i><span style=\"font-weight: 400;\">\/\/ First, query current value<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> query <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0query {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0product(id: &#8220;<\/span><span style=\"font-weight: 400;\">${productId}<\/span><span style=\"font-weight: 400;\">&#8220;) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafield(namespace: &#8220;<\/span><span style=\"font-weight: 400;\">${namespace}<\/span><span style=\"font-weight: 400;\">&#8220;, key: &#8220;<\/span><span style=\"font-weight: 400;\">${key}<\/span><span style=\"font-weight: 400;\">&#8220;) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0`<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> currentData <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">await<\/span> <span style=\"font-weight: 400;\">shopifyGraphQL<\/span><span style=\"font-weight: 400;\">(query);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> currentValue <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> currentData<\/span><span style=\"font-weight: 400;\">?.<\/span><span style=\"font-weight: 400;\">product<\/span><span style=\"font-weight: 400;\">?.<\/span><span style=\"font-weight: 400;\">metafield<\/span><span style=\"font-weight: 400;\">?.<\/span><span style=\"font-weight: 400;\">value;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><i><span style=\"font-weight: 400;\">\/\/ Only update if value differs<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (currentValue <\/span><span style=\"font-weight: 400;\">!==<\/span><span style=\"font-weight: 400;\"> newValue) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> mutation <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mutation {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafieldsSet(metafields: [{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ownerId: &#8220;<\/span><span style=\"font-weight: 400;\">${productId}<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0namespace: &#8220;<\/span><span style=\"font-weight: 400;\">${namespace}<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0key: &#8220;<\/span><span style=\"font-weight: 400;\">${key}<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0value: &#8220;<\/span><span style=\"font-weight: 400;\">${newValue}<\/span><span style=\"font-weight: 400;\">&#8220;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0type: &#8220;single_line_text_field&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}]) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafields {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0`<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span> <span style=\"font-weight: 400;\">await<\/span> <span style=\"font-weight: 400;\">shopifyGraphQL<\/span><span style=\"font-weight: 400;\">(mutation);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> { <\/span><span style=\"font-weight: 400;\">skipped<\/span><span style=\"font-weight: 400;\">:<\/span> <span style=\"font-weight: 400;\">true<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">reason<\/span><span style=\"font-weight: 400;\">:<\/span> <span style=\"font-weight: 400;\">&#8220;Value unchanged&#8221;<\/span><span style=\"font-weight: 400;\"> };<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This pattern prevents unnecessary writes and associated API costs.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Querying Metafields by Type<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Filter metafields based on value type for type-specific processing:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0products(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">50<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">title<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafields(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">20<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Process the response client-side to group by type:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">javascript<\/span><\/p>\n<p><span style=\"font-weight: 400;\">function<\/span> <span style=\"font-weight: 400;\">groupMetafieldsByType<\/span><span style=\"font-weight: 400;\">(products) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> products.edges.<\/span><span style=\"font-weight: 400;\">map<\/span><span style=\"font-weight: 400;\">(({ node }) <\/span><span style=\"font-weight: 400;\">=&gt;<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> grouped <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> node.id,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">title<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> node.title,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">metafields<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">text<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> [],<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">numbers<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> [],<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">json<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> [],<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">booleans<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> []<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0};<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0node.metafields.edges.<\/span><span style=\"font-weight: 400;\">forEach<\/span><span style=\"font-weight: 400;\">(({ <\/span><span style=\"font-weight: 400;\">node<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> metafield }) <\/span><span style=\"font-weight: 400;\">=&gt;<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (metafield.type.<\/span><span style=\"font-weight: 400;\">includes<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;text&#8217;<\/span><span style=\"font-weight: 400;\">)) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0grouped.metafields.text.<\/span><span style=\"font-weight: 400;\">push<\/span><span style=\"font-weight: 400;\">(metafield);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} <\/span><span style=\"font-weight: 400;\">else<\/span> <span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (metafield.type.<\/span><span style=\"font-weight: 400;\">includes<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;number&#8217;<\/span><span style=\"font-weight: 400;\">)) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0grouped.metafields.numbers.<\/span><span style=\"font-weight: 400;\">push<\/span><span style=\"font-weight: 400;\">(metafield);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} <\/span><span style=\"font-weight: 400;\">else<\/span> <span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (metafield.type <\/span><span style=\"font-weight: 400;\">===<\/span> <span style=\"font-weight: 400;\">&#8216;json&#8217;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0grouped.metafields.json.<\/span><span style=\"font-weight: 400;\">push<\/span><span style=\"font-weight: 400;\">({<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">&#8230;<\/span><span style=\"font-weight: 400;\">metafield,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">parsedValue<\/span><span style=\"font-weight: 400;\">:<\/span> <span style=\"font-weight: 400;\">JSON<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">parse<\/span><span style=\"font-weight: 400;\">(metafield.value)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} <\/span><span style=\"font-weight: 400;\">else<\/span> <span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (metafield.type <\/span><span style=\"font-weight: 400;\">===<\/span> <span style=\"font-weight: 400;\">&#8216;boolean&#8217;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0grouped.metafields.booleans.<\/span><span style=\"font-weight: 400;\">push<\/span><span style=\"font-weight: 400;\">(metafield);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> grouped;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Handling Metafield Deletion in Bulk<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Remove metafields matching specific criteria across products:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">javascript<\/span><\/p>\n<p><span style=\"font-weight: 400;\">async<\/span> <span style=\"font-weight: 400;\">function<\/span> <span style=\"font-weight: 400;\">deleteMetafieldsByNamespace<\/span><span style=\"font-weight: 400;\">(namespace) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><i><span style=\"font-weight: 400;\">\/\/ First, collect all metafield IDs<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> query <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0products(first: 250) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafields(first: 50, namespace: &#8220;<\/span><span style=\"font-weight: 400;\">${namespace}<\/span><span style=\"font-weight: 400;\">&#8220;) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0`<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> data <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">await<\/span> <span style=\"font-weight: 400;\">shopifyGraphQL<\/span><span style=\"font-weight: 400;\">(query);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> metafieldIds <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> [];<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0data.products.edges.<\/span><span style=\"font-weight: 400;\">forEach<\/span><span style=\"font-weight: 400;\">(({ node }) <\/span><span style=\"font-weight: 400;\">=&gt;<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0node.metafields.edges.<\/span><span style=\"font-weight: 400;\">forEach<\/span><span style=\"font-weight: 400;\">(({ <\/span><span style=\"font-weight: 400;\">node<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> metafield }) <\/span><span style=\"font-weight: 400;\">=&gt;<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafieldIds.<\/span><span style=\"font-weight: 400;\">push<\/span><span style=\"font-weight: 400;\">(metafield.id);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><i><span style=\"font-weight: 400;\">\/\/ Delete in batches of 25<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> batchSize <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">25<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">let<\/span><span style=\"font-weight: 400;\"> i <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">; i <\/span><span style=\"font-weight: 400;\">&lt;<\/span><span style=\"font-weight: 400;\"> metafieldIds.length; i <\/span><span style=\"font-weight: 400;\">+=<\/span><span style=\"font-weight: 400;\"> batchSize) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> batch <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> metafieldIds.<\/span><span style=\"font-weight: 400;\">slice<\/span><span style=\"font-weight: 400;\">(i, i <\/span><span style=\"font-weight: 400;\">+<\/span><span style=\"font-weight: 400;\"> batchSize);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> mutations <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> batch.<\/span><span style=\"font-weight: 400;\">map<\/span><span style=\"font-weight: 400;\">((id, index) <\/span><span style=\"font-weight: 400;\">=&gt;<\/span> <span style=\"font-weight: 400;\">`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mutation<\/span><span style=\"font-weight: 400;\">${index}<\/span><span style=\"font-weight: 400;\">: metafieldDelete(input: {id: &#8220;<\/span><span style=\"font-weight: 400;\">${id}<\/span><span style=\"font-weight: 400;\">&#8220;}) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0deletedId<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0`<\/span><span style=\"font-weight: 400;\">).<\/span><span style=\"font-weight: 400;\">join<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;\\n&#8217;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">await<\/span> <span style=\"font-weight: 400;\">shopifyGraphQL<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">`mutation { <\/span><span style=\"font-weight: 400;\">${mutations}<\/span><span style=\"font-weight: 400;\"> }`<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> { <\/span><span style=\"font-weight: 400;\">deleted<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> metafieldIds.length };<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Working With List-Type Metafields<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">List metafields store multiple values of the same type:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">CreateListMetafield<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metafieldsSet(<\/span><span style=\"font-weight: 400;\">metafields<\/span><span style=\"font-weight: 400;\">: [{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">ownerId<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;features&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;highlights&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;[\\&#8221;Moisture-wicking\\&#8221;, \\&#8221;Breathable fabric\\&#8221;, \\&#8221;UPF 50+ protection\\&#8221;]&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;list.single_line_text_field&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}]) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafields {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Query and parse list values client-side:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">javascript<\/span><\/p>\n<p><span style=\"font-weight: 400;\">function<\/span> <span style=\"font-weight: 400;\">parseListMetafield<\/span><span style=\"font-weight: 400;\">(metafield) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (metafield.type.<\/span><span style=\"font-weight: 400;\">startsWith<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;list.&#8217;<\/span><span style=\"font-weight: 400;\">)) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span> <span style=\"font-weight: 400;\">JSON<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">parse<\/span><span style=\"font-weight: 400;\">(metafield.value);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> [metafield.value];<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Error Recovery and Retry Logic<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Implement robust error handling for production systems:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">javascript<\/span><\/p>\n<p><span style=\"font-weight: 400;\">async<\/span> <span style=\"font-weight: 400;\">function<\/span> <span style=\"font-weight: 400;\">setMetafieldWithRetry<\/span><span style=\"font-weight: 400;\">(metafieldInput, maxRetries <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">let<\/span><span style=\"font-weight: 400;\"> lastError;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">let<\/span><span style=\"font-weight: 400;\"> attempt <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">; attempt <\/span><span style=\"font-weight: 400;\">&lt;=<\/span><span style=\"font-weight: 400;\"> maxRetries; attempt<\/span><span style=\"font-weight: 400;\">++<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">try<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> mutation <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">`<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mutation {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafieldsSet(metafields: [<\/span><span style=\"font-weight: 400;\">${<\/span><span style=\"font-weight: 400;\">JSON<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">stringify<\/span><span style=\"font-weight: 400;\">(metafieldInput)}<\/span><span style=\"font-weight: 400;\">]) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metafields {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0`<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> response <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">await<\/span> <span style=\"font-weight: 400;\">shopifyGraphQL<\/span><span style=\"font-weight: 400;\">(mutation);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><i><span style=\"font-weight: 400;\">\/\/ Check for validation errors (don&#8217;t retry these)<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (response.userErrors <\/span><span style=\"font-weight: 400;\">&amp;&amp;<\/span><span style=\"font-weight: 400;\"> response.userErrors.length <\/span><span style=\"font-weight: 400;\">&gt;<\/span> <span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">throw<\/span> <span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">ValidationError<\/span><span style=\"font-weight: 400;\">(response.userErrors);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> response.metafields[<\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">];<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0} <\/span><span style=\"font-weight: 400;\">catch<\/span><span style=\"font-weight: 400;\"> (error) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0lastError <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> error;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><i><span style=\"font-weight: 400;\">\/\/ Don&#8217;t retry validation errors<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (error <\/span><span style=\"font-weight: 400;\">instanceof<\/span> <span style=\"font-weight: 400;\">ValidationError<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">throw<\/span><span style=\"font-weight: 400;\"> error;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><i><span style=\"font-weight: 400;\">\/\/ Exponential backoff<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (attempt <\/span><span style=\"font-weight: 400;\">&lt;<\/span><span style=\"font-weight: 400;\"> maxRetries) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">await<\/span> <span style=\"font-weight: 400;\">sleep<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">Math<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">pow<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, attempt) <\/span><span style=\"font-weight: 400;\">*<\/span> <span style=\"font-weight: 400;\">1000<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">throw<\/span> <span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">Error<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">`Failed after <\/span><span style=\"font-weight: 400;\">${maxRetries}<\/span><span style=\"font-weight: 400;\"> attempts: <\/span><span style=\"font-weight: 400;\">${lastError.message}<\/span><span style=\"font-weight: 400;\">`<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Troubleshooting Common Issues<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Even experienced developers encounter challenges when working with the Shopify GraphQL API. These solutions address frequent problems and their root causes.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Metafield Not Appearing in Queries<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Symptom<\/b><span style=\"font-weight: 400;\">: Created metafields don&#8217;t show up in subsequent queries immediately.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Cause<\/b><span style=\"font-weight: 400;\">: Shopify&#8217;s eventual consistency model means data propagates across systems with slight delays.<\/span><\/li>\n<\/ul>\n<p><b>Solution<\/b><span style=\"font-weight: 400;\">: Wait 1-2 seconds after mutations before querying. For critical workflows, verify creation by checking the mutation response:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">CreateAndVerify<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metafieldsSet(<\/span><span style=\"font-weight: 400;\">metafields<\/span><span style=\"font-weight: 400;\">: [{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">ownerId<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/123&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;test&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;verify&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;data&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;single_line_text_field&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}]) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafields {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The returned <\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\"> confirms successful creation. Use this ID in subsequent queries rather than relying on namespace-key lookups immediately.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Type Validation Errors<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Symptom<\/b><span style=\"font-weight: 400;\">: Mutations fail with &#8220;value type mismatch&#8221; errors.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Cause<\/b><span style=\"font-weight: 400;\">: Provided value doesn&#8217;t match declared type or existing metafield definition.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Solution<\/b><span style=\"font-weight: 400;\">: Always verify type compatibility before mutations:<\/span><\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td><b>Value Type<\/b><\/td>\n<td><b>Correct Format<\/b><\/td>\n<td><b>Common Mistakes<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">number_integer<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8220;42&#8221;<\/span><span style=\"font-weight: 400;\"> (as string)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Passing numeric type: <\/span><span style=\"font-weight: 400;\">42<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">number_decimal<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8220;3.14&#8221;<\/span><span style=\"font-weight: 400;\"> (as string)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Missing quotes: <\/span><span style=\"font-weight: 400;\">3.14<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">boolean<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8220;true&#8221;<\/span><span style=\"font-weight: 400;\"> or <\/span><span style=\"font-weight: 400;\">&#8220;false&#8221;<\/span><span style=\"font-weight: 400;\"> (as string)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Passing boolean: <\/span><span style=\"font-weight: 400;\">true<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">json<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Escaped string: <\/span><span style=\"font-weight: 400;\">&#8220;{\\&#8221;key\\&#8221;:\\&#8221;value\\&#8221;}&#8221;<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Unescaped JSON object<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span style=\"font-weight: 400;\">Rate Limit Throttling<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Symptom<\/b><span style=\"font-weight: 400;\">: Requests fail with &#8220;Throttled&#8221; error after several mutations.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Cause<\/b><span style=\"font-weight: 400;\">: Query costs exceed available bucket points.<\/span><\/li>\n<\/ul>\n<p><b>Solution<\/b><span style=\"font-weight: 400;\">: Monitor <\/span><span style=\"font-weight: 400;\">throttleStatus<\/span><span style=\"font-weight: 400;\"> in responses and implement backoff:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">javascript<\/span><\/p>\n<p><span style=\"font-weight: 400;\">async<\/span> <span style=\"font-weight: 400;\">function<\/span> <span style=\"font-weight: 400;\">smartMutation<\/span><span style=\"font-weight: 400;\">(mutation) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> response <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">await<\/span> <span style=\"font-weight: 400;\">shopifyGraphQL<\/span><span style=\"font-weight: 400;\">(mutation);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> throttle <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> response.extensions<\/span><span style=\"font-weight: 400;\">?.<\/span><span style=\"font-weight: 400;\">cost<\/span><span style=\"font-weight: 400;\">?.<\/span><span style=\"font-weight: 400;\">throttleStatus;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (throttle <\/span><span style=\"font-weight: 400;\">&amp;&amp;<\/span><span style=\"font-weight: 400;\"> throttle.currentlyAvailable <\/span><span style=\"font-weight: 400;\">&lt;<\/span> <span style=\"font-weight: 400;\">100<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> waitTime <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">100<\/span> <span style=\"font-weight: 400;\">&#8211;<\/span><span style=\"font-weight: 400;\"> throttle.currentlyAvailable) <\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\"> throttle.restoreRate <\/span><span style=\"font-weight: 400;\">*<\/span> <span style=\"font-weight: 400;\">1000<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">await<\/span> <span style=\"font-weight: 400;\">sleep<\/span><span style=\"font-weight: 400;\">(waitTime);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> response;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Batch operations when possible to reduce total cost. The<\/span><a href=\"https:\/\/ecommerce.folio3.com\/blog\/shopify-plus-features\/\"> <span style=\"font-weight: 400;\">Shopify Plus features<\/span><\/a><span style=\"font-weight: 400;\"> include higher rate limits for enterprise stores.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Global ID Format Confusion<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Symptom<\/b><span style=\"font-weight: 400;\">: Queries return null when using numeric IDs.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Cause<\/b><span style=\"font-weight: 400;\">: GraphQL requires global ID format, not simple numeric IDs.<\/span><\/li>\n<\/ul>\n<p><b>Solution<\/b><span style=\"font-weight: 400;\">: Convert numeric IDs to global ID format:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">javascript<\/span><\/p>\n<p><span style=\"font-weight: 400;\">function<\/span> <span style=\"font-weight: 400;\">toGlobalId<\/span><span style=\"font-weight: 400;\">(resourceType, numericId) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span> <span style=\"font-weight: 400;\">`gid:\/\/shopify\/<\/span><span style=\"font-weight: 400;\">${resourceType}<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">${numericId}<\/span><span style=\"font-weight: 400;\">`<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">\/\/ Usage<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> productGid <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">toGlobalId<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;Product&#8217;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">7982301118638<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">\/\/ Result: &#8220;gid:\/\/shopify\/Product\/7982301118638&#8221;<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">Extract numeric IDs when needed:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">javascript<\/span><\/p>\n<p><span style=\"font-weight: 400;\">function<\/span> <span style=\"font-weight: 400;\">fromGlobalId<\/span><span style=\"font-weight: 400;\">(globalId) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> parts <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> globalId.<\/span><span style=\"font-weight: 400;\">split<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;\/&#8217;<\/span><span style=\"font-weight: 400;\">);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> parts[<\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">],<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> parts[<\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0};<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Metafield Definition Conflicts<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Symptom<\/b><span style=\"font-weight: 400;\">: Cannot create metafield with desired namespace-key combination.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Cause<\/b><span style=\"font-weight: 400;\">: Existing definition specifies different type or validation rules.<\/span><\/li>\n<\/ul>\n<p><b>Solution<\/b><span style=\"font-weight: 400;\">: Query existing definitions before attempting creation:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metafieldDefinitions(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">250<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">ownerType<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">PRODUCT<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">name<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Either conform to existing definition or delete\/update it first (requires appropriate permissions).<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Null Values in Nested Queries<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Symptom<\/b><span style=\"font-weight: 400;\">: Metafield queries return null for products that should have data.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Cause<\/b><span style=\"font-weight: 400;\">: Metafield exists on variants instead of product level, or vice versa.<\/span><\/li>\n<\/ul>\n<p><b>Solution<\/b><span style=\"font-weight: 400;\">: Check both levels explicitly:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0product(<\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/123&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">productLevelMetafield<\/span><span style=\"font-weight: 400;\">: metafield(<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;specs&#8221;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;material&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0variants(<\/span><span style=\"font-weight: 400;\">first<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edges {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0node {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">variantLevelMetafield<\/span><span style=\"font-weight: 400;\">: metafield(<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;specs&#8221;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;material&#8221;<\/span><span style=\"font-weight: 400;\">) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Understanding where metafields are stored prevents unexpected null values.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Permission and Scope Issues<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Symptom<\/b><span style=\"font-weight: 400;\">: Mutations fail with &#8220;Access denied&#8221; even with valid authentication.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Cause<\/b><span style=\"font-weight: 400;\">: App lacks required API scopes for metafield operations.<\/span><\/li>\n<\/ul>\n<p><b>Solution<\/b><span style=\"font-weight: 400;\">: Verify scopes in app configuration include:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">read_metaobjects<\/span><span style=\"font-weight: 400;\"> for queries<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">write_metaobjects<\/span><span style=\"font-weight: 400;\"> for mutations<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Resource-specific scopes like <\/span><span style=\"font-weight: 400;\">read_products<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">write_products<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Request additional scopes through app settings, which requires merchant approval.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Best Practices for Production Implementation<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Scaling Shopify GraphQL metafield operations from development to production requires attention to architecture, performance, and maintainability.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Schema Design Principles<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Namespace Strategy<\/b><span style=\"font-weight: 400;\">: Establish clear namespace conventions early. Use prefixes that indicate ownership: <\/span><span style=\"font-weight: 400;\">app_[appname]<\/span><span style=\"font-weight: 400;\"> for app-specific data, <\/span><span style=\"font-weight: 400;\">merchant_<\/span><span style=\"font-weight: 400;\"> for admin-entered data, <\/span><span style=\"font-weight: 400;\">system_<\/span><span style=\"font-weight: 400;\"> for automated processes.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Key Naming<\/b><span style=\"font-weight: 400;\">: Use descriptive, self-documenting keys. Prefer <\/span><span style=\"font-weight: 400;\">fabric_care_instructions<\/span><span style=\"font-weight: 400;\"> over <\/span><span style=\"font-weight: 400;\">fci<\/span><span style=\"font-weight: 400;\"> or <\/span><span style=\"font-weight: 400;\">instructions<\/span><span style=\"font-weight: 400;\">. Future developers will appreciate clarity.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Type Selection<\/b><span style=\"font-weight: 400;\">: Choose the most restrictive type that accommodates your data. Use <\/span><span style=\"font-weight: 400;\">number_integer<\/span><span style=\"font-weight: 400;\"> instead of <\/span><span style=\"font-weight: 400;\">single_line_text_field<\/span><span style=\"font-weight: 400;\"> for quantities, enabling mathematical operations later.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Version Management<\/b><span style=\"font-weight: 400;\">: When changing metafield structure, create new keys rather than modifying existing ones. For example, transition from <\/span><span style=\"font-weight: 400;\">size_chart<\/span><span style=\"font-weight: 400;\"> to <\/span><span style=\"font-weight: 400;\">size_chart_v2<\/span><span style=\"font-weight: 400;\"> to support backward compatibility.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Performance Optimization<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Query Depth Limits<\/b><span style=\"font-weight: 400;\">: Keep nested queries under four levels deep. Deeper nesting increases cost exponentially and risks timeouts.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Selective Field Retrieval<\/b><span style=\"font-weight: 400;\">: Request only fields you&#8217;ll use. Avoid querying <\/span><span style=\"font-weight: 400;\">createdAt<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">updatedAt<\/span><span style=\"font-weight: 400;\">, or <\/span><span style=\"font-weight: 400;\">owner<\/span><span style=\"font-weight: 400;\"> unless necessary for your logic.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Pagination Strategy<\/b><span style=\"font-weight: 400;\">: Use cursor-based pagination with reasonable page sizes (50-100 items). Track <\/span><span style=\"font-weight: 400;\">pageInfo.hasNextPage<\/span><span style=\"font-weight: 400;\"> to prevent overruns.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Caching Layer<\/b><span style=\"font-weight: 400;\">: Cache metafield definitions since they rarely change. Store them locally for 24 hours to reduce API calls:<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">javascript<\/span><\/p>\n<p><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> definitionCache <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">new<\/span> <span style=\"font-weight: 400;\">Map<\/span><span style=\"font-weight: 400;\">();<\/span><\/p>\n<p><span style=\"font-weight: 400;\">async<\/span> <span style=\"font-weight: 400;\">function<\/span> <span style=\"font-weight: 400;\">getCachedDefinition<\/span><span style=\"font-weight: 400;\">(namespace, key) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> cacheKey <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">`<\/span><span style=\"font-weight: 400;\">${namespace}<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\">${key}<\/span><span style=\"font-weight: 400;\">`<\/span><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (definitionCache.<\/span><span style=\"font-weight: 400;\">has<\/span><span style=\"font-weight: 400;\">(cacheKey)) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> cached <\/span><span style=\"font-weight: 400;\">=<\/span><span style=\"font-weight: 400;\"> definitionCache.<\/span><span style=\"font-weight: 400;\">get<\/span><span style=\"font-weight: 400;\">(cacheKey);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (<\/span><span style=\"font-weight: 400;\">Date<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">now<\/span><span style=\"font-weight: 400;\">() <\/span><span style=\"font-weight: 400;\">&#8211;<\/span><span style=\"font-weight: 400;\"> cached.timestamp <\/span><span style=\"font-weight: 400;\">&lt;<\/span> <span style=\"font-weight: 400;\">86400000<\/span><span style=\"font-weight: 400;\">) { <\/span><i><span style=\"font-weight: 400;\">\/\/ 24 hours<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> cached.definition;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> definition <\/span><span style=\"font-weight: 400;\">=<\/span> <span style=\"font-weight: 400;\">await<\/span> <span style=\"font-weight: 400;\">fetchDefinition<\/span><span style=\"font-weight: 400;\">(namespace, key);<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0definitionCache.<\/span><span style=\"font-weight: 400;\">set<\/span><span style=\"font-weight: 400;\">(cacheKey, {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0definition,<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">timestamp<\/span><span style=\"font-weight: 400;\">:<\/span> <span style=\"font-weight: 400;\">Date<\/span><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\">now<\/span><span style=\"font-weight: 400;\">()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0});<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> definition;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Data Validation and Integrity<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Client-Side Validation<\/b><span style=\"font-weight: 400;\">: Validate metafield values before mutation to catch errors early and provide better user feedback.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Idempotent Operations<\/b><span style=\"font-weight: 400;\">: Design mutations to be safely retryable. Check if metafields exist before creating, or use <\/span><span style=\"font-weight: 400;\">metafieldsSet<\/span><span style=\"font-weight: 400;\"> which handles both creates and updates.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Audit Trails<\/b><span style=\"font-weight: 400;\">: Store modification timestamps and user identifiers in separate metafields for compliance and debugging:<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">graphql<\/span><\/p>\n<p><span style=\"font-weight: 400;\">mutation<\/span> <span style=\"font-weight: 400;\">CreateWithAudit<\/span><span style=\"font-weight: 400;\"> {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0metafieldsSet(<\/span><span style=\"font-weight: 400;\">metafields<\/span><span style=\"font-weight: 400;\">: [<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">ownerId<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/123&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;inventory&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;stock_count&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;50&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;number_integer&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0},<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0{<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">ownerId<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;gid:\/\/shopify\/Product\/123&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">namespace<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;inventory&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">key<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;last_updated_by&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">value<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;user@example.com&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">type<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">&#8220;single_line_text_field&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0]) {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0metafields {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">id<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0userErrors {<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">field<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"font-weight: 400;\">message<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">}<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Security Considerations<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Access Control<\/b><span style=\"font-weight: 400;\">: Never expose metafield management directly to untrusted frontend code. Proxy all operations through your backend.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Input Sanitization<\/b><span style=\"font-weight: 400;\">: Sanitize values before storing in metafields, especially when accepting user input that might later render on storefronts.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Sensitive Data<\/b><span style=\"font-weight: 400;\">: Avoid storing PII, credentials, or payment information in metafields. Use Shopify&#8217;s dedicated customer and order systems for regulated data.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Token Management<\/b><span style=\"font-weight: 400;\">: Rotate access tokens periodically and implement token storage best practices. Never commit tokens to version control.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Error Handling Patterns<\/span><\/h3>\n<p><b>Graceful Degradation<\/b><span style=\"font-weight: 400;\">: When metafields fail to load, fall back to default values or hide dependent features rather than breaking entire pages.<\/span><\/p>\n<p><b>Logging and Monitoring<\/b><span style=\"font-weight: 400;\">: Track metafield operation metrics:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Success\/failure rates by namespace<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Average query costs<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Most frequently accessed keys<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Validation error patterns<\/span><\/li>\n<\/ul>\n<p><b>Alerting Thresholds<\/b><span style=\"font-weight: 400;\">: Set up alerts for:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Error rates exceeding 5%<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Query costs consistently above 800 points<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Rate limit exhaustion<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Unexpected null metafield values in critical paths<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Testing Strategies<\/span><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Unit Tests<\/b><span style=\"font-weight: 400;\">: Mock GraphQL responses to test metafield parsing and transformation logic without API calls.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Integration Tests<\/b><span style=\"font-weight: 400;\">: Use <a href=\"https:\/\/ecommerce.folio3.com\/blog\/shopify-store-development-cost\/\">Shopify&#8217;s development stores<\/a> to test actual API interactions. Create dedicated test namespaces like <\/span><span style=\"font-weight: 400;\">test_app_[feature]<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Load Tests<\/b><span style=\"font-weight: 400;\">: Simulate production volumes before launch. Test batch operations with representative data sizes.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Rollback Plans<\/b><span style=\"font-weight: 400;\">: Maintain scripts to reverse metafield changes if updates cause issues. Store previous values temporarily during migrations.<\/span><\/li>\n<\/ul>\n<h3><span style=\"font-weight: 400;\">Documentation and Maintenance<\/span><\/h3>\n<p><b>Metafield Registry<\/b><span style=\"font-weight: 400;\">: Document all metafields your application creates or modifies:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">markdown<\/span><\/p>\n<p><span style=\"font-weight: 400;\">##<\/span><span style=\"font-weight: 400;\"> Metafield Registry<\/span><\/p>\n<p><span style=\"font-weight: 400;\">###<\/span><span style=\"font-weight: 400;\"> Namespace: product_specs<\/span><\/p>\n<p><span style=\"font-weight: 400;\">|<\/span><span style=\"font-weight: 400;\"> Key <\/span><span style=\"font-weight: 400;\">|<\/span><span style=\"font-weight: 400;\"> Type <\/span><span style=\"font-weight: 400;\">|<\/span><span style=\"font-weight: 400;\"> Purpose <\/span><span style=\"font-weight: 400;\">|<\/span><span style=\"font-weight: 400;\"> Example <\/span><span style=\"font-weight: 400;\">|<\/span><\/p>\n<p><span style=\"font-weight: 400;\">|&#8212;&#8211;|&#8212;&#8212;|&#8212;&#8212;&#8212;|&#8212;&#8212;&#8212;|<\/span><\/p>\n<p><span style=\"font-weight: 400;\">| material | single_line_text_field | Primary fabric composition | &#8220;100% Cotton&#8221; |<\/span><\/p>\n<p><span style=\"font-weight: 400;\">| weight_oz | number_decimal | Product weight in ounces | &#8220;8.5&#8221; |<\/span><\/p>\n<p><b>Change Log<\/b><span style=\"font-weight: 400;\">: Track metafield schema changes with dates and reasons, helping future developers understand evolution.<\/span><\/p>\n<p><b>Deprecation Process<\/b><span style=\"font-weight: 400;\">: When retiring metafields, mark them deprecated for at least one version cycle before deletion. Communicate changes to affected merchants.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Key Takeaways<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Shopify GraphQL metafields extend your store&#8217;s data model with precision and flexibility. Focus on these core concepts:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Strategic Schema Design<\/b><span style=\"font-weight: 400;\">: Plan namespaces, keys, and types before implementation. Clear conventions prevent conflicts and simplify maintenance as your application scales.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Efficient Query Patterns<\/b><span style=\"font-weight: 400;\">: Request only necessary fields and use pagination appropriately. Monitor query costs to stay within rate limits while maintaining responsiveness.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Robust Error Handling<\/b><span style=\"font-weight: 400;\">: Implement retry logic for transient failures but don&#8217;t retry validation errors. Always check <\/span><span style=\"font-weight: 400;\">userErrors<\/span><span style=\"font-weight: 400;\"> in mutation responses before assuming success.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Production-Ready Architecture<\/b><span style=\"font-weight: 400;\">: Cache definitions, validate inputs client-side, and maintain audit trails. Design for graceful degradation when metafield operations fail.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Type-Appropriate Operations<\/b><span style=\"font-weight: 400;\">: Match value types to data structures. Use JSON for complex nested data, numbers for calculations, and booleans for flags.<\/span><\/li>\n<\/ul>\n<h2><span style=\"font-weight: 400;\">Frequently Asked Questions<\/span><\/h2>\n<h3><span style=\"font-weight: 400;\">What Is the Difference Between Shopify GraphQL and REST APIs?<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The Shopify GraphQL API allows precise field selection in single requests, while REST requires multiple endpoints for related data. GraphQL reduces over-fetching and under-fetching, making it more efficient for complex metafield operations across products, variants, and collections.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">How Many Metafields Can a Product Have?<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Each Shopify resource supports unlimited metafields across different namespace-key combinations. However, practical limits exist around query performance and management complexity. Organize related data into structured types like JSON rather than creating dozens of separate single-value metafields.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Can I Query Metafields Using the Storefront API?<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Yes, the Shopify GraphQL Storefront API exposes metafields marked with public read access in their definitions. This lets you display custom product data on your storefront without exposing sensitive merchant-only information through separate API configurations.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">How Do I Handle Metafield Type Changes?<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Create new metafields with updated types rather than modifying existing ones. Migrate data using background jobs, validate the migration, then deprecate old metafields. This approach prevents breaking active integrations that depend on existing field structures.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">What Are Metafield Definitions and Why Use Them?<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Metafield definitions establish validation rules, data types, and admin UI customization for specific namespace-key combinations. They prevent data corruption through type enforcement and enable Shopify&#8217;s admin interface to generate appropriate input fields automatically.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">How Do I Optimize GraphQL Query Costs?<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Request only fields you&#8217;ll use, limit pagination to reasonable sizes, and avoid deeply nested queries. Monitor the cost field in responses and implement backoff when approaching rate limits. Batch-related operations in single mutations rather than making sequential requests.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Can Multiple Apps Use the Same Metafield Namespace?<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">While technically possible, different apps should use unique namespaces to prevent conflicts. Prefix namespaces with your app identifier like <\/span><span style=\"font-weight: 400;\">myapp_specifications<\/span><span style=\"font-weight: 400;\"> to ensure isolation from other integrations accessing the merchant&#8217;s store.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">How Do I Delete All Metafields in a Namespace?<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Query all metafields in the target namespace, collect their IDs, then execute batched delete mutations. Process deletions in groups of 25 to stay within rate limits and implement proper error handling for failed operations.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Conclusion<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Mastering Shopify GraphQL metafields unlocks powerful customization capabilities for your e-commerce store. The GraphQL Admin API provides precise control over custom data while maintaining performance through strategic query design and efficient mutation patterns.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Success with Shopify GraphQL metafields requires understanding schema design, implementing proper error handling, and following production-ready patterns. Start with clear namespace conventions, validate inputs before mutations, and monitor API costs as you scale operations.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ready to implement advanced metafield solutions for your Shopify store?<\/span><a href=\"https:\/\/ecommerce.folio3.com\/contact-us\/\"> <span style=\"font-weight: 400;\">Contact our Shopify development team<\/span><\/a><span style=\"font-weight: 400;\"> to discuss custom integrations that leverage the full power of the GraphQL API for your business needs.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Managing custom data in Shopify often means wrestling with limited fields and inflexible data structures. Shopify GraphQL metafields solve this by letting you store, query, and update custom attributes across products, variants, orders, and customers using a unified API approach. This guide walks you through working with Shopify GraphQL metafields using the GraphQL Admin API.<\/p>\n","protected":false},"author":35,"featured_media":17326,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[29],"tags":[68],"class_list":{"0":"post-17325","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-shopify","8":"tag-shopify-development"},"acf":[],"featured_image_data":{"src":"https:\/\/ecommerce.folio3.com\/blog\/wp-content\/uploads\/2023\/03\/shopify-graphql-best-practices.jpg","alt":"Shopify GraphQL Metafields Guide Using the GraphQL Admin API","caption":""},"_links":{"self":[{"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/posts\/17325"}],"collection":[{"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/comments?post=17325"}],"version-history":[{"count":0,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/posts\/17325\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/media\/17326"}],"wp:attachment":[{"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/media?parent=17325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/categories?post=17325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ecommerce.folio3.com\/blog\/wp-json\/wp\/v2\/tags?post=17325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}