Rename GraphQL fields with aliases

Rename fields in responses, and request the same field with different arguments as new fields with GraphQL aliases.

{
  cart(id: "my-cart-id") {
    count: totalItems
    products: items {
      title: name
      created: createdAt
    }
  }

  cart2: cart(id: "abc") {
    id
    totalItems
  }
}
mutation {
  addToCart: addItem(
    input: {
      cartId: "my-cart-id"
      id: "my-item-id"
      name: "GraphQL Stickers"
      price: 1000
    }
  ) {
    id
    items {
      title: name
      lineTotal {
        amount
        formatted
      }
    }
  }
}
Jamie Barton

Published on 23 Aug 2021 by Jamie Barton