Gatsby plugin to connect with a Notion database recursively using the official API.
This plugin recursively collects categories from a single Notion database, which can be used as a CMS for your blog. It ultimately creates a Churnotion node that converts the components of a Notion page into MDX components and stores them in JSON format.
If you're considering Notion as your CMS for Gatsby, this plugin could be a great choice as it supports recursive category collection.
-
Major Overhaul of Node Relationship Handling:
- Completely rewrote the Book-Post relationship mechanism
- Added custom GraphQL resolver for childrenChurnotion field
- Improved recursive database traversal logic
- Optimized batch processing with smaller batches (20 pages at a time)
- Added detailed logging for better debuggability
- Simplified code structure with direct database page processing
-
Fixed GraphQL Query Error:
- Fixed "Cannot return null for non-nullable field Churnotion.rawText" error
- Changed rawText field to be nullable in schema definition
- Added fallback empty string for rawText in Post node creation
- Improved error handling for description field
-
Fixed childrenChurnotion Field Issues:
- Completely redesigned how Book-Post relationships are handled
- Added explicit node fields for childrenChurnotion
- Implemented robust node relationship creation in onPostBootstrap
- Fixed schema definition by using Fields type
- Resolved persistent "Field childrenChurnotion is not defined" error
-
Fixed Gatsby Schema Relationship Bug:
- Fixed
childrenChurnotion
field relationship in NBook nodes - Properly defined relationship between Book and Post nodes
- Fixed "Field 'childrenChurnotion' is not defined" error during Gatsby build
- Fixed
-
Fixed ES Module compatibility issues:
- Removed dependency on external p-limit library
- Implemented custom parallel processing queue
- Fixed Gatsby build errors related to ESM imports
- Improved CommonJS compatibility
-
Added support for more Notion block types:
- bookmark, breadcrumb, callout, code, column, column_list, divider, embed, equation, file, link_preview, pdf, table, table_of_contents, toggle, to_do, video, audio
-
Improved performance:
- Added parallel processing for Notion API requests with concurrency limits
- Implemented caching to reduce duplicate API calls
- Added batch processing for large datasets
- Added timeout handling for long-running operations
-
Code refactoring:
- Modular block processor architecture
- Better error handling
- Improved type safety
npm install gatsby-source-notion-churnotion
yarn add gatsby-source-notion-churnotion
You need to set the following environment variables:
GATSBY_INTEGRATION_TOKEN GATSBY_DATABASE_ID To get the integration token, set it up in your Notion database, and find the database ID, refer to the official Notion Integration Guide.
GATSBY_INTEGRATION_TOKEN={Your Notion API Integration Token}
GATSBY_DATABASE_ID={Your Notion Database ID}
const config: GatsbyConfig = {
plugins: [
{
resolve: `gatsby-source-notion-churnotion`,
options: {
token: process.env.GATSBY_INTEGRATION_TOKEN,
databaseId: process.env.GATSBY_DATABASE_ID,
},
},
],
};
npm run develop
yarn develop
gatsby develop
When the development server is running, gatsby-source-notion-churnotion
will fetch categories and pages from your Notion database using the official Notion API.
Once the data is fetched, go to http://localhost:8000/__graphql, where you'll find new nodes such as Churnotion
, NBook
, NCategory
, and NTag
as shown below:
Use the following GraphQL query to explore the Churnotion
node:
query MyQuery {
allChurnotion {
nodes {
id
content
}
}
}