Home
Blog
Showcase
Community
Introduction
Overview
Introduction To TinaCMS
Getting Started
Using the Tina Editor
FAQ
Core Concepts
Content Modeling
Data Fetching
Visual Editing
Querying Content
Overview
Writing custom queries
Editing
Overview
Markdown & MDX
Block-based editing
Single Document Collections
Customizing Tina
Overview
Validation
Custom Field Components
Custom List Rendering
Format and Parse Input
Filename Customization
Before Submit function
Going To Production
Overview
Tina Cloud
Self-Hosted
Drafts
Overview
Draft Fields
Editorial Workflow
Guides
Overview
Framework Guides
Separate Content Repo
Querying Tina Content at Runtime
Internationalization
Migrating From Forestry
Further Reference
Overview
Config
Schema
The "tina" folder
The TinaCMS CLI
Media
Search
Content API
Tina's edit state
The "tinaField" helper
Self-Hosted Components

Introduction

With Tina, your content is stored in Git along with your codebase. Tina provides a Content API in front of your repo-based content, so that you can interact with your files as if they're in a database.

You can:

  • Query content for a given collection
  • Apply filters, sorting, pagination, etc
  • Query your content based on relational fields.

To interface with the API, you can use Tina's type-safe client for data-fetching, or manually write custom GraphQL queries and hit the API yourself.

Making requests with the Tina Client

The Tina client is the easiest way to fetch your site's content. The client can be configured the tina/config.<js|ts> in the defineConfig function.

Note: token, clientId and branch are not used in local-mode. To setup these values for production see this doc
// tina/config.{js,ts,tsx}
export default defineConfig({
schema,
token: '***',
clientId: '***',
branch: 'main',
})

When working locally, the client is built with the local url (http://localhost:4001/graphql). When in production mode, clientId, branch and token are used to query TinaCloud.

Tina client provides a type-safe query builder, that is auto-generated based on your site's schema:

import { client } from '../[pathToTina]/tina/__generated__/client'
const myPost = await client.queries.post({ relativePath: 'HelloWorld.md' })
console.log(myPost.data.title)

The above client.queries.post query is not built-in to Tina's API. This is an example of a query based on your defined schema, (where you have a "post" collection defined).

On a page that displays a list of posts, you can fetch the posts like so:

const postsResponse = await client.queries.postConnection()
const posts = postsResponse.data.postConnection.edges.map((post) => {
return { slug: post.node._sys.filename }
})
// This would return an array like: [ { slug: 'HelloWorld.md'}, /*...*/ ]
For more information on manually writing queries for your specific schema, check out our "Writing Custom Queries" docs.

The Local Filesystem-based Content API

When developing locally, it's often beneficial to talk to the content on your local file-system, rather than talk to the hosted content API. Tina provides a CLI tool that lets you run the Content API locally next to your site. This allows all of your content to be made available through the same expressive GraphQL API during development.

If you setup Tina via @tinacms/cli init, or used one of our starters, this should be setup by default. (Read about the CLI here

Video Tutorial

For those who prefer to learn from video, you can check out a snippet on "Data Fetching" from our "TinaCMS Deep Dive" series.

Summary

  • Tina provides a GraphQL API for querying your git-based content.
  • Tina provides a client that allows you to make type-safe requests to the Content API.
  • The client's "queries" property is generated based on your schema.
  • A local version of the Content API can be used for local development.
Previous
Content Modeling with TinaCMS
Next
Visual Editing

Product

Showcase
TinaCloud
Introduction
How Tina Works
Roadmap

Resources

Blog
Examples
Support
Media

Whats New
TinaCMS
TinaCloud
Use Cases
Agencies
Documentation
Teams
Jamstack CMS
Benefits
MDX
Markdown
Git
Editorial Workflow
Customization
SEO
Comparisons
TinaCMS vs Storyblok
TinaCMS vs Sanity
TinaCMS vs DecapCMS
TinaCMS vs Contentful
TinaCMS vs Builder.io
TinaCMS vs Strapi
Integrations
Astro
Hugo
NextJS
Jekyll