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
// If passed RootQuery, then will be added only `node` field to this type.
18
+
// If passed RootQuery, then will be added only `node` field to this type.
19
19
// Via RootQuery.node you may find objects by globally unique ID among all types.
20
-
composeWithRelay(rootQueryTypeComposer);
20
+
composeWithRelay(rootQueryTypeComposer);
21
21
22
22
// Other types, like User, will be wrapped with middlewares that:
23
23
// - add relay's id field. Field will be added or wrapped to return Relay's globally unique ID.
24
24
// - for mutations will be added clientMutationId to input and output objects types
25
25
// - this type will be added to NodeInterface for resolving via RootQuery.node
26
-
composeWithRelay(userTypeComposer);
26
+
composeWithRelay(userTypeComposer);
27
27
```
28
28
That's all!
29
29
30
-
No annoying `clientMutationId` manipulations (declaration, passthru, stripping from input).
31
-
No manual adding/wrapping `id` field. This field returns globally unique ID among all types in format `base64(TypeName + ':' + recordId)`.
32
-
All relay magic done internally by middleware for you.
30
+
All mutations resolvers' arguments will be placed into `input` field, and added `clientMutationId`. If `input` fields already exists in resolver, then `clientMutationId` will be added to it, rest argument stays untouched. Accepted value via `args.input.clientMutationId` will be transfer to `payload.clientMutationId`, as Relay required it.
31
+
32
+
To all wrapped Types with Relay, will be added `id` field or wrapped, if it exist already. This field will return globally unique ID among all types in the following format `base64(TypeName + ':' + recordId)`.
33
+
34
+
For `RootQuery` will be added `node` field, that will resolve by globalId only that types, which you wrap with `composeWithRelay`.
35
+
36
+
All this annoying operations is too fatigue to do by hands. So this middleware done all Relay magic implicitly for you.
33
37
34
38
Requirements
35
39
============
36
40
Method `composeWithRelay` accept `TypeComposer` as input argument. So `TypeComposer` should meet following requirements:
37
-
- has defined `recordIdFn` (function that from object gives you id)
38
-
- should have `findById` resolver
41
+
- has defined `recordIdFn` (function that from object of this type, returns you id for the globalId construction)
42
+
- should have `findById` resolver (that will be used by `RootQuery.node`)
39
43
40
44
If something is missing `composeWithRelay` throws error.
0 commit comments