Skip to content

Commit a6a8176

Browse files
committed
adds Spread documentation #57
1 parent ac403ea commit a6a8176

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Diff for: README.md

+35
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ name = Proxy
8282
- [Decoding and Encoding JSON](#decoding-and-encoding-json)
8383
- [Arguments](#arguments)
8484
- [Aliases](#aliases)
85+
- [Dynamically spread Aliases](#dynamically-spread-aliases)
8586
- [Variables](#variables)
8687
- [Full responses](#full-responses)
8788
- [Apollo only features](#apollo-only-features)
@@ -414,6 +415,40 @@ query client "my_alias_query"
414415
}
415416
```
416417

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+
417452
### Variables
418453

419454
It is possible to define variables using the `Var` contructor

0 commit comments

Comments
 (0)