Socket
Socket
Sign inDemoInstall

@esco/graphql-add-middleware

Package Overview
Dependencies
2
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @esco/graphql-add-middleware

GraphQL middleware for schema resolvers


Version published
Weekly downloads
1
Maintainers
1
Install size
35.6 kB
Created
Weekly downloads
 

Changelog

Source

0.1.5

  • Make graphql package as peer dependency

Readme

Source

graphql-add-middleware Build Status

Easily add middleware to GraphQL schema resolvers

Installation

$ npm install --save graphql-add-middleware

Features

  • Add middleware to all schema resolvers
  • Add middleware to resolvers of given type
  • Add middleware to resolver of given field of given type

Usage

type User {
  name: String!
}

type Post {
  title: String!
  author: User
}

type Query {
  posts: [Post!]!
  user: User
}

type Mutation {
  createUser: User!
}

schema {
  query: Query
  mutation: Mutation
}
import { addMiddleware } from 'graphql-add-middleware';

// add middleware to ALL resolvers (also to nested resolver if they are defined in schema like Post.author)
addMiddleware(schema, async function (root, args, context, info, next) {
  // you can modify root, args, context, info
  const result = await next();
  // you can modify result
  return result; // you must return value
});

// add middleware only to given type
addMiddleware(schema, 'Query', async function (root, args, context, info, next) { ... }); // will add middleware to Query.posts and Query.user
addMiddleware(schema, 'Mutation', async function (root, args, context, info, next) { ... }); // will add middleware to Mutation.createUser
addMiddleware(schema, 'Post', async function (root, args, context, info, next) { ... }); // will add middleware to Post.author (Post.*)

// add middleware only to given type/field
addMiddleware(schema, 'Query.posts', async function (root, args, context, info, next) { ... }); // will add middleware to Query.posts
addMiddleware(schema, 'Post.author', async function (root, args, context, info, next) { ... }); // will add middleware to Post.author

Keywords

FAQs

Last updated on 15 Jun 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc