Skip to content

Commit

Permalink
fix(instrumentation-graphql): stop using types from graphql library…
Browse files Browse the repository at this point in the history
… in public api (#1268)

* fix(instrumentation-graphql): stop using types from graphql lib in instrumentation

This ensures that whenever someone imports the graphql instrumentation
lib while not having the `graphql` package installed, their typescript
build still passes.

The scenario can happen when using the auto instrumentation packages
which import a ton of intrumentation libs but only load them if the
instrumented package is present.

Signed-off-by: Boris Bera <bbera@coveo.com>

* fix(instrumentation-graphql): replace ExecutionResult with any in GraphQLInstrumentationExecutionResponseHook

This ensures that we don't import types from the `graphql` library in
our type declarations.

Since the type annotation is now gone, I have added documentation
linking to all the implementations of the `ExecutionResult` in the
supported `graphql` versions.

* fix(instrumentation-graphql): remove graphql as a peerDependency

Now that the types are no longer re-exported the dependency on `graphql`
doesn't make much sense.

This change also has the benefit of letting users who use auto
intrumentation and that have strict peerDependency requirements (if
they're using pnpm for example) to use this intrumentation without
needing to install `graphql`.

Signed-off-by: Boris Bera <bbera@coveo.com>
  • Loading branch information
dotboris authored Nov 8, 2022
1 parent aff84bb commit f8cabf3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
"access": "public"
},
"peerDependencies": {
"@opentelemetry/api": "^1.0.0",
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
"@opentelemetry/api": "^1.0.0"
},
"devDependencies": {
"@opentelemetry/api": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class GraphQLInstrumentation extends InstrumentationBase {
}

protected init() {
const module = new InstrumentationNodeModuleDefinition<typeof graphqlTypes>(
const module = new InstrumentationNodeModuleDefinition<any>(
'graphql',
supportedVersions
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
*/

import { InstrumentationConfig } from '@opentelemetry/instrumentation';
import type * as graphqlTypes from 'graphql';
import type * as api from '@opentelemetry/api';

export interface GraphQLInstrumentationExecutionResponseHook {
(span: api.Span, data: graphqlTypes.ExecutionResult): void;
(span: api.Span, data: any): void;
}

export interface GraphQLInstrumentationConfig extends InstrumentationConfig {
Expand Down Expand Up @@ -65,6 +64,11 @@ export interface GraphQLInstrumentationConfig extends InstrumentationConfig {
* Hook that allows adding custom span attributes based on the data
* returned from "execute" GraphQL action.
*
* @param data - A GraphQL `ExecutionResult` object. For the exact type definitions, see the following:
* - {@linkcode https://github.com/graphql/graphql-js/blob/v14.7.0/src/execution/execute.js#L115 graphql@14}
* - {@linkcode https://github.com/graphql/graphql-js/blob/15.x.x/src/execution/execute.d.ts#L31 graphql@15}
* - {@linkcode https://github.com/graphql/graphql-js/blob/16.x.x/src/execution/execute.ts#L127 graphql@16}
*
* @default undefined
*/
responseHook?: GraphQLInstrumentationExecutionResponseHook;
Expand Down

0 comments on commit f8cabf3

Please sign in to comment.