It's possible to pass configuration parameters to your Gatsby plugin. One use case is just allow the plugin to be used multiple times creating different queries that will be available for your site.
To do this you need to refactor the origin plugin code to accept this parameters and update the gatsby-config.js
file to set them there.
Matías Hernández: [0:00] It's possible to pass parameters to the plugin from the gatsby-config configuration. One example of use of this is just running the plugin multiple times. To do this, we add the parameters to the function sourceNode as the last argument. We add podcastID, authToken, and name.
[0:19] Now, we'll refactor. I will pull in to use this new parameters. We change the token and the ID podcast variables, and use name as part of the NODE_TYPE to create different queries. Now, on the onCreateNode method, we must modify the conditional log to accept a new parameter name.
[0:40] After that, we add some check on the sourceNode to enforce the required parameters, and we just throw an Error in case that doesn't exist. Finally, we can just change our gatsby-config file to add this parameters.
[0:54] In summary, a source plugin can accept configuration parameters that can be used, for example, to identify the type of node and then using the plugin multiple times.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!