Skip to content

Support applying middleware to both subscription subscribe and resolve functions#569

Open
cuzzlor wants to merge 1 commit into
maticzav:masterfrom
cuzzlor:support-subscription-subscribe-middleware
Open

Support applying middleware to both subscription subscribe and resolve functions#569
cuzzlor wants to merge 1 commit into
maticzav:masterfrom
cuzzlor:support-subscription-subscribe-middleware

Conversation

@cuzzlor
Copy link
Copy Markdown

@cuzzlor cuzzlor commented Aug 22, 2023

Problem defn

When using GraphQL shield to apply rules across the schema, subscription rules are not executed for subscription subscribe operations.

Issue

The applyMiddlewareToField function does not take into account that subscription resolvers can have both subscribe and resolve functions defined.

When applyMiddlewareToField runs, if resolve is defined, subscribe is ignored.

This means that GraphQL shield rules (and other middlewares) are not applied to subscription subscribe operations.

Proposed fix

@leiyangyou posted a patch over here:
#561

This patch worked for me, allowing GraphQL shield middleware rules to be executed during the subscribe operation of subscriptions.

All the tests pass with this variant of applyMiddlewareToField, however it is a pretty solid change to the function's structure.

I was not quickly able to work out how to add a test validating the proposed fix.

…e applied to both subscribe and resolve subscription resolver functions
@lucalas
Copy link
Copy Markdown

lucalas commented Apr 22, 2025

@maticzav any updates on this?

@SteinarTho
Copy link
Copy Markdown

Running into the same error, would be great to have this feature 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants