
A Shopify GraphQL bulk result is not one big JSON document. It is JSON Lines: one object per line. Nested connections, such as Order.lineItems, are pulled out into their own lines and get a __parentId. That sounds like a simple parent-child import until refunds enter the query.
Order.refunds is a GraphQL list, not a connection. Refund headers therefore remain as an array inside the order line. In our generated Shopify-shaped fixture, 9 JSONL lines became 3 orders, 6 line items and 2 refunds. All six item links came from __parentId; neither refund needed it.
The query creates a mixed shape
The bulk API walks connection nodes. The root orders connection supplies order lines. The nested lineItems connection supplies child lines with __parentId. The refunds list is ordinary data on each order object. This distinction also explains a Shopify bulk-query limitation: a connection such as refundLineItems cannot sit below the refunds list in the same bulk query. Fetch detailed refund line items separately if you need them.
Three representative lines
Do not identify a record only by testing whether __parentId exists. A query with several nested connections can produce different child types. The stable discriminator is the GID prefix: gid://shopify/Order/, LineItem/ and Refund/. Keep the full GID as text; stripping it to a number creates unnecessary assumptions.
Tables for PostgreSQL, MySQL and SQLite
This DDL runs with small type changes across the three engines: use timestamptz in PostgreSQL or datetime in MySQL for the time fields after parsing ISO 8601; SQLite can keep the original text. PostgreSQL numeric and MySQL decimal(20,4) preserve money exactly. SQLite stores numeric with dynamic affinity, so for accounting imports we prefer integer minor units plus an explicit currency exponent.
A streaming loader that does not depend on line order
Run it as python load_shopify.py < orders.jsonl. It reads one line at a time, so memory use does not grow with the export. It also does not assume children immediately follow a parent. Shopify now defaults groupObjects to false; grouping can slow an operation and raise its timeout risk, while the foreign key already carries the relationship.
Load parent rows first
Import orders before both child tables so the foreign keys can be checked. For a repeatable sync, load into staging tables, validate, then upsert by GID in one transaction. Never delete production rows merely because a partial bulk result omitted them: a failed operation can expose only partialDataUrl. Treat that as incomplete.
What the nine-line fixture produced
The generated fixture has no shipping, tax or order-level discount, so its six item totals also add to $119.00. That equality is a fixture check, not a universal Shopify rule. In real orders, compare item discounted totals with the order subtotal, then reconcile shipping, tax, duties and discounts to totalPriceSet. Refunds are separate again.
Four checks before you trust the tables
All four checks returned zero problem rows on the fixture. On a real export, also compare your parsed counts with the bulk operation's objectCount and rootObjectCount. Remember that objectCount counts connection objects, not refund objects embedded in an order line.
Refund money is not the same as a successful refund payment
Shopify documents one more accounting trap: a Refund object can exist before money has actually reached the customer. The payment status lives on associated order transactions. If this import feeds a ledger rather than a returns report, fetch and retain refund transactions and count only the statuses your accounting policy accepts.
Related: Nested JSON to CSV explains how choosing one row per order differs from one row per item. Shopify, Square and ad spend in one weekly table covers the reporting grain after the load.
Use Data Converter to inspect a small JSON or JSONL slice, turn it into CSV and check that long IDs stay exact before loading the full export.
Open Data ConverterOpen the three tables in Pilotbase, run the reconciliation queries and inspect any unmatched GIDs beside the source rows.
Get PilotbaseSources and test note
Shopify, Perform bulk operations with the GraphQL Admin API, documents JSONL streaming, __parentId, grouping and partial result URLs. Shopify's BulkOperation reference documents object counts and the query limits. The Order reference defines totals and refunds; the Refund reference explains why transaction status matters. Counts and dollar checks above come from our generated nine-line Shopify-shaped fixture, parsed on 2026-11-27. No database performance claim is made.

