File tree Expand file tree Collapse file tree 1 file changed +22
-25
lines changed Expand file tree Collapse file tree 1 file changed +22
-25
lines changed Original file line number Diff line number Diff line change @@ -15,12 +15,22 @@ export class Dispatcher {
15
15
this . _patches = [ ] ;
16
16
}
17
17
18
- execute ( fn : ( ) = > PromiseOrValue < mixed > , errors : Array < GraphQLError > ) {
18
+ execute (
19
+ fn : ( ) = > PromiseOrValue < mixed > ,
20
+ errors : Array < GraphQLError > ,
21
+ ) : Promise < mixed > {
19
22
try {
20
- return fn ( ) ;
23
+ const data = fn ( ) ;
24
+ if ( isPromise ( data ) ) {
25
+ return data . then ( undefined , error => {
26
+ errors . push ( error ) ;
27
+ return Promise . resolve ( null ) ;
28
+ } ) ;
29
+ }
30
+ return Promise . resolve ( data ) ;
21
31
} catch ( error ) {
22
32
errors . push ( error ) ;
23
- return null ;
33
+ return Promise . resolve ( null ) ;
24
34
}
25
35
}
26
36
@@ -31,28 +41,15 @@ export class Dispatcher {
31
41
errors : Array < GraphQLError > ,
32
42
) {
33
43
this . _patches . push (
34
- Promise . resolve ( this . execute ( fn , errors ) ) . then ( data => {
35
- if ( isPromise ( data ) ) {
36
- return data . then ( undefined , error => ( {
37
- value : {
38
- data : null ,
39
- path : pathToArray ( path ) ,
40
- label,
41
- errors : [ error ] ,
42
- } ,
43
- done : false ,
44
- } ) ) ;
45
- }
46
- return {
47
- value : {
48
- data,
49
- path : pathToArray ( path ) ,
50
- label,
51
- ...( errors && errors . length > 0 ? { errors } : { } ) ,
52
- } ,
53
- done : false ,
54
- } ;
55
- } ) ,
44
+ this . execute ( fn , errors ) . then ( data => ( {
45
+ value : {
46
+ data,
47
+ path : pathToArray ( path ) ,
48
+ label,
49
+ ...( errors && errors . length > 0 ? { errors } : { } ) ,
50
+ } ,
51
+ done : false ,
52
+ } ) ) ,
56
53
) ;
57
54
}
58
55
You can’t perform that action at this time.
0 commit comments