Many API client libraries that you might use to call the Shopify Admin API support both REST and GraphQL. However, you need to make updates to your code that uses these libraries. Some updates that you need to make might include the following: - Switching from a REST client to a GraphQL client - Changing the API endpoint - Updating the method - Adding your query or mutation and specifying the fields to return - Destructuring or digging into the response You don't need to update your authentication or session handling to update from REST to GraphQL. Use the following examples to understand the changes that you need to make for each API library. This guide doesn't explain all of the changes that you need to make to your app to use GraphQL instead of REST. For example, you need to update your error handling and pagination logic. [Learn more about considerations when migrating from REST to GraphQL](/docs/apps/build/graphql/migrate/learn-how). ## shopify-api-js The following examples show you how to update your calls to GraphQL when reading or writing data using the [shopify-api-js](https://github.com/Shopify/shopify-app-js/tree/main/packages/apps/shopify-api) library. ### Reading data The following requests retrieve information about a product. To convert the REST version of this request to GraphQL, you need to make the following changes in your code.
Update Description
Change the client type

Remix: Instead of creating an admin.rest client or using REST resource classes like admin.rest.resources.Product, create an admin.graphql client.

Non-Remix: Instead of creating a shopify.clients.Rest client or using REST resource classes like shopify.rest.Product, create a shopify.clients.GraphQL client.

Change the method Instead of using the get method on the REST client or the find, all, or count method on the resource class, use the query method on the GraphQL client.
Add a query

Pass a query to the client, requesting the information that you want to retrieve.

Instead of specifying the path to the resource (like 'products/1234') or the ID to the find method, write a GraphQL query that retrieves the desired resource and its fields.

If you're retrieving a resource by its ID, then use the GraphQL API global ID (GID) for the resource (like "gid://shopify/Product/1234") instead of a simple ID.

Destructure the response

GraphQL responses are typically nested within a data object. The structure of the data mirrors the structure of the query. To make the data easier to work with, destructure the object that's returned.

You can also access properties of the object using dot notation (response.body.data.product).

### Writing data The following requests create a new product. To convert the REST version of this request to GraphQL, you need to make the following changes in your code.
Update Description
Change the client type

Remix: Instead of creating an admin.rest client or using REST resource classes like admin.rest.resources.Product, create an admin.graphql client.

Non-Remix: Instead of creating a shopify.clients.Rest client or using REST resource classes like shopify.rest.Product, create a shopify.clients.GraphQL client.

Change the method Instead of using the post, put, or delete method on the REST client, or the save or delete method on the resource class, use the query method on the GraphQL client.
Add a mutation

Instead of specifying the path to the resource (like 'products'), or the data to the resource's new method, write a GraphQL mutation that creates or updates the desired resource and specifies the fields to be returned.

Destructure the response

GraphQL responses are typically nested within a data object, and the structure of the data often mirrors the structure of the mutation. To make the data easier to work with, destructure the object that's returned.

You can also access properties of the object using dot notation (response.body.data.productCreate.product).

Read userErrors Extract the userErrors array from the response. If the mutation wasn't completed, then this information is returned in this array. Learn about how error handling differs in GraphQL.

## shopify-api-ruby The following examples show you how to update your calls to GraphQL when reading or writing data using the [shopify-api-ruby](https://github.com/Shopify/shopify-api-ruby) library. ### Reading data The following requests retrieve information about a product. To convert the REST version of this request to GraphQL, you need to make the following changes in your code.
Update Description
Change the client type Instead of creating a shopify.clients.Rest client or using REST resource classes like shopify.rest.Product.find, create a shopify.clients.GraphQL client.
Change the method Instead of using the get method on the REST client or the find, all, or count method on the resource class, use the query method on the GraphQL client.
Add a query

Pass a query to the client, requesting the information that you want to retrieve.

Instead of specifying the path to a resource (like 'products/1234'), or passing an ID to a resource method, write a GraphQL query that retrieves the desired resource and its fields.

If you're retrieving a resource by its ID, then use the GraphQL API global ID (GID) for the resource (like "gid://shopify/Product/1234") instead of a simple ID.

Destructure the response

GraphQL responses are typically nested within a data object. The structure of the data mirrors the structure of the query. To make the data easier to work with, destructure the object that's returned.

You can also access properties of the object using bracket notation. In the provided Ruby example, the product data is accessed with result.body["data"]["product"].

### Writing data The following requests create a new product. To convert the REST version of this request to GraphQL, you need to make the following changes in your code.
Update Description
Change the client type Instead of creating a ShopifyAPI::Clients::Rest::Admin client or using REST resource classes like ShopifyAPI::Product, create a ShopifyAPI::Clients::Graphql::Admin client.
Change the method Instead of using the post, put, or delete method on the REST client, or the save or delete method on the resource class, use the query method on the GraphQL client.
Add a mutation

Instead of specifying the path to the resource (like 'products'), or the data to the resource's new method, write a GraphQL mutation that creates or updates the desired resource and specifies the fields to be returned.

Destructure the response

GraphQL responses are typically nested within a data object, and the structure of the data often mirrors the structure of the mutation. To make the data easier to work with, destructure the object that's returned.

You can also access properties of the object using dot notation (result.body["data"]["productCreate"]).

Read userErrors Extract the userErrors array from the response. If the mutation wasn't completed, then this information is returned in this array. Learn about how error handling differs in GraphQL.

## Node Fetch / Axios The following examples show you how to update your calls to GraphQL when reading or writing data using the [Node Fetch](https://www.npmjs.com/package/node-fetch) or [Axios](https://axios-http.com/) libraries. ### Reading data The following requests retrieve information about a product. To convert the REST version of this request to GraphQL, you need to make the following changes in your code.                                                                                                                                       
UpdateDescription
Change the endpointInstead of a resource-specific endpoint (/products/1234.json), use the generic GraphQL endpoint for the store. Information about the resource that you want to retrieve is passed in the request body.
Change the methodInstead of using GET, use POST for all requests.
Add a query

In the request body, query the resource (for example, product).

Instead of using a simple ID (1234), use the GraphQL API global ID (GID) for the resource (gid://shopify/Product/1234).

Specify the fields that you want to return in the request body.

Destructure the response

GraphQL responses are typically nested within a data object. The structure of the data mirrors the structure of the query. To make the data easier to work with, destructure the object that's returned.

You can also access properties of the object using dot notation (body.data.product).

### Writing data The following requests create a new product. To convert the REST version of this request to GraphQL, you need to make the following changes in your code. > Tip: > The same changes need to be made when updating from a `POST`, `PUT`, or `DELETE` REST call.                               
Update Description
Change the endpointInstead of a resource-specific endpoint (/products/1234.json), use the generic GraphQL endpoint for the store. The details for the update that you want to make is now part of a GraphQL mutation that's passed in the request body.
Change the methodIf you're using a PUT or DELETE method, then update the method to POST.
Add a query Add a GraphQL mutation in the request body. In this example, we're creating a new product.
Add query variables

Pass the details for the resource that you want to create or update as query variable.

If you're updating or deleting a resource, then instead of using a simple ID (1234), use the GraphQL API global ID (GID) for the resource (gid://shopify/Product/1234).

Destructure the response

GraphQL responses are typically nested within a data object. The structure of the data mirrors the structure of the query. To make the data easier to work with, destructure the object that's returned.

You can also access properties of the object using dot notation (body.data.product).

Read userErrors Extract the userErrors array from the response. If the mutation wasn't completed, then this information is returned in this array. Learn about how error handling differs in GraphQL.