Skip to main content
Version: Legacy

Implement Your Resolvers

GraphQL Modules lets you implement your GraphQL resolvers in a standard way, just like other GraphQL applications.

Basic Resolvers#

To get started with implementing basic resolvers, create a simple object with a 'type name → fields' mapping.

Let's take for an example the following schema for User and Query.


type Query {
user(id: ID!): User
type User {
id: ID!
username: String!

Let's implement the resolvers object. For now we will use just static mocked objects.


export default {
Query: {
user: (root, { id }) => {
return {
_id: id,
username: 'jhon',
User: {
id: (user) => user._id,
username: (user) => user.username,

Now, update your GraphQLModule declaration to load the resolvers:


import { GraphQLModule } from '@graphql-modules/core';
import * as typeDefs from './schema.graphql';
import resolvers from './resolvers';
export const MyModule = new GraphQLModule({

We can import from schema.graphql because we are doing some bundling tricks. If you need help with it, refer to the Development Environment section.

With Providers#

Providers are a first-class citizen in GraphQL Modules - they can easily interact with other modules, access modules' configurations, manage their lifecycles, and more.

To know how to use Providers, in the next step, we will take the previous example and change it to use Provider.