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

推荐订阅源

MyScale Blog
MyScale Blog
博客园 - 司徒正美
A
About on SuperTechFans
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
爱范儿
爱范儿
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
F
Fortinet All Blogs
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
D
Docker
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
Jina AI
Jina AI
H
Help Net Security
量子位
IT之家
IT之家

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.