Skip to content

Commit

Permalink
fix(registration): error with default settings and gql (#52)
Browse files Browse the repository at this point in the history
* fix(registration): error on install with gql

Resolves #51

* chore: format
  • Loading branch information
ComfortablyCoding authored Apr 8, 2022
1 parent 6b28c77 commit 6cd9b79
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions server/graphql/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const getCustomTypes = (strapi, nexus) => {
args: {
modelName: nexus.stringArg('The model name of the content type'),
slug: nexus.stringArg('The slug to query for'),
publicationState: nexus.stringArg('The publication state of the entry')
publicationState: nexus.stringArg('The publication state of the entry'),
},
resolve: async (_parent, args, ctx) => {
const { models } = getPluginService(strapi, 'settingsService').get();
Expand All @@ -58,7 +58,7 @@ const getCustomTypes = (strapi, nexus) => {
modelName,
slug,
models,
publicationState
publicationState,
});

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

const data = await getPluginService(strapi, 'slugService').findOne(uid, query);
const sanitizedEntity = await sanitizeOutput(data, contentType, auth);
Expand Down
7 changes: 7 additions & 0 deletions server/register.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
'use strict';

const { registerGraphlQLQuery } = require('./graphql');
const { getPluginService } = require('./utils/getPluginService');

module.exports = ({ strapi }) => {
const { contentTypes } = getPluginService(strapi, 'settingsService').get();

// ensure we have at least one model before attempting registration
if (!Object.keys(contentTypes).length) {
return;
}
// add graphql query if present
if (strapi.plugin('graphql')) {
strapi.log.info('[slugify] graphql detected, registering queries');
Expand Down
4 changes: 3 additions & 1 deletion server/utils/isValidFindSlugParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const isValidFindSlugParams = (params) => {
}

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

// ensure valid model is passed
Expand Down

0 comments on commit 6cd9b79

Please sign in to comment.