kontent-ai / gatsby-packages

Monorepo with Gatsby Kontent packages.
https://www.gatsbyjs.org/plugins/?=%40kentico%2Fkontent-
MIT License
33 stars 24 forks source link

Multiproject data data source #51

Open Simply007 opened 5 years ago

Simply007 commented 5 years ago

Motivation

Allow users to load data from more than one project.

Proposed solution

Extend a configuration object by the project identification property that would create the project-specific prefix for created Nodes.

Configuration example:

       {
      resolve: `gatsby-source-kentico-cloud`,
      options: {
        project1: {
          deliveryClientConfig: {
            projectId: `firstProjectGuid`,
          },
          languageCodenames: [
            `en-US`,
            `es-ES`,
          ]
        },
        project2: {
          deliveryClientConfig: {
            projectId: `secondProjectId`,
          },
          languageCodenames: [
            `en-US`,
          ]
        }
      }
    }

Possible workaround

Using Kontent Delivery API directly (or using JS SDK) without the GraphQL layer might work as a workaround: https://www.gatsbyjs.com/docs/how-to/querying-data/using-gatsby-without-graphql/

Simply007 commented 3 years ago

Note:

I have tested out a 🚩 really HACKY 🚩 thing with the source plugin and it is definitely not recommended to use it like that in production, but registering the plugin twice with different configurations works if the types are two distinct sets.

gatsby.config.js

[
    // ...
    {
      resolve: '@kentico/gatsby-source-kontent',
      options: {
        projectId: "FIRST_PROJECT", // Fill in your Project ID
        languageCodenames: ["default"]
      },
    },
    {
      resolve: '@kentico/gatsby-source-kontent',
      options: {
        projectId: "SECOND_PROJECT", // Fill in your Project ID
        languageCodenames: ["default"]
      },
    }
    // ...
]

The only thing is this error

A field extension with the name `kontent_item_language_link` has already been registered.

But this might be another approach to implement it - allow registering source plugin multiple times like i.e. gatsby-source-filesystem