Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Re: How do I query Order.Returns.ReturnLineItems when it is ReturnLineItemType instead of ReturnLine

Solved

How do I query Order.Returns.ReturnLineItems when it is ReturnLineItemType instead of ReturnLineItem

FRBen
Shopify Partner
2 1 1

Order.Returns has a connection to ReturnLineItems https://shopify.dev/docs/api/admin-graphql/2024-07/objects/Return#connection-returnlineitems

ReturnLineItems points to the type ReturnLineItemType https://shopify.dev/docs/api/admin-graphql/2024-07/interfaces/ReturnLineItemType

ReturnLineItemType does not contain the FulfillmentLineItem.LineItem.Sku which is what I need to complete my query.

This information is important because its used to compare a Order.LineItem SKU with a Return LineItem SKU to determine if the item in the order was returned. I am trying to determine this without writing an entire new query just to retrieve orders.

Is this possible?

Here is my query written in Go syntax:

type GraphQLOrder struct {
	ID                       string
	Test                     bool
	Name                     string
	Email                    string
	DisplayFinancialStatus   string
	DisplayFulfillmentStatus string
	ReturnStatus             string
	Note                     string
	ClientIP                 string
	ClosedAt                 *time.Time
	CancelledAt              *time.Time
	Tags                     []string
	CreatedAt                time.Time
	UpdatedAt                *time.Time
	CustomAttributes         []struct {
		Key   string
		Value string
	}
	Customer struct {
		Email string
	}
	LineItems struct {
		Nodes []GraphQLLineItem
	} `graphql:"lineItems(first: 100)"`
	Returns struct {
		Nodes []struct {
			ID                string
			Status            string
			totalQuantity     int64
			ExchangeLineItems struct {
				Nodes []struct {
					LineItem struct {
						SKU      string
						Name     string
						Quantity int64
					}
				}
			} `graphql:"exchangeLineItems(first: 10)"`
			// Returns only has connection to ReturnLineItemType which does not contain FulfillmentLineItem.LineItem
			/* 						ReturnLineItems struct {
				Nodes []struct {
					RefundableQuantity int64
					RefundedQuantity   int64
					ReturnReason       string
					ReturnReasonNote   string
					CustomerNote       string
													 FulfillmentLineItem struct {
						quantity int64
						LineItem struct {
							Name string
							SKU  string
						}
					} `graphql:"FulfillmentLineItem(first: 10)"`
				}
			} `graphql:"returnLineItems(first: 10)"` */
		}
	} `graphql:"returns(first: 10)"`
	Refunds []struct {
		ID              string
		CreatedAt       time.Time
		UpdatedAt       *time.Time
		Note            string
		RefundLineItems struct {
			Nodes []struct {
				Quantity    int64
				RestockType string
				LineItem    struct {
					SKU      string
					Name     string
					Quantity int64
				}
			}
		} `graphql:"refundLineItems(first:10)"`
	}
}

type OrdersGraphQL struct {
	Orders struct {
		Edges []struct {
			Node GraphQLOrder `graphql:"node"`
		}
		PageInfo struct {
			EndCursor   string
			HasNextPage bool
		}
	} `graphql:"orders(first: $first, after: $after)"`
}
Accepted Solution (1)
FRBen
Shopify Partner
2 1 1

This is an accepted solution.

I ended up finding the solution:

			ReturnLineItems struct {
				Nodes []struct {
					ReturnLineItem struct {
						RefundableQuantity  int64
						RefundedQuantity    int64
						ReturnReason        string
						ReturnReasonNote    string
						CustomerNote        string
						Quantity            int64
						FulfillmentLineItem struct {
							LineItem struct {
								Name string
								SKU  string
							}
						}
					} `graphql:"... on ReturnLineItem"`
				}
			} `graphql:"returnLineItems(first: 25)"`

 

View solution in original post

Replies 2 (2)

julian-p22
Shopify Partner
1 0 0

Experiencing the exact same issue: `Field 'fulfillmentLineItem' doesn't exist on type 'ReturnLineItemType`

FRBen
Shopify Partner
2 1 1

This is an accepted solution.

I ended up finding the solution:

			ReturnLineItems struct {
				Nodes []struct {
					ReturnLineItem struct {
						RefundableQuantity  int64
						RefundedQuantity    int64
						ReturnReason        string
						ReturnReasonNote    string
						CustomerNote        string
						Quantity            int64
						FulfillmentLineItem struct {
							LineItem struct {
								Name string
								SKU  string
							}
						}
					} `graphql:"... on ReturnLineItem"`
				}
			} `graphql:"returnLineItems(first: 25)"`