Gridsome Source Plugin for building websites using Cosmic JS as a data source
npm install gridsome-source-cosmicjsSource plugin for fetching data into Gridsome from Cosmic JS. Cosmic JS offers a Headless CMS for your Gridsome website.
npm install --save gridsome-source-cosmicjs
``javascriptposts
// In your gridsome.config.js
plugins: [
{
use: 'gridsome-source-cosmicjs',
options: {
bucketSlug: 'gridsome-blog-cosmicjs',
objectTypes: [],`
// If you have enabled read_key to fetch data (optional).
apiAccess: {
read_key: ''
}
},
}
]
You can query the nodes created from Cosmic JS with the following:
`javascript`
query IndexQuery {
posts: allCosmicjsPosts {
edges {
node {
id
slug
title
createdAt(format: "DD MMMM, YYYY")
}
}
}
}
and you can filter specific node using this:
`javascript``
query postQuery($path: String!) {
post: cosmicjsPosts(path: $path) {
id
content
title
}
}