VirtusLab-Open-Source / strapi-plugin-comments

A plugin for Strapi Headless CMS that provides end to end comments feature with their moderation panel, bad words filtering, abuse reporting and more.
MIT License
414 stars 65 forks source link

GraphQL support #54

Closed cyp3rius closed 3 years ago

cyp3rius commented 3 years ago
  1. Native support for GQL in Strapi
  2. Research topic with Gatsby (https://www.gatsbyjs.com/plugins/gatsby-source-strapi-plugin-navigation/?=strapi)

References: #13, #24

SalahAdDin commented 3 years ago

Is there any ETA for this?

cyp3rius commented 3 years ago

@SalahAdDin first draft PR by @Kronos66 is already here, expecting 1-2 weeks to release under new version.

kwiat1990 commented 3 years ago

Hi @cyp3rius, any progress on this one? When we could expect this feature to be released?

cyp3rius commented 3 years ago

@kwiat1990 @SalahAdDin -> strapi-plugin-comments@1.0.2-beta.1 has been published recently and contains basic support for GQL. All feedback and testing welcome :)

scrhicks commented 3 years ago

Hello

I have strapi project with GraphQL enabled and after installing strapi-plugin-comments I receive error:

"GraphQLError: Syntax Error: Expected Name, found "}"."

I'm using strapi 3.6.6 and strapi-plugin-comments: ^1.0.2-beta.1

Any idea what I'm doing wrong there :( ?

This is a clean project without any custom modifications

Kronos66 commented 3 years ago

Hi @pogosoftware I checked your error and the reason why you got this is not configured a comments plugin :(. When I create GQL schema I use config to add to schema relation content types:

plugins.comments.relatedContentTypes

That configuration should contain an object with configuration content types in relation to the comments plugin. I forgot to add documentation to readme about this, but if you create this configuration everything should start working,. Example configuration:

 comments: {
    relatedContentTypes: {
      pages: {
        contentManager: true,
        isSingle: true,
        key: 'title',
        value: 'id'
      },
      test: {
        contentManager: false
      }
    },
  },
scrhicks commented 3 years ago

@Kronos66 thanks! It's working now.

But I found 2 other issues.

First, if you block some comments then GraphQL return it. It would be nice if blocked comments and threads will be automatically filtered out from GraphQL query results.

Second, i tried to filter block comments using this query:

query GetArticles {
    articles(where: { comments: { blocked: false}}) {
        title
        comments {
            id
            content
            blocked
        }
    }

But i received and error:

"select distinct `articles`.* from `articles` left join `main`.`comments` as `comments_1` on `comments_1`.`related` = `articles`.`id` where `comments_1`.`blocked` = false and (`articles`.`published_at` is not null) limit 100 - SQLITE_ERROR: no such column: comments_1.related"
Kronos66 commented 3 years ago

@pogosoftware thanks for the feedback! I checked that problem and I think your query won't work correctly because you tried to filter on polymorphic relation where strapi have a problem with this relation type https://github.com/strapi/strapi/issues/4254 I prepared a special query for this can't use built-in methods. Please use our query methods:

      findAllInHierarchy(relation: Relation!, where: JSON): [CommentsInHierarchy]!
      findAllFlat(relation: Relation!, where: JSON): [Comment]!
      findAll(related: Relation, entity: ID, where: JSON): CommentsPagination!
      findOne(id: ID!): CommentsFindOne
      config: CommentsConfig
      contentTypeName(contentType: String!): [CommentsContentType]!
sheddy123 commented 3 years ago

Hi @pogosoftware I checked your error and the reason why you got this is not configured a comments plugin :(. When I create GQL schema I use config to add to schema relation content types:

plugins.comments.relatedContentTypes

That configuration should contain an object with configuration content types in relation to the comments plugin. I forgot to add documentation to readme about this, but if you create this configuration everything should start working,. Example configuration:

 comments: {
    relatedContentTypes: {
      pages: {
        contentManager: true,
        isSingle: true,
        key: 'title',
        value: 'id'
      },
      test: {
        contentManager: false
      }
    },
  },

Please where do I find this file.. location

scrhicks commented 3 years ago

@sheddy123 I've created a plugin.js file inside the config directory with this content.

module.exports = ({ env }) => ({
  comments: {
      relatedContentTypes: {
        pages: {
          contentManager: true,
          isSingle: true,
          key: 'title',
          value: 'id'
        },
        test: {
          contentManager: false
        }
      },
    },
  });

That works for me. If you need more information abot that please go to the official documentation

sheddy123 commented 3 years ago

@sheddy123 I've created a plugin.js file inside the config directory with this content.

module.exports = ({ env }) => ({
  comments: {
      relatedContentTypes: {
        pages: {
          contentManager: true,
          isSingle: true,
          key: 'title',
          value: 'id'
        },
        test: {
          contentManager: false
        }
      },
    },
  });

That works for me. If you need more information abot that please go to the official documentation

I couldn't figure that as well. Trying to use REST Api rather. But calling the endpoint "http://localhost:1337/comments/article:1" I get this as my response { "statusCode": 403, "error": "Forbidden", "message": "Forbidden" } Please help on how to resolve this.. and for path specification I would be glad if that's included

cyp3rius commented 3 years ago

@sheddy123 have you turned on endpoints in the settings? By default they are not exposed publicly.

sheddy123 commented 3 years ago

@sheddy123 have you turned on endpoints in the settings? By default they are not exposed publicly.

@cyp3rius I am new to this... so could you be more specific... The endpoint have been turned in the roles section(public) on the UI... so for the Comments part under permission, findall, findone, and put have been checked, but still get same error. When I click on findone it displays "/comments/moderation/single/:id"... how should the url look like. I have an articles collection type and want to do a [GET and POST] http://localhost:1337/comments/article:1 for GET but returns { "statusCode": 403, "error": "Forbidden", "message": "Forbidden" } using POSTMAN... please I need more clarification on this thanks

VuQuang commented 3 years ago

@sheddy123 I've created a plugin.js file inside the config directory with this content.

module.exports = ({ env }) => ({
  comments: {
      relatedContentTypes: {
        pages: {
          contentManager: true,
          isSingle: true,
          key: 'title',
          value: 'id'
        },
        test: {
          contentManager: false
        }
      },
    },
  });

That works for me. If you need more information abot that please go to the official documentation

I use name plugins.js instead of plugin.js and worked.

SalahAdDin commented 3 years ago

@sheddy123 I've created a plugin.js file inside the config directory with this content.

module.exports = ({ env }) => ({
  comments: {
      relatedContentTypes: {
        pages: {
          contentManager: true,
          isSingle: true,
          key: 'title',
          value: 'id'
        },
        test: {
          contentManager: false
        }
      },
    },
  });

That works for me. If you need more information abot that please go to the official documentation

I use name plugins.js instead of plugin.js and worked.

actually, the correct name is plugins.js.

cyp3rius commented 3 years ago

Feature has been released as v1.0.2

SalahAdDin commented 3 years ago

@cyp3rius So, it means it is full operative now, right?