You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds support for setting a custom type prefix, which allows
multiple instances of the plugin to be used. The prefix is in addition
to the `Sanity` prefix, so for example if you have a `movies` type,
setting the type prefix to `Staging` will make the type
`StagingSanityMovies`.
| projectId | string ||**[required]** Your Sanity project's ID |
87
-
| dataset | string ||**[required]** The dataset to fetch from |
88
-
| token | string || Authentication token for fetching data from private datasets, or when using `overlayDrafts`[Learn more](https://www.sanity.io/docs/http-auth)|
89
-
| graphqlTag | string |`default`| If the Sanity GraphQL API was deployed using `--tag <name>`, use this to specify the tag name. |
90
-
| overlayDrafts | boolean |`false`| Set to `true` in order for drafts to replace their published version. By default, drafts will be skipped. |
91
-
| watchMode | boolean |`false`| Set to `true` to keep a listener open and update with the latest changes in realtime. If you add a `token` you will get all content updates down to each key press. |
92
-
| watchModeBuffer | number |`150`| How many milliseconds to wait on watchMode changes before applying them to Gatsby's GraphQL layer. Introduced in 7.2.0. |
| projectId | string ||**[required]** Your Sanity project's ID |
88
+
| dataset | string ||**[required]** The dataset to fetch from |
89
+
| token | string || Authentication token for fetching data from private datasets, or when using `overlayDrafts`[Learn more](https://www.sanity.io/docs/http-auth)|
90
+
| graphqlTag | string |`default`| If the Sanity GraphQL API was deployed using `--tag <name>`, use this to specify the tag name. |
91
+
| overlayDrafts | boolean |`false`| Set to `true` in order for drafts to replace their published version. By default, drafts will be skipped. |
92
+
| watchMode | boolean |`false`| Set to `true` to keep a listener open and update with the latest changes in realtime. If you add a `token` you will get all content updates down to each key press. |
93
+
| watchModeBuffer | number |`150`| How many milliseconds to wait on watchMode changes before applying them to Gatsby's GraphQL layer. Introduced in 7.2.0. |
94
+
| typePrefix | string || Prefix to use for the GraphQL types. This is prepended to `Sanity` in the type names and allows you to have multiple instances of the plugin in your Gatsby project. |
93
95
94
96
## Preview of unpublished content
95
97
@@ -244,6 +246,35 @@ These data structures can be deep and a chore to query (specifying all the possi
244
246
245
247
You can install [@portabletext/react](https://www.npmjs.com/package/@portabletext/react) from npm and use it in your Gatsby project to serialize Portable Text. It lets you use your own React components to override defaults and render custom content types. [Learn more about Portable Text in our documentation](https://www.sanity.io/docs/content-studio/what-you-need-to-know-about-block-text).
246
248
249
+
## Using multiple datasets
250
+
251
+
If you want to use more than one dataset in your site, you can do so by adding multiple instances of the plugin to your `gatsby-config.js` file. To avoid conflicting type names you can use the `typeName` option to set a custom prefix for the GraphQL types. These can be datasets from different projects, or different datasets within the same project.
252
+
253
+
```js
254
+
// In your gatsby-config.js
255
+
module.exports= {
256
+
plugins: [
257
+
{
258
+
resolve:'gatsby-source-sanity',
259
+
options: {
260
+
projectId:'abc123',
261
+
dataset:'production',
262
+
},
263
+
},
264
+
{
265
+
resolve:'gatsby-source-sanity',
266
+
options: {
267
+
projectId:'abc123',
268
+
dataset:'staging',
269
+
typePrefix:'Staging',
270
+
},
271
+
},
272
+
],
273
+
}
274
+
```
275
+
276
+
In this case, the type names for the first instance will be `Sanity<typeName>`, while the second will be `StagingSanity<typeName>`.
277
+
247
278
## Real-time content preview with watch mode
248
279
249
280
While developing, it can often be beneficial to get updates without having to manually restart the build process. By setting `watchMode` to true, this plugin will set up a listener which watches for changes. When it detects a change, the document in question is updated in real-time and will be reflected immediately.
@@ -38,7 +38,7 @@ export default function getSyncWithGatsby(props: {
38
38
39
39
constdoc=draft||published
40
40
if(doc){
41
-
consttype=getTypeName(doc._type)
41
+
consttype=getTypeName(doc._type,typePrefix)
42
42
if(!typeMap.objects[type]){
43
43
reporter.warn(
44
44
`[sanity] Document "${doc._id}" has type ${doc._type} (${type}), which is not declared in the GraphQL schema. Make sure you run "graphql deploy". Skipping document.`,
0 commit comments