npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gatsby-source-mozaik

v1.0.0

Published

Gatsby source plugin for building static websites using Mozaik CMS as a data source.

Downloads

15

Readme

gatsby-source-mozaik

Source plugin for pulling data from a Mozaik endpoint into Gatsby.

Install

  1. yarn add gatsby-source-mozaik or npm i gatsby-source-mozaik
  2. Add reference in your Gatsby config plugins section to gatsby-source-mozaik. See example below.
  3. Run gatsby develop

Usage

Make sure that gatsby-source-mozaik plugin is referenced in you gatsby-config.js:

plugins: [
  {
    resolve: `gatsby-source-mozaik`,
    options: {
      endpoint: `https://api.mozaik.io/[your-project-name]`,
      accessToken: `your-access-token`,
      query: `
        query documentsQuery($types: [DocumentContentTypeEnum] $pageSize: Int $page: Int) {
          documents(types: $types pageSize: $pageSize page: $page) {
            pagination {
              page
              pageCount
            }
            items {
              id
              contentType
              slug
            }
          }
        }
      `,
      variables: {
        types: [],
        pageSize: 20,
        page: 1
      },
      fragments: []
    },
  }
],

Plugin options

| Key | Value | Required | | -------- | -------- | -------- | | endpoint | Your mozaik api endpoint: https://api.mozaik.io/[your-project-name] | Yes | | accessToken | The access token for authorizing against the api | Yes | | query | The graphql query to execute. You should use the sample documents query and only amend it. | Yes | | variables | Variables to use in the graphql query | Yes | | variables.types | An array of string that defines the content types you want to get from the api | Yes | | variables.pageSize | Number of items to download in one batch | Yes | | variables.page | The page number | Yes | | fragments | An array of string that defines the fields you want to query on each content type | No |

How to write a query

Let's say you have created a blog project using the sample blog template on Mozaik. You will have 3 different content types (the enum name in your GraphQL schema):

  • Homepage (HOMEPAGE)
  • Post (POST)
  • Author (AUTHOR)

And you only implement the homepage and the post page components.

To create the query you have to add the following plugin options:

Variables

variables: {
  types: ['HOMEPAGE', 'POST'],
  page: 1,
  pageSize: 20
}

Query and Fragments

In Mozaik each document implements the DocumentInterface type, and because of this the result of the documents query returns an array of DocumentInterface object. To be able to query specific fields on each document, you have to define a fragment for each content type. Although you can do this by inlining the fragments in the query itself, we highly recommend to add every fragment in the fragments plugin option in you config. You can read more about interfaces and fragments in the GraphQL documentation

First let's add the fragment definitions:

fragments: [
  `fragment HomepageDetails on HomepageDocument {
    title
    tagline
    headerImage {
      ...HeaderImageFragment
    }
    topPosts {
      items {
        ...PostDetails
      }
    }
  }`
  `fragment PostDetails on PostDocument {
    title
    slug
    date
    postContent {
      html
    }
    postAuthor {
      name
    }
    headerImage {
      ...HeaderImageFragment
    }
  }`,
  `fragment HeaderImageFragment on Asset {
    url
    thumbnailUrl
    caption
  }`
]

Update the default query to add the fragments above:

query documentsQuery($types: [DocumentContentTypeEnum] $pageSize: Int $page: Int) {
  documents(types: $types pageSize: $pageSize page: $page) {
    pagination {
      page
      pageCount
    }
    items {
      id
      contentType
      slug
      ...PostDetails
      ...HomepageDetails
    }
  }
}

And that's it! You're ready to run gatsby develop and load all your documents. If you open the graphql ide that comes with Gatsby you can query your Post documents by running the allPosts query (or the allHomepage query for the Homepage document).

Contributing

  1. cd to the Gatsby project you've set up in which you want to test your changes of the plugin code, or clone mozaikio/mozaik-gatsby-example
  2. If you cloned the example or previously installed the plugin through yarn or npm, run yarn remove gatsby-source-mozaik or npm r gatsby-source-mozaik
  3. mkdir plugins if it does not exist in your Gatsby project yet and cd into it
  4. The path should now be similar to this: ~/projects/mozaik-gatsby-website/plugins/
  5. run git clone https://github.com/mozaikio/gatsby-source-mozaik.git
  6. cd gatsby-source-mozaik
  7. run yarn or yarn && yarn watch in gatsby-source-mozaik plugin’s folder for auto-rebuilding the plugin after you make changes to it (you need to do this only during development)
  8. Make sure plugin is referenced in your Gatsby config (see above at Usage)
  9. From there you can cd ../.. && yarn && yarn develop to test