1
- import { ExecutionArgs , GraphQLError , Kind , OperationDefinitionNode , print } from 'graphql' ;
1
+ import { GraphQLError , Kind , OperationDefinitionNode , print } from 'graphql' ;
2
2
import {
3
3
getDocumentString ,
4
4
handleStreamOrSingleExecutionResult ,
5
5
isOriginalGraphQLError ,
6
6
OnExecuteDoneHookResultOnNextHook ,
7
+ TypedExecutionArgs ,
7
8
type Plugin ,
8
9
} from '@envelop/core' ;
9
10
import * as Sentry from '@sentry/node' ;
10
11
import type { Span , TraceparentData } from '@sentry/types' ;
11
12
12
- export type SentryPluginOptions = {
13
+ export type SentryPluginOptions < PluginContext extends Record < string , any > > = {
13
14
/**
14
15
* Starts a new transaction for every GraphQL Operation.
15
16
* When disabled, an already existing Transaction will be used.
@@ -45,34 +46,34 @@ export type SentryPluginOptions = {
45
46
/**
46
47
* Adds custom tags to every Transaction.
47
48
*/
48
- appendTags ?: ( args : ExecutionArgs ) => Record < string , unknown > ;
49
+ appendTags ?: ( args : TypedExecutionArgs < PluginContext > ) => Record < string , unknown > ;
49
50
/**
50
51
* Callback to set context information onto the scope.
51
52
*/
52
- configureScope ?: ( args : ExecutionArgs , scope : Sentry . Scope ) => void ;
53
+ configureScope ?: ( args : TypedExecutionArgs < PluginContext > , scope : Sentry . Scope ) => void ;
53
54
/**
54
55
* Produces a name of Transaction (only when "renameTransaction" or "startTransaction" are enabled) and description of created Span.
55
56
*
56
57
* @default operation's name or "Anonymous Operation" when missing)
57
58
*/
58
- transactionName ?: ( args : ExecutionArgs ) => string ;
59
+ transactionName ?: ( args : TypedExecutionArgs < PluginContext > ) => string ;
59
60
/**
60
61
* Produces tracing data for Transaction
61
62
*
62
63
* @default is empty
63
64
*/
64
- traceparentData ?: ( args : ExecutionArgs ) => TraceparentData | undefined ;
65
+ traceparentData ?: ( args : TypedExecutionArgs < PluginContext > ) => TraceparentData | undefined ;
65
66
/**
66
67
* Produces a "op" (operation) of created Span.
67
68
*
68
69
* @default execute
69
70
*/
70
- operationName ?: ( args : ExecutionArgs ) => string ;
71
+ operationName ?: ( args : TypedExecutionArgs < PluginContext > ) => string ;
71
72
/**
72
73
* Indicates whether or not to skip the entire Sentry flow for given GraphQL operation.
73
74
* By default, no operations are skipped.
74
75
*/
75
- skip ?: ( args : ExecutionArgs ) => boolean ;
76
+ skip ?: ( args : TypedExecutionArgs < PluginContext > ) => boolean ;
76
77
/**
77
78
* Indicates whether or not to skip Sentry exception reporting for a given error.
78
79
* By default, this plugin skips all `GraphQLError` errors and does not report it to Sentry.
@@ -82,10 +83,12 @@ export type SentryPluginOptions = {
82
83
83
84
export const defaultSkipError = isOriginalGraphQLError ;
84
85
85
- export const useSentry = ( options : SentryPluginOptions = { } ) : Plugin => {
86
- function pick < K extends keyof SentryPluginOptions > (
86
+ export const useSentry = < PluginContext extends Record < string , any > = { } > (
87
+ options : SentryPluginOptions < PluginContext > = { } ,
88
+ ) : Plugin < PluginContext > => {
89
+ function pick < K extends keyof SentryPluginOptions < PluginContext > > (
87
90
key : K ,
88
- defaultValue : NonNullable < SentryPluginOptions [ K ] > ,
91
+ defaultValue : NonNullable < SentryPluginOptions < PluginContext > [ K ] > ,
89
92
) {
90
93
return options [ key ] ?? defaultValue ;
91
94
}
0 commit comments