xclade
GraphQL API

Migration from REST

Migrating from REST to GraphQL

Migration from REST

GraphQL provides significant advantages over REST for many use cases:

REST Request Pattern

// Multiple REST requests required
const product = await fetch('/store/products/prod_123');
const collection = await fetch(`/store/collections/${product.collection_id}`);
const variants = await fetch(`/store/products/${product.id}/variants`);

// Total: 3 requests, over-fetching in each response

GraphQL Request Pattern

// Single GraphQL request
const result = await graphqlRequest(`
  query GetProduct($id: String!) {
    product(id: $id) {
      id
      title
      collection {
        id
        title
      }
      variants {
        id
        title
      }
    }
  }
`, { id: 'prod_123' });

// Total: 1 request, exact data needed

When to Use GraphQL vs REST

Use GraphQL when:

  • You need precise control over response data
  • You are fetching related resources
  • Mobile apps require minimal bandwidth
  • You are building complex UIs with varying data needs
  • You want to reduce API requests

Use REST when:

  • Simple CRUD operations on single resources
  • File uploads or downloads
  • Webhooks or callbacks
  • Third-party integrations with REST-only support

On this page