Apollo Server Metrics Plugin

The Stellate GraphQL Apollo Server Metrics Plugin is a powerful tool designed to integrate Stellate with your existing GraphQL Apollo Server APIs with just a few lines of code.

Simple and easy to integrate, our Apollo Server Metrics Plugin enables metrics logging, allowing for a seamless connection with the Stellate service for performance insights and analytics.

Benefits of the Apollo Server Metrics Plugin

The primary benefit of using our Apollo Server Metrics Plugin is to be able to collect metrics without setting up the Stellate Edge proxy. For more information about the Stellate Edge proxy metrics, read Stellate Edge Proxy Metrics. In addition, the Apollo Server Metrics Plugin features:

  • Straightforward setup and integration.
  • Ability to log metrics, which are useful for monitoring and analyzing API usage.
  • Automatically synchronize your GraphQL schema with your Stellate service, ensuring that your Apollo Server GraphQL API structure is always up to date.
  • The apollo-server plugin, as do all of the plugins for JavaScript-based servers, takes a fetch function as an argument. This enables using the plugin in any JavaScript environment. If you are running NodeJS you can use the node-fetch package, and in an edge environment (such as Cloudflare Workers) you can pass the global fetch function.

Before You Begin

Before you install and use the Stellate apollo-server plugin, you need to have your environment set up with the Apollo Server. For more information, read the Apollo Server documentation. Additionally, you need to:

  • Set Up a Stellate Service: You must have an active Stellate service set up. Our GraphQL Apollo Server Plugin is designed to work with your Stellate service. It provides performance insights and analytics for Apollo Server-based APIs.

  • Create a Logging Token: To implement this plugin, you need to create a logging token specific to your Stellate service. This token is used to authenticate and log metrics data from your GraphQL API to your Stellate dashboard. You can get your logging token by going to your Stellate Dashboard > Services > Your Service > Config > Token.

Once these prerequisites are met, you can install the GraphQL Apollo Server Metrics Plugin.

Set up the Apollo Server Metrics Plugin

To install and set up the apollo-server plugin, use the following steps:

  1. Before you can make use of this plugin, you must have set up a Stellate service and created a logging token. See the prior Before You Begin section for more information.
  2. Copy and paste the following JavaScript plugin code to your server:
import { createStellateLoggerPlugin } from 'stellate/apollo-server'
import { startStandaloneServer } from '@apollo/server/standalone'
import { ApolloServer } from '@apollo/server'

const stellatePlugin = createStellateLoggerPlugin({
  serviceName: '${serviceName}',
  token: '${loggingToken}',
  // a fetch compliant function, can be from `node-fetch` if you are running in NodeJS,
  // or the global fetch function if running in a v8 environment (e.g. Cloudflare Workers)
  fetch: fetch,
})

const server = new ApolloServer({
  typeDefs,
  resolvers,
  plugins: [stellatePlugin],
})

const { url } = await startStandaloneServer(server, { listen: { port: 4000 } })

  1. Start the server to begin handling requests.
  2. Refresh your dashboard to show the incoming requests and metrics, highlighting the plugin's capability to track Apollo Server GraphQL API usage.

Discover more

JavaScript Server Plugins

Other Language Plugins