GatsbyJS Slicknode Source Plugin
Source plugin for loading content from Slicknode Headless GraphQL CMS into Gatsby.
This source plugin downloads all content nodes from the CMS and adds the content as Gatsby nodes
to the Gatsby GraphQL API. The content can then be transformed, extended etc. with all the
other Gatsby plugins.
Features:
Links:
Installation
Install the source plugin via npm:
npm install gatsby-source-slicknode
Configuration
Add the source plugin to the gatsby-config.js
file of your project and customize the configuration:
module.exports = {
plugins: [
{
resolve: 'gatsby-source-slicknode',
options: {
endpoint: 'https://<your-slicknode-project-endpoint>',
downloadImages: true,
preview: false,
fragmentsPath: 'slicknode-fragments',
typePrefix: 'Slicknode_',
},
}
],
};
Usage
For each content type the root query fields will be added to the Gatsby GraphQL schema.
Check out the GraphiQL playground for query capabilities: https://localhost:8000/___graphql
Customizing Fragments
The gatsby-source-slicknode
plugin generates fragments for each custom type in your Slicknode schema
that implements the Node
interface. The entire object is then sourced into Gatsby
according to the specified fragment.
The source plugin creates files for each fragment
in the directory specified in the config option fragmentPath
(default to ./slicknode-fragments
).
You can customize the fragments in the directory to load additional data like
many-to-many relations that are not included by default, or you can remove fields
if you don't want to include certain fields in your Gatsby schema.
Image Transforms
To use the images with the gatsby-image plugin,
install the required plugins and add them to your configuration:
module.exports = {
plugins: [
{
resolve: 'gatsby-source-slicknode',
options: {
endpoint: 'https://<your-slicknode-endpoint>',
downloadImages: true,
},
},
`gatsby-plugin-sharp`,
`gatsby-transformer-sharp`,
],
}
Then use the image fragments of the image sharp plugin to generate optimized images for assets loaded
from the Slicknode API, for example:
query GetBlogPostsQuery {
allSlicknodeBlogPost {
edges {
node {
image {
localFile {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
}
}
}
}
}
Sourcing Multiple Slicknode APIs
To source data from multiple Slicknode APIs, add the configuration for both endpoints
and choose differnet fragmentsPath
and typePrefix
settings for each API,
for example:
module.exports = {
plugins: [
{
resolve: 'gatsby-source-slicknode',
options: {
endpoint: 'https://<your-primary-slicknode-endpoint>',
fragmentsPath: 'slicknode-fragments-primary',
typePrefix: 'SlicknodePrimary_'
},
},
{
resolve: 'gatsby-source-slicknode',
options: {
endpoint: 'https://<your-secondary-slicknode-endpoint>',
fragmentsPath: 'slicknode-fragments-secondary',
typePrefix: 'SlicknodeSecondary_'
},
},
],
}