How can I retrieve the transactions.paymentDetails for an Order?

Topic summary

A user migrating from REST to GraphQL encountered an error when querying payment details for orders. The initial attempt to access CardPaymentDetails directly within paymentDetails failed with a “selections can’t be made directly on unions” error.

Solution Found:
The issue was resolved using GraphQL’s inline fragment syntax for union types:

paymentDetails { 
  ... on CardPaymentDetails { 
    company 
    paymentMethodName 
  } 
}

Follow-up Question:
Another user requested clarification on the complete syntax, specifically asking about the ... (inline fragment operator) and whether etc was placeholder text or actual syntax. This question remains unanswered, leaving the thread open for further explanation of the union query pattern.

Summarized with AI on October 28. AI used: claude-sonnet-4-5-20250929.

I’m migrating from REST to GraphQL, so I’m fairly new with GraphQL. When retrieving orders I have figured out most of what I need, but I’m having trouble getting the payment details transactions for the order. If I add the following section to my query for example:

paymentDetails { CardPaymentDetails { paymentMethodName } }

I get the following error:

{“errors”:[{“message”:“Selections can’t be made directly on unions (see selections on PaymentDetails)”,“locations”:[{“line”:1,“column”:857}],“path”:[“query”,“orders”,“nodes”,“transactions”,“paymentDetails”,“CardPaymentDetails”],“extensions”:{“code”:“selectionMismatch”,“nodeName”:“PaymentDetails”}}]}

Anyone have an idea on how I get around this?

I found the answer. The following gets me into the CardPaymentDetails section:

paymentDetails { … on CardPaymentDetails { company paymentMethodName etc } }

Would you please share the full syntax or a link that better explains building out this union? I am not sure about the “…” or the etc.

paymentDetails { … on CardPaymentDetails { company paymentMethodName etc } }

Thank you for help.

Randy