1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- /* eslint-disable no-console */
3
1
/* eslint-disable no-debugger */
4
2
import { Hub } from '@sentry/hub' ;
5
3
import { EventProcessor , Integration } from '@sentry/types' ;
@@ -9,11 +7,11 @@ type ApolloResolverGroup = {
9
7
[ key : string ] : ( ) => any ;
10
8
} ;
11
9
12
- type ApolloField = {
10
+ type ApolloModelResolvers = {
13
11
[ key : string ] : ApolloResolverGroup ;
14
12
} ;
15
13
16
- /** Tracing integration for Apollo package */
14
+ /** Tracing integration for Apollo */
17
15
export class Apollo implements Integration {
18
16
/**
19
17
* @inheritDoc
@@ -37,26 +35,28 @@ export class Apollo implements Integration {
37
35
} ;
38
36
} > ( `apollo-server-core` ) ;
39
37
40
- debugger ;
41
38
if ( ! pkg ) {
42
- logger . error ( ` Apollo Integration was unable to require apollo package.` ) ;
39
+ logger . error ( ' Apollo Integration was unable to require apollo-server-core package.' ) ;
43
40
return ;
44
41
}
45
42
43
+ /**
44
+ * Iterate over resolvers of the ApolloServer instance before schemas are constructed.
45
+ */
46
46
fill ( pkg . ApolloServerBase . prototype , 'constructSchema' , function ( orig : ( ) => void ) {
47
- return function ( this : { config : { resolvers : ApolloField [ ] } } ) {
48
- this . config . resolvers = this . config . resolvers . map ( field => {
49
- Object . keys ( field ) . forEach ( resolverGroupName => {
50
- Object . keys ( field [ resolverGroupName ] ) . forEach ( resolverName => {
51
- if ( typeof field [ resolverGroupName ] [ resolverName ] !== 'function' ) {
47
+ return function ( this : { config : { resolvers : ApolloModelResolvers [ ] } } ) {
48
+ this . config . resolvers = this . config . resolvers . map ( model => {
49
+ Object . keys ( model ) . forEach ( resolverGroupName => {
50
+ Object . keys ( model [ resolverGroupName ] ) . forEach ( resolverName => {
51
+ if ( typeof model [ resolverGroupName ] [ resolverName ] !== 'function' ) {
52
52
return ;
53
53
}
54
54
55
- patchResolver ( field , resolverGroupName , resolverName , getCurrentHub ) ;
55
+ wrapResolver ( model , resolverGroupName , resolverName , getCurrentHub ) ;
56
56
} ) ;
57
57
} ) ;
58
58
59
- return field ;
59
+ return model ;
60
60
} ) ;
61
61
62
62
return orig . call ( this ) ;
@@ -66,18 +66,15 @@ export class Apollo implements Integration {
66
66
}
67
67
68
68
/**
69
- *
70
- * @param field
71
- * @param resolverGroupName
72
- * @param resolverName
69
+ * Wrap a single resolver which can be a parent of other resolvers and/or db operations.
73
70
*/
74
- function patchResolver (
75
- field : ApolloField ,
71
+ function wrapResolver (
72
+ model : ApolloModelResolvers ,
76
73
resolverGroupName : string ,
77
74
resolverName : string ,
78
75
getCurrentHub : ( ) => Hub ,
79
76
) : void {
80
- fill ( field [ resolverGroupName ] , resolverName , function ( orig : ( ) => unknown | Promise < unknown > ) {
77
+ fill ( model [ resolverGroupName ] , resolverName , function ( orig : ( ) => unknown | Promise < unknown > ) {
81
78
return function ( this : unknown , ...args : unknown [ ] ) {
82
79
const scope = getCurrentHub ( ) . getScope ( ) ;
83
80
const parentSpan = scope ?. getSpan ( ) ;
0 commit comments