--- title: Retrieve product data using the new product model description: >- Learn how to retrieve product data using the new product model, including using fragments and cursor-based pagination to request product variant data efficiently. source_url: html: >- https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/retrieve-data md: >- https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/retrieve-data.md --- ExpandOn this page * [What you'll learn](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/retrieve-data.md#what-youll-learn) * [Query product variants with fragments and cursor-based pagination](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/retrieve-data.md#query-product-variants-with-fragments-and-cursor-based-pagination) * [Next steps](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/retrieve-data.md#next-steps) # Retrieve product data using the new product model Legacy The REST Admin API is a legacy API as of October 1, 2024. All apps and integrations should be built with the [GraphQL Admin API](https://shopify.dev/docs/api/admin-graphql). For details and migration steps, visit our [migration guide](https://shopify.dev/docs/apps/build/graphql/migrate). After you understand the [new product model](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/product-model-components), you can use it to interact with products, variants, and options in a store. In this guide, you'll use the GraphQL Admin API to query product variant data. *** ## What you'll learn In this guide, you'll learn how to request data on existing product variants using the GraphQL Admin API, taking into consideration GraphQL features like nested pagination. Nested pagination might be new to you if you're [migrating from the REST Admin API](https://shopify.dev/docs/apps/build/graphql/migrate). Note If your app or use case aligns with the [database sync workflow](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/product-model-components#database-sync-workflow), then use the [`productSet`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/productSet) mutation to [retrieve data asynchronously](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/sync-data#query-the-updated-product-asynchronously). *** ## Query product variants with fragments and cursor-based pagination Retrieving a list of product variants with the GraphQL Admin API may require pagination if the number of variants exceeds the page size limit of 250. For example, to fetch data from 300 variants in a product, you need to run a query to retrieve 250 variants and then run it again to retrieve the remaining 50. The following examples demonstrate how to use [fragments](https://shopify.dev/docs/api/usage/graphql-basics/advanced#inline-fragments) and [cursor-based pagination](https://shopify.dev/docs/api/usage/pagination-graphql) to query product variants with the GraphQL Admin API. In this context, nested pagination refers to the process of retrieving all variants (a nested field) of a product in multiple steps due to the page size limit. Initially, the first 250 variants are fetched. Then, using the cursor from the last variant of the first batch, the remaining variants are fetched in a subsequent query. ### Fragments example: Product fields Use fragments to request the same fields in multiple queries without duplicating them: ## Fragment for requesting product data across multiple queries ```graphql fragment ProductFields on Product { id title description options { id name position values optionValues { id name hasVariants } } } ``` ### Fragments example: Variant fields Use fragments to request the same fields in multiple queries without duplicating them: ## Fragment for requesting product variant data across multiple queries ```graphql fragment VariantFields on ProductVariant { id title price sku } ``` ### Query the first 250 variants GraphQL offers a `cursor` field, which acts as a reference to a node's position in a [connection](https://shopify.dev/docs/api/usage/graphql-basics/queries#connections). To ensure that you can retrieve all of the nodes in a connection, or, all of the variants that are attached to a product, request the cursor field. You can pass this value in your next query to start retrieving where you left off. The first query requests the first 250 variants: ## POST https\://{shop}.myshopify.com/api/{api\_version}/graphql.json ## GraphQL query ```graphql query GetProductAndFirst250Variants { product(id: "gid://shopify/Product/456") { ...ProductFields variants(first: 250) { edges { cursor node { ...VariantFields } } } } } ``` ## JSON response ```json { "data": { "product": { "id": "gid://shopify/Product/18", "title": "My Extra Cool Socks", "description": "", "options": [ { "id": "gid://shopify/ProductOption/42", "name": "Color", "position": 1, "values": [ "Blue", "Yellow", "Orange", "Turquoise", "Red", "Green" ], "optionValues": [ { "id": "gid://shopify/ProductOptionValue/161", "name": "Blue", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/170", "name": "Yellow", "hasVariants": true }, { "id": "gid://shopify/ProductOptionValue/171", "name": "Orange", "hasVariants": true }, { ``` ### Query the remaining variants The second query requests the next set of data, or the remaining 50 variants, by passing the `cursor` value in an `after` argument: ## POST https\://{shop}.myshopify.com/api/{api\_version}/graphql.json ## GraphQL query ```graphql query GetProductAndLast50Variants { product(id: "gid://shopify/Product/456") { ...ProductFields variants(first: 50, after: "eyJsYXN0X2lkIjoxLCJsYXN0X3ZhbHVlIjoiMSJ9") { edges { node { ...VariantFields } } } } } ``` ## JSON response ```json { // The response's data structure will be the same as the return for the first 250 variants } ``` ### Tip: Check the number of product variants A quick way to check the number of variants in a product is by requesting the [`Product` object's `variantCount`](https://shopify.dev/docs/api/admin-graphql/unstable/objects/Product#field-product-variantscount) field. This field is useful when you're managing large volumes of variants, and is highly optimized. ## POST https\://{shop}.myshopify.com/api/{api\_version}/graphql.json ## GraphQL query ```graphql query GetProductVariantsCount { product(id: "gid://shopify/Product/456") { variantsCount { count } } } ``` ## JSON response ```json { "data": { "product": { "variantsCount": { "count": 9 } } } } ``` *** ## Next steps [![](https://shopify.dev/images/icons/48/graphql.png)![](https://shopify.dev/images/icons/48/graphql-dark.png)](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/add-data) [Add data](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/add-data) [Learn how to add product data, including variants and options.](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/add-data) [![](https://shopify.dev/images/icons/48/graphql.png)![](https://shopify.dev/images/icons/48/graphql-dark.png)](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/edit-data) [Edit data](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/edit-data) [Learn how to edit product data, including variants and options.](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/edit-data) [![](https://shopify.dev/images/icons/48/graphql.png)![](https://shopify.dev/images/icons/48/graphql-dark.png)](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/sync-data) [Sync data](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/sync-data) [Learn how you can sync product data from an external source into Shopify.](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/sync-data) *** * [What you'll learn](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/retrieve-data.md#what-youll-learn) * [Query product variants with fragments and cursor-based pagination](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/retrieve-data.md#query-product-variants-with-fragments-and-cursor-based-pagination) * [Next steps](https://shopify.dev/docs/apps/build/graphql/migrate/new-product-model/retrieve-data.md#next-steps)