Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(registration): error on install with gql #52

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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