use default config instead of the dedicated service

This commit is contained in:
Convly 2021-11-10 16:04:32 +01:00
parent f025deffe9
commit a7592e04a9
8 changed files with 31 additions and 49 deletions

View File

@ -31,9 +31,9 @@ module.exports = async ({ strapi }) => {
return;
}
const { config } = strapi.plugin('graphql').service('utils');
const { config } = strapi.plugin('graphql');
const path = config.endpoint;
const path = config('endpoint');
const defaultServerConfig = {
// Schema
@ -46,7 +46,7 @@ module.exports = async ({ strapi }) => {
}),
// Validation
validationRules: [depthLimit(config.depthLimit)],
validationRules: [depthLimit(config('depthLimit'))],
// Errors
formatError: formatGraphqlError,
@ -63,10 +63,10 @@ module.exports = async ({ strapi }) => {
],
};
const serverConfig = merge(defaultServerConfig, config.apolloServer);
const serverConfig = merge(defaultServerConfig, config('apolloServer'));
// Handle subscriptions
if (config.subscriptions) {
if (config('subscriptions')) {
const subscriptionServer = SubscriptionServer.create(
{ schema, execute, subscribe },
{ server: strapi.server.httpServer, path }

View File

@ -0,0 +1,13 @@
'use strict';
module.exports = {
shadowCRUD: true,
endpoint: '/graphql',
subscriptions: false,
maxLimit: -1,
apolloServer: {},
};

View File

@ -0,0 +1,7 @@
'use strict';
const defaultConfig = require('./default-config');
module.exports = {
default: defaultConfig,
};

View File

@ -27,7 +27,7 @@ const {
module.exports = ({ strapi }) => {
const { service: getGraphQLService } = strapi.plugin('graphql');
const { config } = getGraphQLService('utils');
const { config } = strapi.plugin('graphql');
const { KINDS, GENERIC_MORPH_TYPENAME } = getGraphQLService('constants');
const extensionService = getGraphQLService('extension');
@ -38,7 +38,7 @@ module.exports = ({ strapi }) => {
let builders;
const buildSchema = () => {
const isShadowCRUDEnabled = !!config.shadowCRUD;
const isShadowCRUDEnabled = !!config('shadowCRUD');
// Create a new empty type registry
registry = getGraphQLService('type-registry').new();

View File

@ -25,7 +25,7 @@ const introspectionQueries = [
* @return {GraphQLSchema}
*/
const wrapResolvers = ({ schema, strapi, extension = {} }) => {
const { config: graphQLConfig } = strapi.plugin('graphql').service('utils');
const { config: graphQLConfig } = strapi.plugin('graphql');
// Get all the registered resolvers configuration
const { resolversConfig = {} } = extension;
@ -34,7 +34,7 @@ const wrapResolvers = ({ schema, strapi, extension = {} }) => {
const typeMap = schema.getTypeMap();
if (!graphQLConfig.subscriptions) {
if (!graphQLConfig('subscriptions')) {
delete typeMap.Subscription;
}

View File

@ -1,38 +0,0 @@
'use strict';
/**
* GraphQL config helper with consistent defaults values
*/
module.exports = ({ strapi }) => {
const { config: graphQLConfig } = strapi.plugin('graphql');
return {
get shadowCRUD() {
return graphQLConfig('shadowCRUD', true);
},
get subscriptions() {
return graphQLConfig('subscriptions', false);
},
get endpoint() {
return graphQLConfig('endpoint', '/graphql');
},
get defaultLimit() {
return graphQLConfig('defaultLimit');
},
get maxLimit() {
return graphQLConfig('maxLimit', -1);
},
get depthLimit() {
return graphQLConfig('depthLimit');
},
get apolloServer() {
return graphQLConfig('apolloServer', {});
},
};
};

View File

@ -3,11 +3,9 @@
const mappers = require('./mappers');
const attributes = require('./attributes');
const naming = require('./naming');
const config = require('./config');
module.exports = context => ({
naming: naming(context),
attributes: attributes(context),
mappers: mappers(context),
config: config(context),
});

View File

@ -2,9 +2,11 @@
const bootstrap = require('./server/bootstrap');
const services = require('./server/services');
const config = require('./server/config');
module.exports = (/* strapi, config */) => {
return {
config,
bootstrap,
services,
};