Since the output of bulk operations from GraphQL doesn't nest connections within each object, it can be tedious to correctly parse the file with the desired outcome. According to the docs, we can rely on the fact that children connections will always be listed after their parent, not directly after. A tip I picked up from @eapache, looping through the file in reverse order can make reading the data reliable with efficient memory loading.
Here's an example of how nested connections are added:
{"id":"gid:\/\/shopify\/Customer\/123456"}
{"id":"gid:\/\/shopify\/Metafield\/987654","key":"some_key","__parentId":"gid:\/\/shopify\/Customer\/123456"}
The ideal output:
{"id":"gid:\/\/shopify\/Customer\/123456","metafields":{"edges":[{"node":{"id":"gid:\/\/shopify\/Metafield\/987654","key":"some_key"}}]}}
My suggestion is that we build a helper utility to parse through the data in reverse order and nest any connections within a hash. This would make it easier for developers to quickly handle the data in an intuitive way.
Since the output of bulk operations from GraphQL doesn't nest connections within each object, it can be tedious to correctly parse the file with the desired outcome. According to the docs, we can rely on the fact that children connections will always be listed after their parent, not directly after. A tip I picked up from @eapache, looping through the file in reverse order can make reading the data reliable with efficient memory loading.
Here's an example of how nested connections are added:
The ideal output:
My suggestion is that we build a helper utility to parse through the data in reverse order and nest any connections within a hash. This would make it easier for developers to quickly handle the data in an intuitive way.