gatsby-uc / gatsby-source-strapi

Gatsby source plugin for building websites using Strapi as a data source
MIT License
354 stars 182 forks source link

Pull plugin comments data into Gatsby #357

Closed Oscin closed 1 year ago

Oscin commented 2 years ago

Hi all,

I am using the Strapi Comments plugin 'strapi-plugin-comments' (https://market.strapi.io/plugins/strapi-plugin-comments) to add a comments functionality to Strapi. The comment functionality is working fine and also showing the expected data in Strapi's Playground (http://localhost:1337/graphql).

I am trying to pull this data into Gatsby with the gatsby-source-strapi plugin but cannot figure out how.

In an attempt to fix it I found in .../node_modules/gatsby-source-strapi/lib/helpers.js the following code:

return {
      singularName,
      pluralName,
      kind,
      uid,
      endpoint: '/api/${pluralName}',
      queryParams: { ...(queryParams || {}),
        pagination: {
          pageSize: queryLimit || 250,
          page: 1
        },
        populate: (queryParams === null || queryParams === void 0 ? void 0 : queryParams.populate) || '*'
      },
      pluginOptions
    };

which implies that the name specifying in gatsby-config should in inserted there. For example:

collectionTypes: [
    {
      singularName: "comments/api::recipe.recipe:123",
      queryParams: {
        publicationState: process.env.GATSBY_IS_PREVIEW === 'true' ? "preview" : "live",
        populate: '*',
      },
    },
]

However, this would not work because we don't know the ID's upfront. As a result I don't see how we can import the comments from Strapi into Gatsby. Ideally we want to use the function "findAllFlat" as provided on https://market.strapi.io/plugins/strapi-plugin-comments

query {
  findAllFlat(
    relation: "api::page.page:1"
    filters: { content: { contains: "Test" } }
  ) {
    id
    content
    blocked
    threadOf {
      id
    }
    author {
      id
      name
    }
  }
}

Any thoughts on how to import plugin data into Gatsby?

moonmeister commented 1 year ago

Thanks for your interest in this project. This plugin is moving into the Gatsby User Collective and this repo will be archived. Please open an issue in that repository, submit a PR if you'd like to see this implemented, or join us on Discord if you have questions!