Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: All configuration for multiple instances #126

Merged
merged 4 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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