Commit 0fd8be1
committed
Support more forms of async returned values.
GraphQL.js already had support for `Promise<T>` and `Promise<Array<T>>`, but not `Array<Promise<T>>`. We had assumed that resolve functions would call Promise.all when necessary based on how GraphQL had been used in the context of PHP/Hack at Facebook where `Array<Promise<T>>` is actually pretty hard to construct. In JavaScript, however, it's easy to forget a call to Promise.all and provide this kind of value.
This change makes GraphQL.js aware of `Array<Promise<T>>` and importantly enables a new expression of error handling for nullable list item types (`[T]` vs `[T!]`): If the second of an array of three values fails, we can log an error accordingly and place a null value for that index.
The primary structural change here is moving the error detection logic to after calling a field's `resolve` rather than before it. This means direct field `resolve` errors have to be dealt with directly, which is a little less elegant, but it means this error detection logic can be easily reused when completing the values of items in a list.
Finally, this adds a more comprehensive test suite for list types in permuation with nullability and Array and Promise return types.
Fixes #171 parent 099eeb7 commit 0fd8be1
File tree
5 files changed
+450
-429
lines changed- src
- __tests__
- error
- executor
- __tests__
5 files changed
+450
-429
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
98 | 101 | | |
99 | 102 | | |
100 | 103 | | |
| |||
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
111 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
49 | 59 | | |
50 | 60 | | |
51 | 61 | | |
| |||
0 commit comments