Queries

Caisy automatically generates queries for fetching your documents for each defined blueprint of your project. Depending, if your blueprint is defined as unique, you will have a query to fetch multiple entries.

Auto-generated queries

When a new blueprint is added to your project, there are one or more generated GraphQL queries added to your schema. Responsible for the name is the field API ID of the blueprint.

Single Queries

Lets you want to define a blueprint called MainNavigation. That is something that should only exist once. So you define it as a unique blueprint. The result will be that the External API will generate only this single query for you.

  • MainNavigation


Fetching a single entry

The MainNavigation query is what you would use now to fetch the single document that can exist from the External API.

If the blueprint is marked as unique you do not need to provide the id in the query.

{  MainNavigation {    id    title   }}

Plural queries

Plural queries come with their own generated arguments for filtering, ordering, paginated.

For example, let’s assume we have the model Page in our blueprint, and not make it unique. The following queries would be generated in the External API automatically:

  • Page

  • allPage

Fetching multiple entries

Now we can use the allPage query to retrieve multiple documents from the External API.

{
  allPage{
    edges{
      node{
        id
        slug
        title
      }
    }
  }
}

Fetching connections

Imagine we would connect our pages to the main navigation. To do so, you would need to update the MainNavigation blueprint with a connection field that is connecting the Page blueprint. Afterwards, if we want to query the MainNavigation together with the links to the Page, we could use the following query:

{
  MainNavigation{
    title
    id
    links{
      ... on Page {
        slug 
        id 
        title
      }
    }
  }
}