# Use cases

By
The Quable Team

Data extraction with the GraphQL API depends on your PIM's data model, which can lead to the following use cases:

  1. You want to extract a all documents, their linked resources and all their assets. Your GraphQL query might look like this:
query {
  documents {
    id
    attributes
    documentLinks {
      document {
        id
        assetLinks {
          asset {
            id
          }
        }
      }
    }
    classifications {
      id
      catalogId
      assetLinks {
        asset {
          id
        }
      }
    }
    variants {
      id
      attributes
      assetLinks {
        asset {
          id
        }
      }
    }
    assetLinks {
      asset {
        assetLinks {
          asset {
            id
          }
        }
      }
    }
  }
}
  1. Given you have a multi-layered data model in the wine industry, here’s a visual breakdown of the structure :

At the root, you have a product document that links to its parent batch. Each batch is connected to a domain and each domain belong a classification.
Additionally, each product is linked to a bundle of documents and cross-sell options for other products. You want to retreive all resources with their assets.

document (product)
  β”œβ”€β”€ document (batch)
  β”‚   └── asset
  β”‚     └── document (domain)
  β”‚           └── asset
  β”‚           └── classification
  β”‚                 └── asset
  β”œβ”€β”€ variant
  β”‚   └── asset
  β”œβ”€β”€ bundle (list of documents of various types)
  β”‚   └── asset
  β”œβ”€β”€ cross-sell (list of documents of product type)
  β”‚   └── asset
  └── asset

Thus, your GraphQL query might look like this:

query {
  documents(documentType: "product") {
    id
    attributes
    documentLinks(
      linkNames: [
        "link_product_bundle"
        "link_product_cross_sell"
        "link_batch_to_product"
      ]
    ) {
      document {
        id
        documentLinks(linkNames: ["link_domain_to_batch"]) {
          document {
            id
            classifications {
              id
              catalogId
              assetLinks {
                asset {
                  id
                }
              }
            }
            assetLinks {
              asset {
                id
              }
            }
          }
        }
        assetLinks {
          asset {
            id
          }
        }
      }
    }
    variants {
      id
      attributes
      assetLinks {
        asset {
          id
        }
      }
    }
  }
}

You can reverse the query, to retrieve all domains along with their classifications, then the linked batch and finally the product of each batch.

query {
  documents(documentType: "domain") {
    id
    attributes
    classifications {
      id
      catalogId
      assetLinks {
        asset {
          id
        }
      }
    }
    assetLinks {
      asset {
        id
      }
    }
    documentLinks(linkNames: ["link_domain_to_batch"]) {
      document {
        id
        documentLinks(linkNames: ["link_batch_to_product"]) {
          document {
            id
            documentLinks(
              linkNames: ["link_product_bundle", "link_product_cross_sell"]
            ) {
              document {
                id
                assetLinks {
                  asset {
                    id
                  }
                }
              }
            }
            assetLinks {
              asset {
                id
              }
            }
          }
        }
        assetLinks {
          asset {
            id
          }
        }
      }
    }
  }
}

You can also request to retrieve only products with a completeness status of "live_product" at 100% and only domains that carry the "premium_quality" tag

query {
  documents(documentType: "domain", filters: { tags: ["premium_quality"] }) {
    id
    attributes
    classifications {
      id
      catalogId
      assetLinks {
        asset {
          id
        }
      }
    }
    assetLinks {
      asset {
        id
      }
    }
    documentLinks(linkNames: ["link_domain_to_batch"]) {
      document {
        id
        documentLinks(
          linkNames: ["link_batch_to_product"]
          filters: {
            completeness: {
              code: "live_product"
              localeCode: "fr_FR"
              operator: EQ
              value: 1
            }
          }
        ) {
          document {
            id
          }
        }
        assetLinks {
          asset {
            id
          }
        }
      }
    }
  }
}