Socket
Socket
Sign inDemoInstall

apollo-server-plugin-base

Package Overview
Dependencies
56
Maintainers
1
Versions
162
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-server-plugin-base

Apollo Server plugin base classes


Version published
Maintainers
1
Weekly downloads
1,177,515
decreased by-9.86%

Weekly downloads

Package description

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

Readme

Source

apollo-server-plugin-base

This package exports TypeScript types for defining your own Apollo Server plugin.

FAQs

Last updated on 02 Mar 2023

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