@@ -31,24 +31,24 @@ import fs from 'node:fs/promises';
3131 * Dynamic header provider for GraphQL requests.
3232 *
3333 * @param params - The GraphQL query parameters
34- * @param context - Optional context from contextProvider (e.g., auth tokens)
34+ * @param requestContext - Optional request context from the execution environment (e.g., user info , auth tokens)
3535 */
3636export type GraphQLAuthProvider = (
3737 params ?: Record < string , any > ,
38- context ?: Record < string , any >
38+ requestContext ?: Record < string , any >
3939) => Promise < Record < string , string > > | Record < string , string > ;
4040
4141/**
4242 * Resolve headers for GraphQL requests based on auth options
4343 * Priority: headerProvider > authProvider + auth > static headers
4444 * @param options - Load options including auth config
4545 * @param params - Optional request params passed to headerProvider for dynamic resolution
46- * @param executionContext - Optional execution context passed from handler (contains requestContext )
46+ * @param requestContext - Optional request context from the execution environment (e.g., user info, auth tokens )
4747 */
4848async function resolveHeaders (
4949 options : LoadGraphQLOptions ,
5050 params ?: Record < string , any > ,
51- executionContext ?: Record < string , any >
51+ requestContext ?: Record < string , any >
5252) : Promise < Record < string , string > > {
5353 const headers : Record < string , string > = { } ;
5454
@@ -65,10 +65,11 @@ async function resolveHeaders(
6565 }
6666
6767 if ( options . headerProvider ) {
68- const context = options . contextProvider
69- ? await options . contextProvider ( executionContext )
70- : undefined ;
71- const dynamicHeaders = await options . headerProvider ( params , context ) ;
68+ let ctx = requestContext ;
69+ if ( options . contextProvider ) {
70+ ctx = await options . contextProvider ( requestContext ) ;
71+ }
72+ const dynamicHeaders = await options . headerProvider ( params , ctx ) ;
7273 Object . assign ( headers , dynamicHeaders ) ;
7374 }
7475
@@ -193,10 +194,11 @@ export interface LoadGraphQLOptions {
193194 headers ?: Record < string , string > ;
194195 /** Auth provider for dynamic credential resolution */
195196 authProvider ?: AuthProvider ;
196- /** Dynamic header provider function - called before each request */
197+ /** Dynamic header provider function - called before each request with params and requestContext */
197198 headerProvider ?: GraphQLAuthProvider ;
198- /** Context provider - called before each request to get current context (e.g., auth tokens).
199- * Receives execution context which may contain requestContext from execute() call. */
199+ /**
200+ * @deprecated Use headerProvider instead, which now receives requestContext directly as its second parameter.
201+ */
200202 contextProvider ?: (
201203 executionContext ?: Record < string , any >
202204 ) => Record < string , any > | Promise < Record < string , any > > ;
@@ -342,7 +344,7 @@ function convertFieldToFunction(
342344 description,
343345 inputSchema,
344346 outputSchema,
345- handler : async ( params : unknown , context ?: { metadata ?: Record < string , any > } ) => {
347+ handler : async ( params : unknown , context ?: { metadata ?: Record < string , any > ; requestContext ?: Record < string , unknown > } ) => {
346348 const paramsObj = ( params as Record < string , any > ) || { } ;
347349 const customFields = paramsObj . _fields ;
348350
@@ -373,8 +375,7 @@ function convertFieldToFunction(
373375 context . metadata . graphql_variables = variables ;
374376 }
375377
376- // Pass execution context (including requestContext) to resolveHeaders
377- const headers = await resolveHeaders ( options , paramsObj , context ) ;
378+ const headers = await resolveHeaders ( options , paramsObj , context ?. requestContext ) ;
378379
379380 const fetchFn = options . fetcher || fetch ;
380381 const response = await fetchFn ( url , {
0 commit comments