Skip to content

Commit

Permalink
Clear up error message in defense mechanism against existing tracing.
Browse files Browse the repository at this point in the history
This package should never have already set it itself prior to this point,
but the circumstance exists that something (anything) else could have
already used the `extensions` sink to attach a value.

This guards against that.
  • Loading branch information
abernix committed Apr 16, 2020
1 parent 8ec39c9 commit 5c9ceaa
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/apollo-tracing/src/index.ts
Expand Up @@ -5,6 +5,8 @@ import {
} from 'graphql';
import { ApolloServerPlugin } from "apollo-server-plugin-base";

const { PACKAGE_NAME } = require("../../package.json").name;

export interface TracingFormat {
version: 1;
startTime: string;
Expand Down Expand Up @@ -88,8 +90,11 @@ export const plugin = (_futureOptions = {}) => (): ApolloServerPlugin => ({
const extensions =
response.extensions || (response.extensions = Object.create(null));

// Be defensive and make sure nothing else (other plugin, etc.) has
// already used the `tracing` property on `extensions`.
if (typeof extensions.tracing !== 'undefined') {
throw new Error("The tracing information already existed.");
throw new Error(PACKAGE_NAME + ": Could not add `tracing` to " +
"`extensions` since `tracing` was unexpectedly already present.");
}

// Set the extensions.
Expand Down

0 comments on commit 5c9ceaa

Please sign in to comment.