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
405 stars 63 forks source link

Comments are created, and can be fetched, but they are not loaded in Strapi #117

Closed M1ck0 closed 2 years ago

M1ck0 commented 2 years ago

When I create comments through graphql it works as it should (with some queries missing, read below for this). But I get this error when trying to load comments in Strapi. This is the image

image

Any ideas what could be the issue? This is log in the console

TypeError: Cannot read properties of null (reading 'split')
    at getRelatedGroups (/home/m1ck0/Desktop/projects/portfolio-admin/node_modules/strapi-plugin-comments/server/services/utils/functions.js:52:42)
    at /home/m1ck0/Desktop/projects/portfolio-admin/node_modules/strapi-plugin-comments/server/services/common.js:198:55
    at Array.reduce (<anonymous>)
    at Object.findRelatedEntitiesFor (/home/m1ck0/Desktop/projects/portfolio-admin/node_modules/strapi-plugin-comments/server/services/common.js:197:31)
    at Object.findAll (/home/m1ck0/Desktop/projects/portfolio-admin/node_modules/strapi-plugin-comments/server/services/admin.js:137:63)
    at async returnBodyMiddleware (/home/m1ck0/Desktop/projects/portfolio-admin/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
    at async policiesMiddleware (/home/m1ck0/Desktop/projects/portfolio-admin/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
    at async serve (/home/m1ck0/Desktop/projects/portfolio-admin/node_modules/koa-static/index.js:59:5)
    at async returnBodyMiddleware (/home/m1ck0/Desktop/projects/portfolio-admin/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
    at async policiesMiddleware (/home/m1ck0/Desktop/projects/portfolio-admin/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
    at async /home/m1ck0/Desktop/projects/portfolio-admin/node_modules/@strapi/strapi/lib/middlewares/body.js:25:7
    at async /home/m1ck0/Desktop/projects/portfolio-admin/node_modules/@strapi/strapi/lib/middlewares/logger.js:22:5
    at async /home/m1ck0/Desktop/projects/portfolio-admin/node_modules/@strapi/strapi/lib/middlewares/powered-by.js:16:5
    at async cors (/home/m1ck0/Desktop/projects/portfolio-admin/node_modules/@koa/cors/index.js:56:32)
    at async /home/m1ck0/Desktop/projects/portfolio-admin/node_modules/@strapi/strapi/lib/middlewares/errors.js:13:7
    at async session (/home/m1ck0/Desktop/projects/portfolio-admin/node_modules/koa-session/index.js:41:7)

Also, these are all available queries and mutations for comments. Judging by the docs, some of them are missing, and are named incorrectly.

image

This is new Strapi installation.

I have custom config/env/production/database.js file with this content

const parse = require('pg-connection-string').parse;
const config = parse(process.env.DATABASE_URL);
module.exports = ({ env }) => ({
  connection: {
    client: 'postgres',
    connection: {
      host: config.host,
      port: config.port,
      database: config.database,
      user: config.user,
      password: config.password,
      ssl: {
        rejectUnauthorized: false
      },
    },
    debug: false,
  },
});

Node: 16.13.1 Strapi: 4.1.1 npm: 8.1.2 yarn: 1.22.17 OS: Linux

M1ck0 commented 2 years ago

@cyp3rius Any ideas?

cyp3rius commented 2 years ago

@M1ck0 as I see you have got disabled the plugin queries. And probably you've added comments to not existing collections. Can you please check what settings you got per this plugin? Settings -> Comments plugin -> configuration

Adding this via not supported queries (that I see on your screen) caused errors as you are loosing all validation logic.

M1ck0 commented 2 years ago

Settings are fine. They are added to collection Blogs, which is the only collection I currently have

image image

And what do you mean by disabled the plugin queries? Could you point me to some docs about it, because I can't seem to find anything about it.

M1ck0 commented 2 years ago

As you can see here my Public group has following permissions

image

cyp3rius commented 2 years ago

Hello @M1ck0 I've schema on Strapi 4.1.1 and looks correct. Check please if you got it right. I assume you've added the comments via default Strapi mutation (which should be disabled) and that causes issues.

Screenshot 2022-02-28 at 09 05 02

  1. Have you restarted Strapi after changing settings?
  2. Provide me please mutation query which you triggered
M1ck0 commented 2 years ago

@cyp3rius

My schema is not the same as yours.

I have restarted Strapi after the changes. Currently, I reinstalled the whole strapi, still the same issue. These are the only mutations I have

image

cyp3rius commented 2 years ago

Can you please share your config/plugins.js ? I'm interested in about the ordering of plugins as based on our doc it might be important.

M1ck0 commented 2 years ago

I don't have plugins.js. Only files present in config directory are

admin.js
api.js
database.js
middleware.js
server.js
cyp3rius commented 2 years ago

then try to put there and revert back with result:

module.exports = {

  'comments': {
      enabled: true,
   }
};

Seems like default ordering of plugins in the Strapi lifecycle makes some problems with enabling GQL support for Comments.

M1ck0 commented 2 years ago

Still the same. I did yarn build and yarn develop after adding config/plugins.js file with the content you provided.

M1ck0 commented 2 years ago

Any updates on this?

cyp3rius commented 2 years ago

I'm trying different configurations to reproduce this. Also in a meantime checking the other way to enable GQL support of plugin. It's clearly visible that bootstrap didn't enable it as expected

M1ck0 commented 2 years ago

Can I do anything to help you with reproduction? This is really strange issue

cyp3rius commented 2 years ago

Finally reproduced it, looking for a solution. Expect it in 1-2 days hopefully

M1ck0 commented 2 years ago

Okay great. If I can do anything to help, just tell me. Hopefully we will resolve it

cyp3rius commented 2 years ago

@M1ck0 found the fix for this issue. Try to put such configuration:

module.exports = {
  'comments': { enabled: true },
  'graphql': { enabled: true },
};

The problem is indeed what we have described in docs about GraphQL configuration. Installed plugins are ordered by default somehow by Strapi and the custom Comment plugin schemas are not injected before GraphQL plugin runs.

We will work on it with Strapi to figure out a way to "order" it properly. But as for now it should solve your issue and also it wont break anything existing :)

M1ck0 commented 2 years ago

@cyp3rius It is still not working. Everything is the same. I'll try to reinstall the whole project again later to see if it is working from scratch, then I'll come back to you with the result.

cyp3rius commented 2 years ago

I've did it against the plain strapi example we've got prepared for this plugin + made a settings for at least single collection there.

M1ck0 commented 2 years ago

@cyp3rius Could this be of any help?

image

It is working now, but I thought I should provide you with this image if it was something important. Thank you for your help. Initializing new project and using

module.exports = {
  'comments': { enabled: true },
  'graphql': { enabled: true },
};

in config/plugins.js did the trick

cyp3rius commented 2 years ago

Thats the dependency inside the GraphQL plugin so typical warning :)

I've already asked question to Strapi team to check if there is a possibility to force plugins orders by their dependencies as Thats purely the issue. By this trick with plugins.js you are forcing the ordering.

As its solved, lets close the issue and I will keep eye this.

M1ck0 commented 2 years ago

@cyp3rius same thing happens with strapi 4.1.5.

cyp3rius commented 2 years ago

Strapi didn't fixed it I assume :) So the trick must be applied as for now.

gbdubs commented 1 year ago

Just putting this here for folks who can't find their missing query types (i.e. findAllInHierarchy not in the schema/not queryable) with this setup. I had to explicitly add the collection types to Settings > Comments > General Configuration > Enable comments only for in order for the generated GQL code for the query types to be in the resulting schema + queryable through GQL.