microcmsio/gatsby-source-microcms

sourcing from multiple endpoints

Closed this issue · 1 comments

hi, thanks for publishing this awesome plugin :)

I'd like to know if there is a way to source from multiple endpoints from the same serviceId.

for example, I have a microCMS service with the id "fooId", and I have two endpoints "endpoint1" and "endpoint2".
I know I can source from "endpoint1" with the settings in the documentation, but what happens if I want to source from both "endpoint1" and "endpoint2"?

question 1: is this possible?
question 2: if so, how can I set the options in gatsby-config.js?

thanks in advance.

okay so I was able to solve this on my own
turned out it was on the docs all along, my apologies.

closing issue.


in case anyone has the same question, the answer is to use the type field in gatsby-config.js

so if you have to endpoints posts and tags, the config would be like this:

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-source-microcms',
      options: {
        apiKey: 'MICROCMS_API_KEY',
        serviceId: 'myblog',
        endpoint: 'posts',
        type: 'post', // GraphQL types will be 'microcmsPost' and 'allMicrocmsPost'
      },
    },
    {
      resolve: 'gatsby-source-microcms',
      options: {
        apiKey: 'MICROCMS_API_KEY',
        serviceId: 'myblog',
        endpoint: 'tags',
        type: 'tag', // GraphQL types will be 'microcmsTag' and 'allMicrocmsTags'
      },
    },
  ],
};

and the query would be like this:

{
  allMicrocmsPosts {
    edge {
      node {
        id
      }
    }
  }
  allMicrocmsTags {
    edge {
      node {
        id
      }
    }
  }
}

see also: