Star us on GitHub
Star
Menu

Apollo Server Quick Start

Learn how to set up highlight.io on your Apollo Server backend.

1

Configure client-side Highlight. (optional)

If you're using Highlight on the frontend for your application, make sure you've initialized it correctly and followed the fullstack mapping guide.

2

Install the relevant Highlight SDK(s).

Install @highlight-run/node, @highlight-run/apollo with your package manager.

npm install --save @highlight-run/node @highlight-run/apollo
Copy
3

Initialize the Highlight JS SDK.

Initialize the Highlight JS SDK with your project ID.

import { H } from '@highlight-run/node' H.init({ projectID: '<YOUR_PROJECT_ID>', serviceName: '<YOUR_SERVICE_NAME>', environment: 'production', })
Copy
4

Add the Apollo Server integration.

ApolloServerHighlightPlugin is an Apollo Server plugin to capture errors in your graphql handlers.

import { ApolloServer } from '@apollo/server' import { ApolloServerHighlightPlugin } from '@highlight-run/apollo' // on legacy Apollo V3, use the following import // import { ApolloServerV3HighlightPlugin as ApolloServerHighlightPlugin } from '@highlight-run/apollo' // ... const server = new ApolloServer({ typeDefs, resolvers, plugins: [ ApolloServerHighlightPlugin({ projectID: '<YOUR_PROJECT_ID>', serviceName: 'my-apollo-app', serviceVersion: 'git-sha', environment: 'production' }), ], })
Copy
5

Optionally, report manual errors in your app.

If you need to report exceptions outside of a handler, use the Highlight SDK.

const parsed = H.parseHeaders(request.headers) H.consumeError(error, parsed?.secureSessionId, parsed?.requestId)
Copy
6

Verify that your SDK is reporting errors.

You'll want to throw an exception in one of your apollo handlers. Access the API handler and make sure the error shows up in Highlight.

const server = new ApolloServer({ typeDefs, resolvers: { Query: { books: () => { throw new Error('a sample error!'); }, }, }, });
Copy
7

Verify your backend logs are being recorded.

Visit the highlight logs portal and check that backend logs are coming in.

8

Verify your backend traces are being recorded.

Visit the highlight traces portal and check that backend traces are coming in.