-
Notifications
You must be signed in to change notification settings - Fork 134
Open
Description
Discussed in #2363
Originally posted by ethdev279 January 11, 2025
I’m using @envelop/generic-auth in my GraphQL Yoga server, following this example. I’ve set mode to protect-granular, expecting the resolveUserFn to only be called for fields marked with the @authenticated directive. However, I noticed that resolveUserFn is being called for all fields, including public fields that don’t require authentication.
This behavior adds unnecessary overhead for fields that don’t need user resolution or validation.
What I was expecting:
In protect-granular mode:
resolveUserFnshould only be invoked for fields marked with the@authenticateddirective.- Public fields should bypass user resolution and validation.
Actual Behavior
resolveUserFnis executed for all fields, including public fields, leading to unnecessary overhead.
Reproduction
-
Schema:
directive @authenticated on FIELD_DEFINITION type Query { requiresAuth: String @authenticated public: String }
-
Plugin setup in GraphQL Yoga:
useGenericAuth({ mode: 'protect-granular', async resolveUserFn(context) { const token = context.request.headers.get('x-authorization'); // further validations: decoding, getting user deails from db e.t.c. return token ?? null; }, });
-
Query:
query { public }
-
Observe that
resolveUserFnis called for thepublicfield.
any thoughts on this?
Metadata
Metadata
Assignees
Labels
No labels