At its core, GraphQL queries simply ask for certain fields on objects. This section covers the query fields associated with the items present in the catalogue.
- id: Every item in the catalogue has its own unique id, which can be queried using this field.
- name: Refers to the name you have given to an item.
- type: Returns the type of an item i.e. whether it's a document, a folder, or a product.
Here's a query that asks for the id, name, and type for the plants folder in the demo tenant.
In Crystallize, you can define shapes for your items to have a more semantic structure. The shape field includes information such as the shape name, the identifier, creation data, etc.
Any item, be it a product, a document, or a folder, can be translated into multiple languages. The following query asks for the name, language, and path of a particular item.
Folders usually have more items inside of them. The query below fetches all the items within the plants folder in the demo tenant.
Similar to how the child items are fetched, you can fetch parent items as well. The example query below fetches the parent item of the plants folder.
Using the Catalogue API, you can ask for the following fields for any item: the date the item was created, the date it was uploaded, and the date it was published. The following query asks for the aforementioned fields for a document.
One of the components provided in the catalog is the Item Relation component. Through this component, you can link related items to a particular item. This field can be queried as follows:
The subtree field works similarly to how the children field works. However, when you want to slice items or when you want to add pagination, this is the field you would use. This field is discussed in more detail in the pagination section. Let's say you want to fetch only the top 3 items within a folder, this is how you can do it:
A collection of components is what makes up a shape in Crystallize. This includes single line component, rich text, videos, file, etc. The following query asks for all the components present on the path specified. For simplicity's sake, we’re only retrieving rich text and image component information.
In case you only want to grab a single component, you can ask for the component field. The component field requires the identifier of the component you would like to fetch. The query below fetches the rich text component with the id of “brief.”
Any of the items defined in Crystallize can have multiple topics attached to them. To fetch all the topics associated with a product, document, or folder, you can do the following:
As mentioned above, there are some fields that are specific to products only. This includes vatType, isVirtual, isSubscriptionOnly, variants, and defaultVariants. Let's take a look at each of these in more detail.
Note: Keep in mind that since these fields are specific to the product, you will need to use the product type in the query.
This field fetches the VAT type of a product and can be queried as follows:
In Crystallize, you can add any number of variants to a product. These variants can then be fetched as follows:
Additionally, the variant field allows you to fetch data including images, price, SKU, name, subscriptionPlans, attributes, stock, etc.
In case you only want to fetch the default variant, you can use this field instead. It simply fetches the default variant and its related information such as images, price, SKU, name, subscriptionPlans, attributes, stock, etc.
This is the property that will return the stock for each location. Stock locations are defined under Settings in Crystallize.
Each variant will have its own set of values for the different locations. The locations can also have unlimited stock when no minimum value is defined, and this is good for products that don't have stock (i.e. virtual products).