mirror of
https://github.com/strapi/strapi.git
synced 2025-07-31 04:45:54 +00:00

* Add basic implementation for the graphql extension service * Add createPolicyContext in @strapi/utils * policiesMiddleware implementation for graphql * wrapResolvers first implementation (authentication, middlewares, policies) * move the content API schema build from /generators to /content-api. Extract types' register functions into a dedicated folder * fix schema generation on bootstrap * update the graphql service file to match new services arch * fix single type queries * simplify entity's resolver * use apollo graphql conventions for resolver's args naming * use the graphql extension system in i18n to add a locale arg to localized queries & mutations
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
module.exports = ({ strapi }) => ({
|
|
register() {
|
|
const useExtension = strapi
|
|
.plugin('graphql')
|
|
.service('extension')
|
|
.for('content-api').use;
|
|
|
|
const { isLocalizedContentType } = strapi.plugin('i18n').service('content-types');
|
|
|
|
useExtension(({ nexus, typeRegistry }) => {
|
|
/**
|
|
* Adds a "locale" arg to localized queries and mutations
|
|
* @param {object} config
|
|
*/
|
|
const addLocaleArg = config => {
|
|
const { parentType } = config;
|
|
|
|
// Only target queries or mutations
|
|
if (parentType !== 'Query' && parentType !== 'Mutation') {
|
|
return;
|
|
}
|
|
|
|
const contentType = typeRegistry.get(config.type).config.contentType;
|
|
|
|
// Ignore non-localized content types
|
|
if (!isLocalizedContentType(contentType)) {
|
|
return;
|
|
}
|
|
|
|
config.args.locale = nexus.stringArg();
|
|
};
|
|
|
|
const i18nPlugin = nexus.plugin({
|
|
name: 'i18nPlugin',
|
|
|
|
onAddOutputField(config) {
|
|
// Add the locale arg to the queries on localized CTs
|
|
addLocaleArg(config);
|
|
},
|
|
});
|
|
|
|
return { plugins: [i18nPlugin] };
|
|
});
|
|
},
|
|
});
|