Handle subscriptions in wrapResolvers

This commit is contained in:
Convly 2021-09-29 13:35:26 +02:00
parent c1e3c41cbd
commit 96ac7e314b

View File

@ -30,8 +30,9 @@ const wrapResolvers = ({ schema, strapi, extension = {} }) => {
// Fields filters
const isValidFieldName = ([field]) => !field.startsWith('__');
const typeMap = schema.getTypeMap();
const typesMaps = [schema.getTypeMap(), schema.getSubscriptionType().getFields()];
typesMaps.forEach(typeMap =>
// Iterate over every field from every type within the
// schema's type map and wrap its resolve attribute if needed
Object.entries(typeMap).forEach(([type, definition]) => {
@ -81,12 +82,12 @@ const wrapResolvers = ({ schema, strapi, extension = {} }) => {
const authConfig = get('auth', resolverConfig);
const authContext = get('state.auth', context);
const isMutationOrQuery = ['Mutation', 'Query'].includes(type);
const isValidType = ['Mutation', 'Query', 'Subscription'].includes(type);
const hasConfig = !isNil(authConfig);
const isAuthDisabled = authConfig === false;
if ((isMutationOrQuery || hasConfig) && !isAuthDisabled) {
if ((isValidType || hasConfig) && !isAuthDisabled) {
try {
await strapi.auth.verify(authContext, authConfig);
} catch (error) {
@ -111,7 +112,8 @@ const wrapResolvers = ({ schema, strapi, extension = {} }) => {
return first(boundMiddlewares).call(null, parent, args, context, info);
};
}
});
})
);
return schema;
};