Giter Club home page Giter Club logo

graphql-missing-resolvers's Introduction

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

graphql-missing-resolvers's People

Contributors

helgastogova avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.