Skip to content

Commit 5074268

Browse files
authored
docs: improve example for screenshot
1 parent 2e93fd0 commit 5074268

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export const PersonGraphQLType = PersonTC.getType();
5858
You can write custom field configs directly to a field of your API response object via function (see `mass` and `starships_count` field):
5959

6060
```js
61+
import composeWithJson from 'graphql-compose-json';
62+
6163
const restApiResponse = {
6264
name: 'Anakin Skywalker',
6365
birth_year: '41.9BBY',
@@ -66,12 +68,15 @@ const restApiResponse = {
6668
'https://swapi.co/api/starships/65/',
6769
'https://swapi.co/api/starships/39/',
6870
],
69-
mass: () => 'Int', // by default numbers coerced to Float, here we set up Int
71+
mass: () => 'Int', // by default JSON numbers coerced to Float, here we set up Int
7072
starships_count: () => ({ // more granular field config with resolve function
7173
type: 'Int',
7274
resolve: source => source.starships.length,
7375
}),
7476
};
77+
78+
export const CustomPersonTC = composeWithJson('CustomPerson', restApiResponse);
79+
export const CustomPersonGraphQLType = CustomPersonTC.getType();
7580
```
7681

7782
## Schema building

0 commit comments

Comments
 (0)