nuxt.config.jsでApollo Clientを使う方法

暫定対応

yarn add node-fetch apollo-boost
export default {
  modules: [
    "@nuxtjs/sitemap",
    "@nuxtjs/apollo",
  ],

  sitemap: {
    path: "/sitemap.xml",
    hostname: process.env.BASE_URL || "https://example.com/",
    generate: true,
    cacheTime: 1000 * 60 * 60 * 24,
    exclude: [
      "/login",
      "/404",
    ],
    routes: async () => {
       const routes = []
      const fetch = require("node-fetch")
      const { gql } = require("apollo-boost")
      const ApolloBoost = require("apollo-boost")
      const ApolloClient = ApolloBoost.default

      const apolloClient = new ApolloClient({
        fetch: fetch,
        uri: YOUR_API_ENDPOINT,
      })
      const fetchUsers = gql`
        query {
          users {
            id
          }
        }
      `

      const users = await apolloClient
        .query({
          query: fetchUsers,
        })
        .then((res) => res.data.users)

      users.forEach((user) => {
        routes.push({
          route: `/${user.id}`,
        })
      })

      return routes
    },
}