Skip to content
This repository was archived by the owner on Sep 16, 2025. It is now read-only.

Commit 6cd9b79

Browse files
fix(registration): error with default settings and gql (#52)
* fix(registration): error on install with gql Resolves #51 * chore: format
1 parent 6b28c77 commit 6cd9b79

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

server/graphql/types.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const getCustomTypes = (strapi, nexus) => {
4747
args: {
4848
modelName: nexus.stringArg('The model name of the content type'),
4949
slug: nexus.stringArg('The slug to query for'),
50-
publicationState: nexus.stringArg('The publication state of the entry')
50+
publicationState: nexus.stringArg('The publication state of the entry'),
5151
},
5252
resolve: async (_parent, args, ctx) => {
5353
const { models } = getPluginService(strapi, 'settingsService').get();
@@ -58,7 +58,7 @@ const getCustomTypes = (strapi, nexus) => {
5858
modelName,
5959
slug,
6060
models,
61-
publicationState
61+
publicationState,
6262
});
6363

6464
const { uid, field, contentType } = models[modelName];
@@ -75,7 +75,7 @@ const getCustomTypes = (strapi, nexus) => {
7575
// only return published entries by default if content type has draftAndPublish enabled
7676
if (_.get(contentType, ['options', 'draftAndPublish'], false)) {
7777
query.publicationState = publicationState || 'live';
78-
}
78+
}
7979

8080
const data = await getPluginService(strapi, 'slugService').findOne(uid, query);
8181
const sanitizedEntity = await sanitizeOutput(data, contentType, auth);

server/register.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
'use strict';
22

33
const { registerGraphlQLQuery } = require('./graphql');
4+
const { getPluginService } = require('./utils/getPluginService');
45

56
module.exports = ({ strapi }) => {
7+
const { contentTypes } = getPluginService(strapi, 'settingsService').get();
8+
9+
// ensure we have at least one model before attempting registration
10+
if (!Object.keys(contentTypes).length) {
11+
return;
12+
}
613
// add graphql query if present
714
if (strapi.plugin('graphql')) {
815
strapi.log.info('[slugify] graphql detected, registering queries');

server/utils/isValidFindSlugParams.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ const isValidFindSlugParams = (params) => {
1818
}
1919

2020
if (!_.get(model, ['contentType', 'options', 'draftAndPublish'], false) && publicationState) {
21-
throw new ValidationError('Filtering by publication state is only supported for content types that have Draft and Publish enabled.')
21+
throw new ValidationError(
22+
'Filtering by publication state is only supported for content types that have Draft and Publish enabled.'
23+
);
2224
}
2325

2426
// ensure valid model is passed

0 commit comments

Comments
 (0)