Tina Docs
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
Introduction
Getting Started
Querying Content
User Management
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

Querying Content in Self-hosted Backend

Table of Contents

Overview

When using TinaCloud, you would typically use the TinaCMS client to query your content.

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

Under the hood, this uses the fetch api to request data from TinaCloud.

When self-hosting, since your database content is fully scoped to your project, you're able to communicate with the database directly. We provide a separate databaseClient that can be used to query data from the database.

- import { client } from '../[pathToTina]/tina/__generated__/client'
+ import { client } from '../[pathToTina]/tina/__generated__/databaseClient'
// ...

This databaseClient should be used when querying data on the server. For example: getStaticProps, getServerSideProps, or using React Server Components, etc.

How does it work?

The databaseClient uses the exported database in your database.{ts,js}. It creates a GraphQL resolver that uses the database to retrieve data from the database.

Usage

The databaseClient has the same interface as the TinaCMS client. This means you can use it in the same way you would use the TinaCMS client.

import databaseClient from '../tina/__generated__/databaseClient'
//...
const res = await databaseClient.queries.postConnection()
Previous
Migrating from TinaCloud to Self-Hosted
Next
User Management

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