0

I am working on a shopify integration, and I am trying to perform some bulk queries which return data in jsonl format. I read carefully the documentation, and I understood which is the principle behind this format, but there is one thing I don't understand: the following is a portion of my jsonl file representing the first item in the result

{"id":"gid:\/\/shopify\/Product\/6755349070004","options":[{"id":"gid:\/\/shopify\/ProductOption\/8677003133108","name":"Città","position":1}],"title":"Product title","productType":"Concerto Live"}
{"id":"gid:\/\/shopify\/ProductVariant\/40163436363956","price":"100.00","title":"MIlano","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/ProductVariant\/40163436396724","price":"100.00","title":"Roma","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/ProductVariant\/40163436429492","price":"100.00","title":"Firenze","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/Collection\/272323707060","description":"Product variant description","title":"CONCERTI","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/Collection\/272323739828","description":"Product variant description","title":"LIVE","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}
{"id":"gid:\/\/shopify\/Collection\/273036607668","description":"Product variant description","title":"Product variant description","__parentId":"gid:\/\/shopify\/Product\/6755349070004"}

and it's obtained by the following query

mutation {
  bulkOperationRunQuery(
    query: """
          {
                    items: products{
                        pageInfo {
                          hasNextPage
                        }
                        edges {
                          cursor
                          node {
                            id
                            variants(first: 10) {
                              edges {
                                node {
                                  id
                                  price
                                  title
                                }
                              }
                            }
                            options(first: 5) {
                              id
                              name
                              position
                            }
                            title
                            collections(first: 8) {
                              edges {
                                node {
                                    id
                                  metafields(first: 5) {
                                    edges {
                                      node {
                                        id
                                        key
                                        namespace
                                        value
                                      }
                                    }
                                  }
                                  description
                                  title
                                }
                              }
                            }
                            productType
                            images(first: 2) {
                              edges {
                                node {
                                  src
                                }
                              }
                            }
                          }
                        }
                      }
                  }

    """
  ) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}

So The first line it the "main" product object, the lines 2,3 and 4 are the variants, then we have the collections and then the image: the problem is that, besides the parent's id, there is no way to know which parent's property a child line refers to. If I want to build back a json from this, how can I know for example that the second line is an item of the array in products.variants?

Apperside
  • 3,542
  • 2
  • 38
  • 65

1 Answers1

0

You can use either:

  1. the id format (gid://shopify/Product/6755349070004 is a product)
  2. the __typename property that exists on all GraphQL objects
Eugene Kim
  • 496
  • 4
  • 17