You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To see an example call to `getLoaders`, [check out the SWAPI example](./examples/swapi/swapi-server.js) or [the tests](./__tests__/implementation.test.js).
79
79
80
+
## Batch Resources with`properties` parameters
81
+
82
+
Instead of accepting just a list ofusers (`user_ids`), a batch resource could accept both a list ofusers (`user_ids`) and a list ofproperties (`properties`) to fetch about that user:
To batch up calls to this resource with different `properties`for different `user_ids`, we specify `propertyBatchKey`in the config to describe the "properties" argument.
104
+
We specify `responseKey`in the config as the key in the response objects corresponds to `batchKey`.
105
+
106
+
The config for our `getUserInfoV2` would look like this:
107
+
108
+
```yaml
109
+
resources:
110
+
getUserInfo:
111
+
isBatchResource: true
112
+
batchKey: user_ids
113
+
newKey: user_id
114
+
propertyBatchKey: properties
115
+
responseKey: id
116
+
```
117
+
118
+
**IMPORTANTNOTE**
119
+
To use this feature, there are several restrictions. (Please open an issue if you're interested in helping us support other use cases):
120
+
121
+
**Contract**
122
+
123
+
1. The resource accepts a list of `ids` and a list of `properties`; to specify the entity IDs and the properties for each entity to fetch:
124
+
125
+
```js
126
+
({
127
+
// this is the batchKey
128
+
ids: Array<string>,
129
+
// this is the propertyBatchKey
130
+
properties: Array<string>,
131
+
}): Array<T>
132
+
```
133
+
134
+
2. In the response, `properties` are spread at the same level as the `responseKey`. (Check out `getFilmsV2` in [swapi example](./examples/swapi/swapi.js).)
135
+
3. All `properties` must be optional in the response object. The flow types currently don't handle the nullability of these properties correctly, so to enforce this, we recommend a build step to ensure that the underlying types are always set as maybe types.
136
+
4. The resource must have a one-to-one correspondence between the input "properties" and the output "properties".
137
+
-e.g. if we request property "name", the response must have "name"in it, and no extra data associated with it.
138
+
80
139
## Config File
81
140
82
141
The config file should be a [YAML](https://yaml.org/) file in the following format:
@@ -94,6 +153,8 @@ resources:
94
153
commaSeparatedBatchKey: ?string (can only use if isBatchResource=true)
95
154
isResponseDictionary: ?boolean (can only use if isBatchResource=true)
96
155
isBatchKeyASet: ?boolean (can only use if isBatchResource=true)
156
+
propertyBatchKey: ?string (can only use if isBatchResource=true)
157
+
responseKey: ?string (non-optional when propertyBatchKey is used)
97
158
98
159
typings:
99
160
language: flow
@@ -125,6 +186,8 @@ Describes the shape and behaviour of the resources object you will pass to `getL
125
186
| `commaSeparatedBatchKey` | (Optional) Set to true if the interface of the resource takes the batch key as a comma separated list (rather than an array of IDs, as is more common). Default: false |
126
187
| `isResponseDictionary` | (Optional) Set to true if the batch resource returns the results as a dictionary with key mapped to values (instead of a list of items). If this option is supplied `reorderResultsByKey` should not be. Default: false |
127
188
| `isBatchKeyASet` | (Optional) Set to true if the interface of the resource takes the batch key as a set (rather than an array). For example, when using a generated clientlib based on swagger where `uniqueItems: true` is set for the batchKey parameter. Default: false. |
189
+
| `propertyBatchKey` | (Optional) The argument to the resource that represents the optional properties we want to fetch. (e.g. usually 'properties' or 'features'). |
190
+
| `responseKey` | (Non-optional when propertyBatchKey is used) The key in the response objects corresponds to `batchKey`. This should be the only field that are marked as required in your swagger endpoint response, except nestedPath. |
0 commit comments