Skip to content

Commit

Permalink
feat(gql): add local support
Browse files Browse the repository at this point in the history
Resolves #50
  • Loading branch information
ComfortablyCoding committed Oct 25, 2022
1 parent 8381b32 commit cfedb69
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/graphql/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ const getCustomTypes = (strapi, nexus) => {
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'),
locale: nexus.stringArg('The locale for the entry'),
},
resolve: async (_parent, args, ctx) => {
const { modelsByName } = getPluginService('settingsService').get();
const { modelName, slug, publicationState } = args;
const { modelName, slug, publicationState, locale } = args;
const { auth } = ctx.state;

isValidFindSlugParams({
Expand All @@ -77,6 +78,17 @@ const getCustomTypes = (strapi, nexus) => {
query.publicationState = publicationState || 'live';
}

const isLocaleFieldEnabled = strapi
.plugin('graphql')
.service('extension')
.shadowCRUD(uid)
.field('locale')
.isEnabled();

if (isLocaleFieldEnabled) {
query.locale = locale || 'en';
}

const data = await getPluginService('slugService').findOne(uid, query);
const sanitizedEntity = await sanitizeOutput(data, contentType, auth);
return toEntityResponse(sanitizedEntity, { resourceUID: uid });
Expand Down

0 comments on commit cfedb69

Please sign in to comment.