api-reference > graphql

Documents

Last updated Invalid Date

To make Document queries, first create a Document. Remember that all Documents depend on a Template. In this example, the Template we used to create this Document is called Page. You can see this output in the API tab of any Document within the Tipe dashboard.

graphql
query API {
  Page(id: "YOUR_PAGE_ID") {
    # your blocks API ID goes here
    # for example, your Block name is `Title`
    # which is converted to camelcase `title`
  }
}

When you name a Block, the API ID is generated and the name is converted to camelCase, so Title becomes title and Featured Image becomes featuredImage. We also do this for Template names but they are converted to TitleCase so my folder becomes MyFolder. So, in the API tab, you'll see title and featuredImage. So the query would look like this:

graphql
query API {
  <template-api-id>Page(id: "<document-id>") {
    <block-api-id>
    <block-api-id>
    <block-api-id>
  }
}

You can find this in the code example in the API tab as a string. However, you can also use it to create a .graphql file if you're using an Apollo client for more advanced use-cases.

With GraphQL you declare the fields you want to get and the shape is like json without the values. For example, if you want the following json result:

json
{
  testing: ‘ok’
}

You have to create a model on the server called Test. So for Tipe, you'd create a Template, which serves as the model. As an example, take a Template called Test and query it with GraphQL.

graphql
query API {
  Test {
    testing
  }
}

The query API {} part of our query allows us to name the query, a feature in GraphQL which allows us to pass variables, but in this example we’re hard coding our IDs. Here, we're asking for a Test using the Template API ID and writing out the Blocks we want with the corresponding Block API ID testing. Now we need to add the Document id, so we pass id: "1111" in Test, where the 1111 is the id.

graphql
query API {
  Test(id: "1111") {
    testing
  }
}

In the API tab of a Document, you'll notice that the id is dynamic, as in id: $id.

Because the id is 1111 we can hard code it as an argument when requesting Test. In this way, the server knows which Test to get. If you wanted to get all Test documents, you'd do the following:

graphql
query API {
  allTests(id: "1111") {
    testing
  }
}

Notice how we added all<template-api-id>sall and plural version of the Template name, thus allTests. Templates in Tipe auto-generate queries for a Document by using the Template name or, in the case of multiple Documents, all<template-name>s.

We also provide metadata, or system information, as a _meta object. Notice that if we have an object we need to expand it with { } and within the curly braces, declare which fields we want.

graphql
query API {
  allTests(id: “1”) {
    testing
    _meta {
      id
      name
    }
  }
}

Go further

Query Folders

Learn about how to query Folders with GraphQL.