mirror of
https://github.com/strapi/strapi.git
synced 2025-08-26 09:42:09 +00:00
Handle subscriptions in wrapResolvers
This commit is contained in:
parent
c1e3c41cbd
commit
96ac7e314b
@ -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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user