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
413 stars 65 forks source link

[CI-232p7qk] Inconsistent GraphQL functionality with default configuration #110

Closed Raffy27 closed 2 years ago

Raffy27 commented 2 years ago

Using GraphQL, Strapi v4.0.7, strapi-plugin-comments 2.0.3. When upgrading to version 2.0.3 from 2.0.0, previous GraphQL queries seem to fail due to custom mutations and queries (such as findAllInHierarchy, createComment) not being available with the default settings. Modifications carried out through the newly added Settings page have no effect on this.

Steps to reproduce

  1. Add a Content-Type of api::post.post (Post), having a Rich Text field named content and a text field named title. Add a post for testing purposes.
  2. Set the base configuration is as follows:
    module.exports = ({ env }) => ({
    comments: {
      badWords: false,
      approvalFlow: ['api::post.post'],
      entryLabel: {
          'api::post.post': ['content'],
      },
      gql: { 
        auth: false
      },
    },
    });
  3. Test a simple mutation to add a new comment:
    mutation createComment($relation: String!, $threadOf: Id, $content: String!, $author: CreateCommentAuthor) {
    createComment(
    input: {
      relation: $relation
      threadOf: $threadOf
      content: $content
      author: $author
    }
    ) {
    id
    content
    threadOf {
      id
    }
    author {
      id
      name
      email
    }
    }
    }

    with the parameters

    {
    "relation": "api::post.post:1",
    "author": { "id": -999, "name": "JW", "email": "contact@at.me" },
    "content": "Hewwo",
    }

    As expected, the query succeeds.

  4. Update the version of strapi-plugin-comments to 2.0.3 by editing package.json, then issuing yarn install.
  5. Rebuild and start Strapi using yarn build, then yarn develop.
  6. Repeat the mutation specified above. It fails with GRAPHQL_VALIDATION_FAILED: Unknown type "Id". Did you mean "ID"? Correcting this mistake yields the underlying error GRAPHQL_VALIDATION_FAILED: Unknown type "CreateCommentAuthor"., which in turn makes it obvious that the GraphQL functionality of the comments plugin is not enabled, or incorrectly configured.
  7. Set the appropriate settings using the new interface and click Save. New Settings
  8. Repeat the mutation. It still fails with the same errors.
  9. Restarting the server results in a different error message:
    INTERNAL_SERVER_ERROR: TypeError: this.getCommonService(...).getConfig(...).includes is not a function
    at resolve (.../strapi/node_modules/strapi-plugin-comments/server/graphql/mutations/createComment.js:21:11)
  10. Reducing the manual configuration to
    module.exports = ({ env }) => ({
    comments: {
    gql: {
      auth: false
    }
    }
    });

    has no effect whatsoever.

  11. Removing comments: { } (essentially leaving an empty function) leads to the GRAPHQL_VALIDATION_FAILED specified above. So does reverting to the default configuration through the Admin interface.

Expected behavior

Upon updating to the new version, for lack of manual configuration through the Admin interface, the fallback configuration of plugins.js should be used, and the GraphQL integration should still work. It should be clearly indicated somewhere whether the active configuration is the one specified through the Admin interface, the fallback configuration in plugins.js, or a mixture of both.

cyp3rius commented 2 years ago

Registered as CU-232p7qk

cyp3rius commented 2 years ago

@Raffy27 thanks for detailed scenario, I was able to reproduce your case and just published fix as part of v2.0.4