Tina Docs
Introduction
Core Concepts
Querying Content
Editing
Customizing Tina
Going To Production
Media
Drafts
Guides
Further Reference

Querying a single document

Get a single document, providing it's relativePath as the argument.

  • relativePath is the portion of the path relative to the collection's path.

In this example, the post collection has a path of content/posts and your document can be found at content/posts/voteForPedro.md giving relativePath: "voteForPedro.md". If your item was at content/posts/nested-folder/voteForPedro.md you'd specify: relativePath: "nested-folder/voteForPedro.md".

Our collections for the above schema are named "post" and "author", so we can query for each using the post & author

Examples

Query on author only.

{
author(relativePath: "napolean.json") {
name
}
}
{
"data": {
"author": {
"name": "Napolean"
}
}
}

Query on post and author.

{
post(relativePath: "voteForPedro.json") {
title
category
author {
... on Author {
name
}
}
}
}
{
"data": {
"post": {
"title": "Vote For Pedro",
"category": "politics",
"author": {
"name": "Napolean"
}
}
}
}

Query post on author.

{
author(relativePath: "napolean.json") {
name
post {
edges {
node {
title
}
}
}
}
}
{
"data": {
"author": {
"name": "Napolean",
"post": {
"edges": [
"node": {
"title": "Vote for Pedro",
}
]
}
}
}
}

Common fields

In a collection, there are a few fields that are common to all documents. These are: id, _values and _sys. The id field is a unique identifier for the document. The _values field is used internally in edit mode and is not for external use. The _sys field contains meta information about the document.

The _sys field is an object with the following fields:

  • filename: The name of the file without the extension
  • basename: The name of the file with the extension
  • path: The full path of the file relative to the project root
  • breadcrumbs: An array of the parent folders of the file
  • relativePath: The path of the file relative to the collection path
  • extension: The extension of the file
  • template: The template of the document (or the name of the collection if not using templates)
  • collection: Information about the collection

Example with a nested folder

{
post(relativePath: "nested/anotherPost.json") {
id
_sys {
filename
basename
path
breadcrumbs
relativePath
extension
template
}
}
}
{
"data": {
"post": {
"id": "content/posts/nested/anotherPost.json",
"_sys": {
"filename": "anotherPost",
"basename": "anotherPost.json",
"path": "content/posts/nested/anotherPost.json",
"breadcrumbs": [
"nested",
"anotherPost"
],
"relativePath": "nested/anotherPost.json",
"extension": ".json",
"template": "post"
}
}
}
}

Example without a nested folder

{
post(relativePath: "anotherPost.json") {
id
_sys {
filename
basename
path
breadcrumbs
relativePath
extension
template
}
}
}
{
"data": {
"post": {
"id": "content/posts/anotherPost.json",
"_sys": {
"filename": "anotherPost",
"basename": "anotherPost.json",
"path": "content/posts/anotherPost.json",
"breadcrumbs": [
"anotherPost"
],
"relativePath": "anotherPost.json",
"extension": ".json",
"template": "post"
}
}
}
}

Last Edited: August 15, 2024