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, Name and Type
- 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 give 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 path for the plants folder in the demo tenant.
In Crystallize, you can define shapes for your items in order to have a more semantic structure. The shape field includes information such as the shape name, the identifier, the creation data, etc.
Language and Path
Any item - be it a product, a document or a folder can be translated to multiple languages. The following query asks for the language and the path of a particular item.
Similar to how the child items are fetched, you can fetch the parent item as well. The example query below fetches the parent item of the plants folder.
Get Date and Time
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 lastly the date an item was published. The following query asks for the aforementioned fields for a document.
One of the components provided in the catalogue 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 similar to how the children field works. However, when you want to slice items or for 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, switch component, images, videos, etc. The following query asks for all the components present on the path specified. For simplicity's sake, we are only asking for the content if it's a rich text component or if it's an image one.
In case, you only want to grab a single component, you can ask for the component field. The component field requires the id 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, a document or a folder, you can do the following:
Fields Specific to Product Items
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 product, you will ned to use the product type in the query.
This field fetches the vat type of a product and can be queried as follows:
isVirtual and isSubscriptionOnly
Both of these fields return a boolean value as shown in the query below.
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.