I’m using the Shopify GraphQL API to show a list of gift cards associated with a user on their dashboard, where they can view both purchased and received gift cards.
Currently, we’re making two separate requests:
- For purchased gift cards: We query gift cards associated with a specific customer ID.
- For received gift cards: We paginate through all gift cards and use JavaScript to filter by recipient email.
Here’s the query we’re using for purchased gift cards:
query {
giftCards(first: 50, query: "customer_id:123", reverse: true, sortKey: CREATED_AT) {
edges {
node {
balance {
amount
currencyCode
}
createdAt
customer {
email
firstName
id
}
deactivatedAt
enabled
expiresOn
id
initialValue {
amount
currencyCode
}
lastCharacters
maskedCode
recipientAttributes {
message
recipient {
email
firstName
id
lastName
}
}
}
}
}
}
Is there a way to combine these into a single query or streamline this process so we can retrieve both purchased and received gift cards in a more efficient way?
Thanks in advance!