Skip to content

Commit fe7c9f7

Browse files
authored
docs: simplify async example
1 parent 0616535 commit fe7c9f7

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,17 @@ export const buildAsyncSchema = async (): Promise<GraphQLSchema> => {
169169
const jsonData = await data.json();
170170

171171
const PeopleTC = composeWithJson('People', jsonData);
172-
PeopleTC.addResolver({
173-
name: 'findById',
174-
type: PeopleTC,
175-
args: {
176-
id: 'Int!',
177-
},
178-
resolve: rp => {
179-
return fetch(`https://swapi.co/api/people/${rp.args.id}/`).then(r => r.json());
180-
},
181-
});
182172

183173
schemaComposer.Query.addFields({
184-
person: PeopleTC.getResolver('findById'),
174+
person: {
175+
type: PeopleTC,
176+
args: {
177+
id: 'Int!',
178+
},
179+
resolve: (_, args) => {
180+
return fetch(`https://swapi.co/api/people/${args.id}/`).then(r => r.json());
181+
},
182+
},
185183
});
186184

187185
const schema = schemaComposer.buildSchema();

0 commit comments

Comments
 (0)