惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
Blog — PlanetScale
Blog — PlanetScale
B
Blog
GbyAI
GbyAI
爱范儿
爱范儿
月光博客
月光博客
N
Netflix TechBlog - Medium
T
Tailwind CSS Blog
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
腾讯CDC
MyScale Blog
MyScale Blog
V
Visual Studio Blog
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

The Astro Blog

Astro 6.4 Astro 6.3 Starlight 0.39 Astro 6.2 What's new in Astro - April 2026 What's new in Astro - March 2026 Astro 6.1 CloudCannon Joins Astro as an Official CMS Partner Astro 6.0 What's new in Astro - February 2026 What's new in Astro - January 2026 Astro 5.17 Supporting the future of Astro The Astro Technology Company joins Cloudflare Astro 6 Beta What's new in Astro - December 2025 What's new in Astro - November 2025 Astro 5.16 Stainless Sponsors Astro, Launches Astro-Powered Docs Platform What's new in Astro - October 2025 Astro 5.15 Spirit of Astro: meet the winning designs What's new in Astro - September 2025 Astro 5.14 Cloudflare Donates $150,000 to Support Astro's Open Source Mission Webflow Donates $150,000 to Support Astro's Open Source Mission Mux: Our Official Video Partner Unleashing creativity: How CodeTV built a video streaming platform with Astro and Mux | Astro What's new in Astro - August 2025 Astro 5.13
Astro x Hygraph: Content Loader
Matthew Phillips · 2024-09-19 · via The Astro Blog

We are excited to announce Hygraph as a launch partner for Astro Content Layer, our new approach to bringing external CMS content into content collections. Hygraph is an API-first CMS that lets you organize your complex, structured content and build high-performance, content-driven applications with any frontend technology.

Content collections allows you to combine content of various types into a single API. With Content Layer this now includes bringing in content from various external sources, such as Hygraph CMS.

Using the Hygraph loader

To use the new loader (in beta), first install the @hygraph/hygraph-astro-loader package:

npm install @hygraph/hygraph-astro-loader

In the Hygraph dashboard, find the endpoint of your API and copy the URL and provide it as an environment variable, naming it something like HYGRAPH_ENDPOINT.

Then import and use the loader inside of your src/content/config.ts configuration file:

import { defineCollection, z } from 'astro:content';

import { HygraphLoader } from '@hygraph/hygraph-astro-loader';

const pages = defineCollection({

loader: HygraphLoader({

endpoint: import.meta.env.HYGRAPH_ENDPOINT,

operation: 'pages',

fields: ["id", "title", "slug", { "body": ["text"] }],

}),

schema: z.object({

id: z.string(),

title: z.string({

required_error: 'Title is required'

}).min(1, {

message: 'Title is required to be at least 1 character'

}),

slug: z.string(),

body: z.object({

text: z.string(),

}),

})

})

export const collections = { pages }

And that’s it, from here you can query and use collections the same way you would for local collections. See the Astro docs on content collections to learn more.

Also check out yesterday’s deep dive on Content Layer to learn how loaders work, and how you can build your own. Also check out the Hygraph loader’s GitHub repo to report issues and contribute.