Resolving GraphQL Query Error in Order Transactions: Seeking Suggestions

Hello Everyone,

I encountered a problem while attempting to retrieve order transactions using GraphQL. I seem to have hit a wall and would greatly appreciate any help from this forum.

Here is a brief overview of my issue: While executing my GraphQL query for retrieving order transactions, I’m receiving an error response that I can’t seem to resolve. I’ve pasted the GraphQL query and the error response below for your reference.

While my main aim isn’t solely focused on retrieving the ‘PaymentDetails’ associated with these transactions, it is nonetheless an important part of the data I require. Unfortunately, the current query doesn’t appear to fetch this data as expected. I’m uncertain whether this requires a separate call or if there is a different approach to obtain this information along with other data.

Based on the order data I have, how should I modify my query to successfully extract the payment details? If a separate call is indeed required, could someone kindly guide me through the process?

I’m eager to learn and would be incredibly grateful for any advice, guidance, or resources that you could share to help me troubleshoot this issue.

Thank you in advance for your time and support.

Query:

{
  order(id: "gid://shopify/Order/{$orderId}") {
    transactions {
        id
        accountNumber

        amountSet{
           presentmentMoney{
                amount
                currencyCode
           }
           shopMoney{
                amount
                currencyCode
           }
        }

        authorizationCode
        authorizationExpiresAt
        createdAt
        errorCode

        fees {
            id
            amount {
                amount
                currencyCode
            }
            flatFee {
                amount
                currencyCode
            }
            flatFeeName
            rate
            rateName
            taxAmount {
                amount
                currencyCode
            }
            type
        }

        gateway
        kind
        maximumRefundableV2 {
            amount
            currencyCode
        }
        order{
            id
        }
        parentTransaction {
            accountNumber
        }
        paymentDetails{
            CardPaymentDetails{
                avsResultCode
            }
        }
        paymentIcon{
            altText
            height
            width
            id
            url
        }
        paymentId
        processedAt
        receiptJson
        settlementCurrency
        settlementCurrencyRate
        status
        test
        totalUnsettledSet{
            presentmentMoney{
                amount
                currencyCode
           }
           shopMoney{
                amount
                currencyCode
           }
        }
    }
  }
}

Error:

{
  "errors": [
    {
      "message": "Selections can't be made directly on unions (see selections on PaymentDetails)",
      "locations": [
        {
          "line": 55,
          "column": 9
        }
      ],
      "path": [
        "query",
        "order",
        "transactions",
        "paymentDetails",
        "CardPaymentDetails"
      ],
      "extensions": {
        "code": "selectionMismatch",
        "nodeName": "PaymentDetails"
      }
    }
  ]
}
[]

Best regards,

Denys

I’m interested in this solution too.

You have the error in section:

paymentDetails**{ }**

It should be like this:

paymentDetails {
   ... on CardPaymentDetails {
          avsResultCode
   }
}

Thanks!!
I can do it.Actualy I did not know the following rules of GraphQL.

"... on" to specify a field for each type of Union.