Remove login, register, me from only graphql schema

System Information
  • Strapi Version: 4.5.1
  • Operating System: Mac OS Monterey
  • Database: postgres
  • Node Version: 16.15.1
  • NPM Version: 8.11.0
  • Yarn Version: 1.22.17

I’m trying to use apollo federation with Strapi but I can’t compose the supergraph because our existing graphql schema already has login, register, and me. I don’t need to include anything but our custom content types in the graphql schema but I can’t seem to remove the login features.

Considering that these features come from the user-permissions plugin (strapi/users-permissions.js at cf49ddbbfc33fa6a0145f9ddf50677e31c1d711e · strapi/strapi · GitHub)
It would make sense that if I disable that plugin for the graphql extension service it would remove them. Something like this

 register({ strapi }) {
    const extensionService = strapi.plugin('graphql').service('extension');
    extensionService.shadowCRUD('plugin::users-permissions.permission').disable();
    extensionService.shadowCRUD('plugin::users-permissions.role').disable();
    extensionService.shadowCRUD('plugin::users-permissions.user').disable();
}

unfortunately throws a nexus error when trying to generate the schema

[2022-12-07 15:49:44.667] error: NEXUS__UNKNOWN__TYPE was already defined and imported as a type, check the docs for extending types
Error: NEXUS__UNKNOWN__TYPE was already defined and imported as a type, check the docs for extending types
    at extendError (/Users/kyle/flymachine/fm-content-manager/node_modules/nexus/dist/builder.js:1123:12)
    at SchemaBuilder.addType (/Users/kyle/flymachine/fm-content-manager/node_modules/nexus/dist/builder.js:156:27)
    at SchemaBuilder.missingType (/Users/kyle/flymachine/fm-content-manager/node_modules/nexus/dist/builder.js:704:14)
    at SchemaBuilder.getOrBuildType (/Users/kyle/flymachine/fm-content-manager/node_modules/nexus/dist/builder.js:938:21)
    at SchemaBuilder.getInputType (/Users/kyle/flymachine/fm-content-manager/node_modules/nexus/dist/builder.js:868:34)
    at SchemaBuilder.buildArgs (/Users/kyle/flymachine/fm-content-manager/node_modules/nexus/dist/builder.js:850:64)
    at SchemaBuilder.buildOutputField (/Users/kyle/flymachine/fm-content-manager/node_modules/nexus/dist/builder.js:799:24)
    at /Users/kyle/flymachine/fm-content-manager/node_modules/nexus/dist/builder.js:770:43
    at Array.forEach (<anonymous>)
    at SchemaBuilder.buildOutputFields (/Users/kyle/flymachine/fm-content-manager/node_modules/nexus/dist/builder.js:769:16)
    at fields (/Users/kyle/flymachine/fm-content-manager/node_modules/nexus/dist/builder.js:544:32)
    at resolveThunk (/Users/kyle/flymachine/fm-content-manager/node_modules/graphql/type/definition.js:480:40)
    at defineFieldMap (/Users/kyle/flymachine/fm-content-manager/node_modules/graphql/type/definition.js:692:18)
    at GraphQLObjectType.getFields (/Users/kyle/flymachine/fm-content-manager/node_modules/graphql/type/definition.js:633:27)
    at collectReferencedTypes (/Users/kyle/flymachine/fm-content-manager/node_modules/graphql/type/schema.js:366:81)
    at new GraphQLSchema (/Users/kyle/flymachine/fm-content-manager/node_modules/graphql/type/schema.js:148:9)

trying to disable all queries or mutations with disableQueries or disableMutations only removes the queries like this:

usersPermissionsUser(id: ID): UsersPermissionsUserEntityResponse

Trying to target the uid in the link above with

extensionService.shadowCRUD('plugin::users-permissions.auth.register').disable();

Does anyone know how to disable these login features from the graphql api?

1 Like

I have a similar problem: me is clashing with an existing field in my schema. How can I disable this from the Strapi graphql schema?

Has there been any solutions for this? Also having trouble trying to disable some plugin::users-permissions.auth actions

This is a really dirty workaround: you can user something like that :

    const fs = require("fs");
    const content = "module.exports = ({ nexus }) => {}";
    const rootPath = require("path").resolve("./");
    fs.writeFileSync(
        rootPath +
        "/node_modules/@strapi/plugin-users-permissions/server/graphql/queries/index.js",
        content,
        { encoding: "utf8", flag: "w" }
    );

it’s not asynchronous, it’s heavy in terms of performances since you open a file then rewrite it and it is one of the dirtiest way to do it but it does the job.

still looking for a better solution

I’ve run into this issue as well. I’m able to fully disable the permission content-type, but the others cause the NEXUS__UNKNOWN__TYPE error on restart.

This happens for several plugins. Basically, I’d like to fully disable shadowCRUD for the built-in content-types (permissions, i18, upload, etc.) and only generate graphql schema for my own content-types.

The following allows the server to start, but does not fully disable the plugins as desired.

graphqlExt.shadowCRUD('plugin::users-permissions.permission').disable()
graphqlExt.shadowCRUD('plugin::users-permissions.role').disableQueries()
graphqlExt.shadowCRUD('plugin::users-permissions.role').disableMutations()
graphqlExt.shadowCRUD('plugin::users-permissions.user').disableQueries()
graphqlExt.shadowCRUD('plugin::users-permissions.user').disableMutations()
1 Like

facing the same error with the latest strapi 4.16.0 Did you find any fix?

Yarn works (1.22), npm (18.19.0 + npm 10.2.3) does not.