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