Skip to content

Commit

Permalink
feat: All configuration for multiple instances (#126)
Browse files Browse the repository at this point in the history
* feat: Add `typePrefix` configuration option

Prevent conflicts for multiple instances

* docs: Add docs for `typePrefix`

* docs: Add docs note for `fragmentsPath`

* docs: Update README
  • Loading branch information
Jonathan Steele authored Oct 13, 2020
1 parent 41f387d commit f6d90b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions gatsby-source-graphcms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ module.exports = {

- If your GraphCMS project is **not** publicly accessible, you will need to provide a [Permanent Auth Token](https://graphcms.com/docs/reference/authorization) to correctly authorize with the API. You can learn more about creating and managing API tokens [here](https://graphcms.com/docs/guides/concepts/apis#working-with-apis).

- `typePrefix` _String_ (default value: `GraphCMS_`)

> If using multiple instances of the source plugin, you **must** provide a value here to prevent type conflicts.
- The string by which every generated type name is prefixed with. For example, a type of `Post` in GraphCMS would become `GraphCMS_Post` by default.

- `downloadLocalImages` _Boolean_ (default value: `false`)

- Download and cache GraphCMS image assets in your Gatsby project. [Learn more](#downloading-local-image-assets).
Expand All @@ -71,6 +77,8 @@ module.exports = {

- `fragmentsPath` _String_ (default value: `graphcms-fragments`)

> If using multiple instances of the source plugin, you **must** provide a value here to prevent type and/or fragment conflicts.
- The local project path where generated query fragments are saved. This is relative to your current working directory.

- `locales` _[String]_ (default value: `['en']`)
Expand Down
10 changes: 8 additions & 2 deletions gatsby-source-graphcms/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ exports.onPreBootstrap = ({ reporter }, pluginOptions) => {

const createSourcingConfig = async (
gatsbyApi,
{ endpoint, fragmentsPath = 'graphcms-fragments', locales = ['en'], token }
{
endpoint,
fragmentsPath = 'graphcms-fragments',
locales = ['en'],
token,
typePrefix = 'GraphCMS_',
}
) => {
const execute = async ({ operationName, query, variables = {} }) => {
return await fetch(endpoint, {
Expand Down Expand Up @@ -122,7 +128,7 @@ const createSourcingConfig = async (
gatsbyApi,
schema,
execute: wrapQueryExecutorWithQueue(execute, { concurrency: 10 }),
gatsbyTypePrefix: `GraphCMS_`,
gatsbyTypePrefix: typePrefix,
gatsbyNodeDefs: buildNodeDefinitions({ gatsbyNodeTypes, documents }),
}
}
Expand Down

0 comments on commit f6d90b8

Please sign in to comment.