@@ -82,6 +82,7 @@ name = Proxy
82
82
- [ Decoding and Encoding JSON] ( #decoding-and-encoding-json )
83
83
- [ Arguments] ( #arguments )
84
84
- [ Aliases] ( #aliases )
85
+ - [ Dynamically spread Aliases] ( #dynamically-spread-aliases )
85
86
- [ Variables] ( #variables )
86
87
- [ Full responses] ( #full-responses )
87
88
- [ Apollo only features] ( #apollo-only-features )
@@ -414,6 +415,40 @@ query client "my_alias_query"
414
415
}
415
416
```
416
417
418
+ #### Dynamically spread Aliases
419
+
420
+ Sometimes it is useful to create aliased queries or mutations from a collection of size unknown at compile time.
421
+
422
+ In a dynamic language you might fold a collection of users to create a graphql query like:
423
+
424
+ ``` gql
425
+ mutation myUpdates {
426
+ _1 : update_users (where : {id : 1 }, _set : { value : 10 }) { affected_rows }
427
+ _2 : update_users (where : {id : 2 }, _set : { value : 15 }) { affected_rows }
428
+ _3 : update_users (where : {id : 3 }, _set : { value : 20 }) { affected_rows }
429
+ }
430
+ ```
431
+
432
+ To do this there is there is the ` Spread ` constructor that creates these aliases for you and decodes the response as an array.
433
+
434
+ eg.
435
+ ``` purs
436
+
437
+ import GraphQL.Client.Alias.Dynamic (Spread(..))
438
+ import Generated.Symbols (update_users) -- Or wherever your symbols module is
439
+
440
+ ...
441
+ query client "update_multiple_users"
442
+ $ Spread update_users
443
+ [ { where: { id: 1}, _set: { value: 10 } }
444
+ , { where: { id: 2}, _set: { value: 15 } }
445
+ , { where: { id: 3}, _set: { value: 20 } }
446
+ ]
447
+ { affected_rows }
448
+ ```
449
+
450
+ Look alias example in the examples directory for more details.
451
+
417
452
### Variables
418
453
419
454
It is possible to define variables using the ` Var ` contructor
0 commit comments