Skip to content

A utility to check for missing resolvers in a GraphQL schema. This package helps you ensure that all fields in your schema have appropriate resolvers.

License

Notifications You must be signed in to change notification settings

helgastogova/graphql-missing-resolvers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graphql-missing-resolvers

A utility to check for missing resolvers in a GraphQL schema. This package helps you ensure that all fields in your schema have appropriate resolvers.

Installation

npm install graphql-missing-resolvers

or

pnpm install graphql-missing-resolvers

or

yarn add graphql-missing-resolvers

Usage

  1. Import the checkMissingResolvers function from the graphql-missing-resolvers package:
import { checkMissingResolvers } from 'graphql-missing-resolvers';
  1. Use the checkMissingResolvers function with your GraphQL schema:
import { makeExecutableSchema } from '@graphql-tools/schema';
import { typeDefs, resolvers } from './schema';
import { checkMissingResolvers } from 'graphql-missing-resolvers';

const schema = makeExecutableSchema({ typeDefs, resolvers });

checkMissingResolvers(schema);

The checkMissingResolvers function will analyze your GraphQL schema and log a warning message for each field without a resolver.

You can also pass a boolean checkNested parameter to check for missing resolvers in nested object types. By default, checkNested is set to false. Here's an example of using the checkNested parameter:

import { makeExecutableSchema } from '@graphql-tools/schema';
import { typeDefs, resolvers } from './schema';
import { checkMissingResolvers } from 'graphql-missing-resolvers';

const schema = makeExecutableSchema({ typeDefs, resolvers });

checkMissingResolvers(schema, true);

In this example, the checkMissingResolvers function will check for missing resolvers in nested object types.

Example

Consider the following schema and resolvers:

// schema.ts
import { gql } from 'graphql-tag';

export const typeDefs = gql`
  type Query {
    hello: String!
    user: User!
  }

  type User {
    id: Int!
    name: String!
  }
`;

export const resolvers = {
  Query: {
    hello: () => 'Hello, world!',
    user: () => ({ id: 1, name: 'Alice' }),
  },
  User: {
    id: (user: any) => user.id,
  },
};

Import the checkMissingResolvers function and use it with your schema:

// index.ts
import { makeExecutableSchema } from '@graphql-tools/schema';
import { typeDefs, resolvers } from './schema';
import { checkMissingResolvers } from 'graphql-missing-resolvers';

const schema = makeExecutableSchema({ typeDefs, resolvers });

checkMissingResolvers(schema);

In this example, the User.name field is missing a resolver. When you run your project, the checkMissingResolvers function will log a warning message:

Missing resolver for field: User.name

To use this package, you will need to install both @graphql-tools/schema and graphql packages as dependencies in your project. You can install these packages using npm by running the following command in your project directory:

npm install @graphql-tools/schema graphql

or

pnpm install @graphql-tools/schema graphql

or

yarn add @graphql-tools/schema graphql

Once these packages are installed, you can import and use this package in your project.

License

MIT

About

A utility to check for missing resolvers in a GraphQL schema. This package helps you ensure that all fields in your schema have appropriate resolvers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published