File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 1
- it . todo ( 'should behave as advertised' ) ;
1
+ import fetch from 'node-fetch' ;
2
+ import { startTServer } from './utils/tserver' ;
3
+
4
+ it ( 'should use the response returned from context' , async ( ) => {
5
+ const server = startTServer ( {
6
+ context : ( ) => {
7
+ return [ null , { status : 418 } ] ;
8
+ } ,
9
+ } ) ;
10
+
11
+ const url = new URL ( server . url ) ;
12
+ url . searchParams . set ( 'query' , '{ __typename }' ) ;
13
+ const res = await fetch ( url . toString ( ) ) ;
14
+ expect ( res . status ) . toBe ( 418 ) ;
15
+ } ) ;
Original file line number Diff line number Diff line change @@ -453,8 +453,10 @@ export function createHandler<RawRequest = unknown>(
453
453
}
454
454
455
455
if ( ! ( 'contextValue' in args ) ) {
456
- args . contextValue =
456
+ const maybeResOrContext =
457
457
typeof context === 'function' ? await context ( req , args ) : context ;
458
+ if ( isResponse ( maybeResOrContext ) ) return maybeResOrContext ;
459
+ args . contextValue = maybeResOrContext ;
458
460
}
459
461
460
462
const validationErrs = validate ( args . schema , args . document ) ;
You can’t perform that action at this time.
0 commit comments