gridsome-source-cosmicjs

Gridsome Source Plugin for building websites using Cosmic JS as a data source

Usage no npm install needed!

<script type="module">
  import gridsomeSourceCosmicjs from 'https://cdn.skypack.dev/gridsome-source-cosmicjs';
</script>

README

Gridsome Source for Cosmic JS

Source plugin for fetching data into Gridsome from Cosmic JS. Cosmic JS offers a Headless CMS for your Gridsome website.

Install

npm install --save gridsome-source-cosmicjs

How to use

// In your gridsome.config.js
plugins: [
  {
    use: 'gridsome-source-cosmicjs',
    options: {
      bucketSlug: 'gridsome-blog-cosmicjs',
      objectTypes: [`posts`],
      // If you have enabled read_key to fetch data (optional).
      apiAccess: {
        read_key: ''
      }
    },
  }
]

How to query and filter

You can query the nodes created from Cosmic JS with the following:

query IndexQuery {
  posts: allCosmicjsPosts {
    edges {
      node {
        id
        slug
        title
        createdAt(format: "DD MMMM, YYYY")
      }
    }
  }
}

and you can filter specific node using this:

query postQuery($path: String!) {
  post: cosmicjsPosts(path: $path) {
    id
    content
    title
  }
}