@@ -109,15 +109,21 @@ export type ExecutionResult = {
109
109
} ;
110
110
111
111
/**
112
- * A partial result of GraphQL execution.
113
- *
114
- * - `errors` is included when any errors occurred as a non-empty array.
115
- * - `data` is the result of a successful execution of the query.
112
+ * A partial result of GraphQL execution. `data` and `errors` as above.
113
+ * "NP" = "Not Promise".
116
114
*/
117
- export type ExecutionPartialResult < T > = MaybePromise < {
115
+ export type ExecutionPartialResultNP < T > = {
118
116
errors ?: $ReadOnlyArray < GraphQLError > ,
119
117
data ?: T | null ,
120
- } > ;
118
+ } ;
119
+
120
+ /**
121
+ * A partial result of GraphQL execution. `data` and `errors` as above.
122
+ * This version might be a promise.
123
+ */
124
+ export type ExecutionPartialResult < T > = MaybePromise <
125
+ ExecutionPartialResultNP < T > ,
126
+ > ;
121
127
122
128
export type ExecutionArgs = { |
123
129
schema : GraphQLSchema ,
@@ -240,18 +246,8 @@ function executeImpl(
240
246
*/
241
247
function mergeErrors (
242
248
context : ExecutionContext ,
243
- result : ExecutionPartialResult < mixed > ,
244
- ): ExecutionPartialResult< mixed > {
245
- invariant ( ! getPromise ( result ) , 'Cannot call on a Promise.' ) ;
246
- // this contortion is to persuade Flow that it really really is a Promise
247
- if (
248
- result instanceof Promise ||
249
- ( typeof result === 'object' &&
250
- result !== null &&
251
- typeof result . then === 'function' )
252
- ) {
253
- throw new Error ( 'Cannot call on a Promise.' ) ;
254
- }
249
+ result : ExecutionPartialResultNP < mixed > ,
250
+ ): ExecutionPartialResultNP< mixed > {
255
251
const errors = context . errors ;
256
252
context . errors = [ ] ;
257
253
return { data : result . data , errors : [ ...errors , ...( result . errors || [ ] ) ] } ;
@@ -598,8 +594,8 @@ function executeFields(
598
594
}
599
595
600
596
function mergeEPRs (
601
- eprMap : ObjMap < ExecutionPartialResult < mixed > > ,
602
- ) : ExecutionPartialResult < mixed > {
597
+ eprMap : ObjMap < ExecutionPartialResultNP < mixed > > ,
598
+ ) : ExecutionPartialResultNP < mixed > {
603
599
const keys = Object . keys ( eprMap ) ;
604
600
const values = keys . map ( name => eprMap [ name ] ) ;
605
601
return values . reduce (
@@ -743,9 +739,9 @@ function doesFragmentConditionMatch(
743
739
* This is akin to bluebird's `Promise.props`, but implemented only using
744
740
* `Promise.all` so it will work with any implementation of ES6 promises.
745
741
*/
746
- function promiseForObject< T > (
747
- object: ObjMap< ExecutionPartialResult < T > > ,
748
- ) : ExecutionPartialResult < T > {
742
+ function promiseForObject(
743
+ object: ObjMap< Promise < ExecutionPartialResultNP < mixed > >> ,
744
+ ) : Promise < ExecutionPartialResultNP < mixed > > {
749
745
const keys = Object . keys ( object ) ;
750
746
const valuesAndPromises = keys . map ( name => object [ name ] ) ;
751
747
return Promise . all ( valuesAndPromises )
@@ -1142,8 +1138,8 @@ function completeListValue(
1142
1138
}
1143
1139
1144
1140
function flattenEPRs (
1145
- eprs : $ReadOnlyArray < ExecutionPartialResult < mixed >> ,
1146
- ) : ExecutionPartialResult < mixed > {
1141
+ eprs : $ReadOnlyArray < ExecutionPartialResultNP < mixed >> ,
1142
+ ) : ExecutionPartialResultNP < mixed > {
1147
1143
const errors = [ ] ;
1148
1144
const data = [ ] ;
1149
1145
forEach ( ( eprs : any ) , item => {
0 commit comments