strapi-community / strapi-plugin-slugify

A plugin for Strapi Headless CMS that provides the ability to auto slugify a field for any content type.
https://market.strapi.io/plugins/strapi-plugin-slugify
MIT License
45 stars 21 forks source link

Not working #20

Closed SoftCreatR closed 2 years ago

SoftCreatR commented 2 years ago

Maybe, I'm just too stupid, but I can't make it work.

Installed the plugin via

yarn add strapi-plugin-slugify

Added it to the configuration:

    slugify: {
      enabled: true,
      config: {
        contentTypes: {
          article: {
            field: 'slug',
            references: 'title',
          },
        },
      },
    },

and rebuilt it via

yarn build

In Strapi (4.1.1, node v16.14.0), I can see that the plugin is enabled, but I can't query anything:

{
  "errors": [
    {
      "message": "Cannot query field \"findSlug\" on type \"Query\".",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "extensions": {
        "code": "GRAPHQL_VALIDATION_FAILED",
        "exception": {
          "stacktrace": [
            "GraphQLError: Cannot query field \"findSlug\" on type \"Query\".",
            "    at Object.Field (/node_modules/graphql/validation/rules/FieldsOnCorrectTypeRule.js:48:31)",
            "    at Object.enter (/node_modules/graphql/language/visitor.js:323:29)",
            "    at Object.enter (/node_modules/graphql/utilities/TypeInfo.js:370:25)",
            "    at visit (/node_modules/graphql/language/visitor.js:243:26)",
            "    at validate (/node_modules/graphql/validation/validate.js:69:24)",
            "    at validate (/node_modules/apollo-server-koa/node_modules/apollo-server-core/dist/requestPipeline.js:186:39)",
            "    at processGraphQLRequest (/node_modules/apollo-server-koa/node_modules/apollo-server-core/dist/requestPipeline.js:98:34)",
            "    at processTicksAndRejections (node:internal/process/task_queues:96:5)",
            "    at async processHTTPRequest (/node_modules/apollo-server-koa/node_modules/apollo-server-core/dist/runHttpQuery.js:187:30)",
            "    at async /node_modules/apollo-server-koa/dist/ApolloServer.js:82:59",
            "    at async bodyParser (/node_modules/koa-bodyparser/index.js:95:5)",
            "    at async cors (/node_modules/@koa/cors/index.js:56:32)",
            "    at async returnBodyMiddleware (/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)",
            "    at async policiesMiddleware (/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)",
            "    at async /node_modules/@strapi/strapi/lib/middlewares/logger.js:22:5",
            "    at async /node_modules/@strapi/strapi/lib/middlewares/powered-by.js:16:5"
          ]
        }
      }
    }
  ]
}

What am I doing wrong?

Oh and yes, a (collection) type named article (resp. articles in singular) exists, and it has a title attribute.

SoftCreatR commented 2 years ago

Nvm, I found the problem. It wasn't clear, that I have to add a field slug as well. I wonder, if this field could be hidden from content creation, or be read-only, so that only this plugin is able to modify it?

ComfortablyCoding commented 2 years ago

Hello @SoftCreatR,

At this time the field must be created in the admin for it to work as you have discovered. Their is a note about this in the configuration section of the docs.

Regarding setting the field to read only or hiding it, I have not found a way to do this via a plugin. The only current way to limit is is via the Role settings in Settings -> Administration Panel -> Roles.

SoftCreatR commented 2 years ago

Their is a note about this in the configuration section of the docs.

I know. But I misunderstood that part. But it's all good now :)

Regarding setting the field to read only or hiding it, I have not found a way to do this via a plugin. The only current way to limit is is via the Role settings in Settings -> Administration Panel -> Roles.

What about a custom field (shipped by the plugin, or a separate plugin) that is read-only?

ComfortablyCoding commented 2 years ago

At the moment custom fields are not officially supported.

We could add a readonly field provided by the plugin but users would need to add it manually to the schema which is not ideal.

As the role settings are available for fields I would say we leave it for now and it can be discussed further once custom field support is released.

Once its released the contentTypes part of the settings can probably be removed altogether.