Creating Basic Resolvers: Linking Schema Fields to Data
Learn to build a GraphQL resolver map. We show you how to link your schema definitions to the actual JavaScript functions that fetch your API's data.

Previously in this course, we used defining the typeDefs for your Apollo Server project to establish the structure of our API. While your typeDefs define the "what," they don't know how to fetch the data.
That is the job of resolvers. Without them, your GraphQL server is just a static blueprint; resolvers are the engine that executes the logic to retrieve the data your clients request.
What is a Resolver Map?
In GraphQL, a resolver map is a JavaScript object that mirrors the structure of your schema. Every field you define in your typeDefs must have a corresponding function in your resolver map if you want that field to return data.
Think of it like a directory: when a query arrives, GraphQL looks at the requested field, checks your resolver map, and executes the associated function to get the value.
Anatomy of a Resolver
A basic resolver is simply a function that returns a value (or a promise that resolves to a value). Here is a simple example of a resolver map:
JAVASCRIPTconst resolvers = { Query: { hello: () => CE9178">'Hello, world!', version: () => CE9178">'1.0.0' } };
If your schema defined type Query { hello: String, version: String }, the resolver map above tells Apollo Server exactly how to satisfy those fields.
Linking Schema Fields to Functions

To make this work in your project, you need to ensure the keys in your resolvers object match the types and fields in your typeDefs. If you have a Query type in your schema, you must have a Query property in your resolvers object.
Let’s advance our project by implementing a basic resolver structure.
Worked Example: Building a Resolver Map
Suppose your typeDefs look like this:
JAVASCRIPTconst typeDefs = CE9178">`#graphql type Query { serverStatus: String uptime: Int } `;
To provide the data, you would define your resolver map like this:
JAVASCRIPTconst resolvers = { Query: { // This function runs when a client queries CE9178">'serverStatus' serverStatus: () => { return "Online"; }, // This function runs when a client queries CE9178">'uptime' uptime: () => { return 120; // Imagine this comes from a system call } } };
In this setup, every time a client asks for serverStatus, the serverStatus function executes and returns the string "Online".
Practice Exercise
- Open your project from installing apollo-server and graphql packages.
- Create a new file called
resolvers.js. - Export a
resolversobject that contains aQueryfield. - Add a function called
greetingsthat returns the string"Welcome to my GraphQL API!". - Import this
resolversobject into your main server file (where you initialize ApolloServer).
Common Pitfalls

- Mismatched Names: If your schema field is called
userProfilebut your resolver function is nameduserprofile(lowercase 'p'), GraphQL won't be able to link them. Names are case-sensitive. - Missing Resolvers: If you define a field in your schema but forget to include a function for it in your resolver map, that field will return
null(unless the field is marked as non-nullable, in which case the server will throw an error). - Returning Promises: Resolvers are often asynchronous. If your resolver returns a promise, GraphQL will wait for that promise to resolve before returning the data to the client. Ensure you handle your
async/awaitlogic correctly.
Frequently Asked Questions
Do I need a resolver for every single field?
Yes. Every field in your schema, from root queries down to nested object fields, requires a resolver function. If you don't provide one, GraphQL uses a default resolver that looks for a property with the same name on the parent object.
Can a resolver return an object?
Absolutely. If your schema defines a field as an object type (e.g., user: User), your resolver should return an object that contains the data for that type.
Does the order of fields in the resolver map matter?
No. JavaScript objects are unordered, and GraphQL looks up resolvers by key name, not by the order in which they appear in the file.
Recap

Resolvers are the bridge between your schema and your data sources. By creating a resolver map that mirrors your typeDefs, you tell GraphQL exactly how to fulfill requests. Remember: match your names exactly, ensure every field is covered, and remember that these are just standard JavaScript functions.
Up next: We will learn how to open the Apollo Sandbox to execute your first real queries against the server we’ve just wired up.
Work with me

Laravel REST API Development
Clean, secure, well-documented Laravel REST APIs — the backend engine for your app, mobile client, or SaaS. Built by an API specialist.

AI Automation & Agentic Workflow Development
Automate the repetitive work eating your time — content pipelines, data workflows, and agentic AI tasks that run themselves.


