Skip to content

Commit 42f70df

Browse files
authored
Update README.md
1 parent 674e157 commit 42f70df

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
graphql-compose-relay
22
======================
3-
This is a plugin for `graphql-compose`, which wraps GraphQL types with Relay specific things, like `Node` type and interface, `globalId`, `clientMutationId`.
3+
This is a plugin for [graphql-compose](https://github.com/nodkz/graphql-compose), which wraps GraphQL types with Relay specific things, like `Node` type and interface, `globalId`, `clientMutationId`.
44

55
[CHANGELOG](https://github.com/nodkz/graphql-compose-relay/blob/master/CHANGELOG.md)
66

77
Example
88
=======
9+
`TypeComposer` is a [graphql-compose](https://github.com/nodkz/graphql-compose) utility, that wraps GraphQL types and provide bunch of useful methods for type manipulation.
910
```js
1011
import composeWithRelay from 'graphql-compose-relay';
12+
import { TypeComposer } from 'graphql-compose';
13+
import { RootQueryType, UserType } from './my-graphq-object-types';
1114

12-
composeWithRelay(rootQueryTypeComposer); // add `node` field to RootQuery
13-
composeWithRelay(userTypeComposer); // wrap Type with middlewares, that add relay's fields and tune resolver.
14-
composeWithRelay(someOtherTypeComposer);
15+
const rootQueryTypeComposer = new TypeComposer(RootQueryType);
16+
const userTypeComposer = new TypeComposer(UserType);
17+
18+
// If passed RootQuery, then will be added only `node` field to this type.
19+
// Via RootQuery.node you may find objects by globally unique ID among all types.
20+
composeWithRelay(rootQueryTypeComposer);
21+
22+
// Other types, like User, will be wrapped with middlewares that:
23+
// - add relay's id field. Field will be added or wrapped to return Relay's globally unique ID.
24+
// - for mutations will be added clientMutationId to input and output objects types
25+
// - this type will be added to NodeInterface for resolving via RootQuery.node
26+
composeWithRelay(userTypeComposer);
1527
```
1628
That's all!
1729

@@ -27,8 +39,6 @@ Method `composeWithRelay` accept `TypeComposer` as input argument. So `TypeCompo
2739

2840
If something is missing `composeWithRelay` throws error.
2941

30-
`TypeComposer` is [graphql-compose](https://github.com/nodkz/graphql-compose) utility, that wraps GraphQL type and provide bunch of useful methods for type manipulation.
31-
3242
Compatible plugins
3343
==================
3444
- [graphql-compose-mongoose](https://github.com/nodkz/graphql-compose-mongoose)

0 commit comments

Comments
 (0)