strapi-community / strapi-plugin-slugify

A plugin for Strapi Headless CMS that provides the ability to auto slugify a field for any content type.

Home Page:https://market.strapi.io/plugins/strapi-plugin-slugify

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slugify and Strapiv4.1.2 with GraphQL - 'admin::permission' of undefined

vmptk opened this issue · comments

  • Error message:
[2022-03-03 17:10:02.429] info: [slugify] graphql detected, registering queries
[2022-03-03 17:10:03.035] debug: ⛔️ Server wasn't able to start properly.
[2022-03-03 17:10:03.035] error: Cannot read property 'admin::permission' of undefined
TypeError: Cannot read property 'admin::permission' of undefined
at <folder>/node_modules/strapi-plugin-slugify/server/graphql/types.js:18:13
at <folder>/node_modules/lodash/lodash.js:4967:15
at baseForOwn (<folder>/node_modules/lodash/lodash.js:3032:24)
at <folder>/node_modules/lodash/lodash.js:4936:18
at Function.forEach (<folder>/node_modules/lodash/lodash.js:9410:14)
at getCustomTypes (<folder>/node_modules/strapi-plugin-slugify/server/graphql/types.js:17:4)
at extension (<folder>/node_modules/strapi-plugin-slugify/server/graphql/index.js:10:10)
at resolveConfig (<folder>/node_modules/@strapi/plugin-graphql/server/services/extension/extension.js:54:47)
at <folder>/node_modules/@strapi/plugin-graphql/server/services/extension/extension.js:59:74
at Array.reduce (<anonymous>)
at Object.generate (<folder>/node_modules/@strapi/plugin-graphql/server/services/extension/extension.js:58:22)
at buildMergedSchema (<folder>/node_modules/@strapi/plugin-graphql/server/services/content-api/index.js:103:55)
at Object.buildSchema (<folder>/node_modules/@strapi/plugin-graphql/server/services/content-api/index.js:54:20)
at Object.module.exports [as bootstrap] (<folder>/node_modules/@strapi/plugin-graphql/server/bootstrap.js:26:6)
at Object.bootstrap (<folder>/node_modules/@strapi/strapi/lib/core/domain/module/index.js:40:47)
at Object.bootstrap (<folder>/node_modules/@strapi/strapi/lib/core/registries/modules.js:28:19)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  • Sample package.json
    "@strapi/plugin-graphql": "^4.1.2",
    "@strapi/plugin-i18n": "4.1.2",
    "@strapi/plugin-users-permissions": "4.1.2",
    "@strapi/strapi": "4.1.2",
    "sqlite3": "5.0.2",
    "strapi-plugin-slugify": "^2.1.1"
  • No additional plugin configuration.

  • Sample repo: https://github.com/vmptk/strapi-slug

Can you please provide the following information:

  • strapi version
  • plugin version
  • plugin configuration

If possible a reproducible example.

I'm also facing the same issue.

Strapi Version: v4.1.0
Plugin Version: 2.1.1
Plugin configuration: N/A As I've just installed the plugin and run the server.

Thanks!

Hi! Same problem over here..

Strapi Version: v4.1.2
Plugin Version: ^v2.1.1
Plugin Configuration:

(..config/plugins.js)

   slugify: {
    enabled: true,
    config: {
      contentTypes: {
        instantie: {
          field: "slug",
          references: "profiel",
        },
      },
    },
  },

Thanks in advance!

Thank you for the information. I will investigate the issue.

I did test it on my side before release and had no issues. Very strange.

I can't reproduce this issue in the exact same constellation.

@vmptk and @chan-fullstack

This looks to be a bug on strapis end.

The only way I was able to reproduce this was to not have the plugin listed in the plugins.js file. It looks like if the plugin is not listed in that file the register file for the plugin still triggers while the bootstrap one does not. That is the cause of this issue and not something I should need to fix on my end.

At minimum to fix this issue one of the following configurations in the plugins.js file is required

slugify:{
  enabled: false
}

or

slugify:{
  enabled: true
}

I was not able to reproduce the issue with either of the above configurations.

TLDR: it looks to be a bug on strapis side. The plugin should be listed in plugins.js (which it should be) with a minimum configuration.

Hi! Same problem over here..

Strapi Version: v4.1.2 Plugin Version: ^v2.1.1 Plugin Configuration:

(..config/plugins.js)

   slugify: {
    enabled: true,
    config: {
      contentTypes: {
        instantie: {
          field: "slug",
          references: "profiel",
        },
      },
    },
  },

Thanks in advance!

@mikeyfe6 do you have a reproducible example? This as this case looks to be different than the original issue, when I tried this configuration the server started with no issue.

Hello, I had the same problem and I found how to avoid the issue at least.
In the ./config/plugins.js file you need to make sure to list all the slugify configuration just before the graphql one, therefore, you need to have the graphql plugin config.

module.exports = ({ env }) => ({
    slugify: {
        enabled: true,
        config: {
            contentTypes: {
                modelName: {
                    field: 'slug',
                    references: 'title',
                },
            },
        },
    },
    graphql: {
        enabled: true,
        config: {
            defaultLimit: 10,
            maxLimit: 20,
            shadowCRUD: true,
            apolloServer: {
                tracing: true,
            },
        }
    },
})

P.S: If you switch the plugins config, you might reproduce the error.

@ComfortablyCoding with the inverted order in the plugin config it is working... definitely it is a bug in the Strapi plugin system. @maneroto thanks for the hint!!!

Updated repo: https://github.com/vmptk/strapi-slug

At the moment it does not look like plugin order can be enforced.

I will add a note about ensuring graphql is placed before the plugin config as well as a minimal config is required.

Thanks @maneroto for finding this requirement.