Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-server-plugin-base

Package Overview
Dependencies
Maintainers
1
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-server-plugin-base

Apollo Server plugin base classes

  • 3.7.1
  • npm
  • Socket score

Version published
Weekly downloads
531K
decreased by-44.12%
Maintainers
1
Weekly downloads
 
Created

What is apollo-server-plugin-base?

The apollo-server-plugin-base package provides an interface for creating plugins that can hook into, modify, or extend the functionality of Apollo Server. These plugins can be used for logging, performance monitoring, validating requests, and more, allowing developers to customize and optimize their GraphQL server.

What are apollo-server-plugin-base's main functionalities?

Server Lifecycle Hooks

Plugins can define lifecycle hooks such as serverWillStart to perform actions during specific phases of the Apollo Server lifecycle. This example logs a message when the server is starting.

const myPlugin = { 
  serverWillStart(service) { 
    console.log(`GraphQL Server is starting!`); 
  } 
};

Request Lifecycle Hooks

This feature allows plugins to hook into various phases of a GraphQL request's lifecycle, such as when a request starts or before a response is sent. The example logs the request query and the response.

const myPlugin = { 
  requestDidStart(requestContext) { 
    console.log(`Request started! Query:\n${requestContext.request.query}`); 
    return { 
      willSendResponse(requestContext) { 
        console.log(`Response:`, requestContext.response); 
      } 
    }; 
  } 
};

Error Handling

Plugins can also be used for error handling throughout the request lifecycle. This example logs any GraphQL errors that occur during a request.

const errorLoggingPlugin = { 
  requestDidStart(requestContext) { 
    return { 
      didEncounterErrors(requestContext) { 
        console.error(`GraphQL Errors:`, requestContext.errors); 
      } 
    }; 
  } 
};

Other packages similar to apollo-server-plugin-base

FAQs

Package last updated on 03 Nov 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc