January 2019
Intermediate to advanced
460 pages
10h 33m
English
Now that the schema is ready, we need the matching resolver functions.
Create a resolvers.js file in the graphql folder as follows:
const resolvers = { RootQuery: { posts(root, args, context) { return []; }, }, }; export default resolvers;
The resolvers object holds all types as a property. We set up RootQuery, holding the posts query in the same way as we did in our schema. The resolvers object must equal the schema but recursively merged. If you want to query a subfield, such as the user of a post, you have to extend the resolvers object with a Post object containing a user function next to RootQuery.
If we send a query for all posts, the posts function is executed. There, you can do whatever you want, but ...
Read now
Unlock full access