GraphQL Fragments

Learn how to work with GraphQL Fragments inside Queries and Mutations together with variables, and nested fragments.

Notes

  • https://api.cartql.com
fragment currencyFields on Currency {
code
symbol
}
fragment moneyFields on Money {
amount
currency {
...currencyFields
}
formatted
}
fragment cartInfo on Cart {
id
totalItems
totalUniqueItems
items {
id
name
quantity
unitTotal {
...moneyFields
}
lineTotal {
...moneyFields
}
}
subTotal {
...moneyFields
}
}
query getCartById($id: ID!) {
cart(id: $id) {
...cartInfo
}
}
mutation addItem($cartId: ID!) {
addItem(input: {cartId: $cartId, id: "new-item-id", name: "New product", price: 1000}) {
...cartInfo
}
}
Jamie Barton

Published on 25 Oct 2021 by Jamie Barton