File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ export const PersonGraphQLType = PersonTC.getType();
5858You 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+
6163const 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
You can’t perform that action at this time.
0 commit comments