Optimizing Gift Card Queries by Customer and Recipient in Shopify GraphQL API

Optimizing Gift Card Queries by Customer and Recipient in Shopify GraphQL API

gnovo
Shopify Partner
1 0 0

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:

  1. For purchased gift cards: We query gift cards associated with a specific customer ID.
  2. 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!

Replies 0 (0)