8. Resolvers and data sources
1m

Progress update

Let's revisit what we've built so far. We've got a working GraphQL server, which has the schema for validating requests. We can return data in a form that matches the queries the client team wants to use on the frontend.

TODO alt text

What next? We want to replace our mock data with actual Catstronaut data! That means we'll need resolvers and data sources.

TODO alt text

Resolvers

A resolver is a function that returns data to populate a specific field in the schema.

How does it do that? By getting data from other services, like REST APIs or databases.

  • Where our data will come from: Catstronauts REST API

Data sources

How do we connect our resolvers to the Catstronauts REST API? We could use something like node-fetch to query the REST API directly. But there's a tool that will make things work better: the RESTDataSource class from Apollo.

The RESTDataSource class includes performance optimizations like caching and de-duplicating requests.

TODO: alt text

Resources:

  • Apollo Docs: Data sources. Includes a list of other commonly used data sources.
Previous
Next