Connecting to multiple Dato projects with Gatsby

I’ve been using gatsby-source-datocms on my gatsby application to load data from two different projects. However, if I start a brand new app and try to connect to the same projects, it doesn’t work. It only loads the data from the first project on the gatsby-config file (see sample below).

{
resolve: gatsby-source-datocms,
options: {
apiToken: process.env.DATO_API_TOKEN,
previewMode: true,
disableLiveReload: false,
},
},
{
resolve: gatsby-source-datocms,
options: {
apiToken: process.env.DATO_API_TOKEN_MASTER,
previewMode: true,
disableLiveReload: false,
},
},

EDIT:
It seems it works if I add a spacific version of the plugin “gatsby-source-datocms”: “2.1.29”, but it breaks if I use the caret in front of the version “gatsby-source-datocms”: “^2.1.29”. Also it seems it doesn’t work at all with any of the 2.2.x versions of the plugin.

@jgiraldo can you please check which version of the datocms-client you have installed in your package.lock/yarn.lock file?

I fixed that in 3.0.17 of that package, which is a dependency of our Gatsby source. If that is the case, can you maybe share access to your repo so that I can better replicate your issue? (feel free to send details over DM)

I have datocms-client “>=3.0.16”

check in the lock file to see what’s the version that you are actually using, if you have that in the package.json might mean that you have an old version.

If instead you have 3.0.17 can you please send over a link for your repo (via DM). Thanks!

@mat_jack1 I am getting the same issue now when I update to “gatsby-source-datocms”: “^2.5.17” which is using “datocms-client@>=3.3.0” according the lock file.

ok @jgiraldo we’ll have a look and get back to you, sorry for this

Thank you @mat_jack1. I wanted to use the new Structured Text functionality and wasn’t working with the version of gatsby-source-datocms I had when I tried to update to the latest, everything broke.

@mat_jack1 any updates on this?

not yet sorry, but we’ll have a look soon at this, we haven’t forgot

1 Like

@jgiraldo could you try version 2.6.5-0? we added an instancePrefix option to handle the case:

https://github.com/datocms/gatsby-source-datocms/tree/multiple-instances#connecting-to-multiple-datocms-projects

@s.verna Thank you for looking into this. I installed the 2.6.5-0 version on a new project and I can see both projects listed; however the instancePrefix only works on one of them; it won’t show the two different prefixes, just one. Not a big deal but I just wanted to let you know.

I also Installed v2.6.5-0 on a current project that was using v2.1.29 and then I get all kinds of errors. for example:

"gatsby-source-datocms" threw an error while running the createSchemaCustomization lifecycle:
TypeError: getGatsbyImageResolver is not a function
Missing onError handler for invocation 'building-schema', error was 'Invariant Violation: Encountered an error trying to infer a GraphQL type
for: `fields___NODE`.
...

So, since I get these errors on a current project, the site won’t build.

EDIT: I got it to work. The problem was that I didn’t have the gatsby-plugin-image plugin installed. Once I installed it, I didn’t get any errors

Thank you,

1 Like

Mh, do you have the gatsby-plugin-image package installed?

@s.verna That was the issue. Once I installed it, it worked just fine.

1 Like