Creating a configurable data source plugin for Hygraph data
We set up our Hygraph data in Chapter 9 to read from a specific Hygraph project with a specific GraphQL query. Not every project will need to use that same project and that same query. How can we configure a plugin to dynamically change the Hygraph endpoint, query, and data key for each new project?
We can set this up with configuration options.
Setting up the plugin to accept options
To start, let’s move to the
eleventy-plugin-hygraph-data directory and run 11ty from within that project. This has the same initial setup as our last plugin: index file, simple included template, and blank configuration. Let’s start by setting up the options in our configuration file.
When being used as a plugin, the exported function of the
eleventy.config.js file will be an optional
options object that a user can pass in when using the
addPlugin method in their configuration. To begin, add that argument and then we...