Hi there,
I am trying to write a general algorithm for parsing the JsonL output from a Graphql bulk query and converting it to an object graph (or rather, a tree) that is equivalent to the output given by the same query in non-bulk mode. I have some issues due to the way the __parentId field is used when objects are nested within another.
For instance, take the following query:
query MyDraftOrderQuery {
draftOrders(first: 5) {
edges {
node {
id
customer {
id
lastOrder {
id
paymentTerms {
id
paymentSchedules(first: 10) {
edges {
node {
id
__typename
}
}
}
}
}
}
paymentTerms {
id
paymentSchedules(first: 10) {
edges {
node {
id
__typename
}
}
}
}
}
}
}
}
In bulk mode, I get the following output (converted to a Json array for readability):
[
{
"id": "gid://shopify/DraftOrder/1521654268227",
"customer": {
"id": "gid://shopify/Customer/22810943586627",
"lastOrder": {
"id": "gid://shopify/Order/10024036860227",
"paymentTerms": { "id": "gid://shopify/PaymentTerms/54645981507" }
}
},
"paymentTerms": { "id": "gid://shopify/PaymentTerms/54645948739" }
},
{
"id": "gid://shopify/PaymentSchedule/53899329859",
"__typename": "PaymentSchedule",
"__parentId": "gid://shopify/DraftOrder/1521654268227"
},
{
"id": "gid://shopify/PaymentSchedule/53899297091",
"__typename": "PaymentSchedule",
"__parentId": "gid://shopify/DraftOrder/1521654268227"
}
]
In non-bulk mode, I get this output:
{
"data": {
"draftOrders": {
"edges": [
{
"node": {
"id": "gid://shopify/DraftOrder/1521654268227",
"customer": {
"id": "gid://shopify/Customer/22810943586627",
"lastOrder": {
"id": "gid://shopify/Order/10024036860227",
"paymentTerms": {
"id": "gid://shopify/PaymentTerms/54645981507",
"paymentSchedules": {
"edges": [
{
"node": {
"id": "gid://shopify/PaymentSchedule/53899329859",
"__typename": "PaymentSchedule"
}
}
]
}
}
}
},
"paymentTerms": {
"id": "gid://shopify/PaymentTerms/54645948739",
"paymentSchedules": {
"edges": [
{
"node": {
"id": "gid://shopify/PaymentSchedule/53899297091",
"__typename": "PaymentSchedule"
}
}
]
}
}
}
}
]
}
}
As can be seen in the non-bulk output, the two payment schedule objects are children of the top-level draft order object and the last order of the customer, respectively (or rather, the payment terms of those orders). However, in the JsonL output, the __parentId field is set to the top-level draft order for both payment schedule objects. This makes it impossible to re-attach them to their correct parent as far as I can tell.
Is this behavior intentional? If yes, is there a way to generate a correct object graph from the JsonL output in this case?