1
1
import { createRequire } from 'module' ;
2
- import { cwd , env } from 'process' ;
2
+ import { cwd } from 'process' ;
3
3
import { isSchema , Kind } from 'graphql' ;
4
4
import {
5
5
asArray ,
6
+ debugTimerEnd ,
7
+ debugTimerStart ,
6
8
getDocumentNodeFromSchema ,
7
9
isDocumentString ,
8
10
parseGraphQLSDL ,
@@ -28,9 +30,7 @@ export async function collectSources<TOptions>({
28
30
} ;
29
31
options : LoadTypedefsOptions < Partial < TOptions > > ;
30
32
} ) : Promise < Source [ ] > {
31
- if ( env [ 'DEBUG' ] != null ) {
32
- console . time ( '@graphql-tools/load: collectSources' ) ;
33
- }
33
+ debugTimerStart ( '@graphql-tools/load: collectSources' ) ;
34
34
const sources : Source [ ] = [ ] ;
35
35
const queue = useQueue < void > ( { concurrency : CONCURRENCY_LIMIT } ) ;
36
36
@@ -42,9 +42,7 @@ export async function collectSources<TOptions>({
42
42
for ( const pointer in pointerOptionMap ) {
43
43
const pointerOptions = pointerOptionMap [ pointer ] ;
44
44
45
- if ( env [ 'DEBUG' ] != null ) {
46
- console . time ( `@graphql-tools/load: collectSources ${ pointer } ` ) ;
47
- }
45
+ debugTimerStart ( `@graphql-tools/load: collectSources ${ pointer } ` ) ;
48
46
collect ( {
49
47
pointer,
50
48
pointerOptions,
@@ -53,18 +51,12 @@ export async function collectSources<TOptions>({
53
51
addSource,
54
52
queue : queue . add as AddToQueue < void > ,
55
53
} ) ;
56
- if ( env [ 'DEBUG' ] != null ) {
57
- console . timeEnd ( `@graphql-tools/load: collectSources ${ pointer } ` ) ;
58
- }
54
+ debugTimerEnd ( `@graphql-tools/load: collectSources ${ pointer } ` ) ;
59
55
}
60
56
61
- if ( env [ 'DEBUG' ] != null ) {
62
- console . time ( '@graphql-tools/load: collectSources queue' ) ;
63
- }
57
+ debugTimerStart ( '@graphql-tools/load: collectSources queue' ) ;
64
58
await queue . runAll ( ) ;
65
- if ( env [ 'DEBUG' ] != null ) {
66
- console . timeEnd ( '@graphql-tools/load: collectSources queue' ) ;
67
- }
59
+ debugTimerEnd ( '@graphql-tools/load: collectSources queue' ) ;
68
60
return sources ;
69
61
}
70
62
@@ -85,16 +77,12 @@ export function collectSourcesSync<TOptions>({
85
77
stack : [ collectDocumentString , collectCustomLoaderSync , collectFallbackSync ] ,
86
78
} ) ;
87
79
88
- if ( env [ 'DEBUG' ] != null ) {
89
- console . time ( '@graphql-tools/load: collectSourcesSync' ) ;
90
- }
80
+ debugTimerStart ( '@graphql-tools/load: collectSourcesSync' ) ;
91
81
92
82
for ( const pointer in pointerOptionMap ) {
93
83
const pointerOptions = pointerOptionMap [ pointer ] ;
94
84
95
- if ( env [ 'DEBUG' ] != null ) {
96
- console . time ( `@graphql-tools/load: collectSourcesSync ${ pointer } ` ) ;
97
- }
85
+ debugTimerStart ( `@graphql-tools/load: collectSourcesSync ${ pointer } ` ) ;
98
86
collect ( {
99
87
pointer,
100
88
pointerOptions,
@@ -103,19 +91,13 @@ export function collectSourcesSync<TOptions>({
103
91
addSource,
104
92
queue : queue . add ,
105
93
} ) ;
106
- if ( env [ 'DEBUG' ] != null ) {
107
- console . timeEnd ( `@graphql-tools/load: collectSourcesSync ${ pointer } ` ) ;
108
- }
94
+ debugTimerEnd ( `@graphql-tools/load: collectSourcesSync ${ pointer } ` ) ;
109
95
}
110
96
111
- if ( env [ 'DEBUG' ] != null ) {
112
- console . time ( '@graphql-tools/load: collectSourcesSync queue' ) ;
113
- }
97
+ debugTimerStart ( '@graphql-tools/load: collectSourcesSync queue' ) ;
114
98
queue . runAll ( ) ;
99
+ debugTimerEnd ( '@graphql-tools/load: collectSourcesSync queue' ) ;
115
100
116
- if ( env [ 'DEBUG' ] != null ) {
117
- console . timeEnd ( '@graphql-tools/load: collectSourcesSync queue' ) ;
118
- }
119
101
return sources ;
120
102
}
121
103
@@ -156,9 +138,7 @@ function addResultOfCustomLoader({
156
138
result : any ;
157
139
addSource : AddSource ;
158
140
} ) {
159
- if ( env [ 'DEBUG' ] != null ) {
160
- console . time ( `@graphql-tools/load: addResultOfCustomLoader ${ pointer } ` ) ;
161
- }
141
+ debugTimerStart ( `@graphql-tools/load: addResultOfCustomLoader ${ pointer } ` ) ;
162
142
if ( isSchema ( result ) ) {
163
143
addSource ( {
164
144
source : {
@@ -186,18 +166,14 @@ function addResultOfCustomLoader({
186
166
pointer,
187
167
} ) ;
188
168
}
189
- if ( env [ 'DEBUG' ] != null ) {
190
- console . timeEnd ( `@graphql-tools/load: addResultOfCustomLoader ${ pointer } ` ) ;
191
- }
169
+ debugTimerEnd ( `@graphql-tools/load: addResultOfCustomLoader ${ pointer } ` ) ;
192
170
}
193
171
194
172
function collectDocumentString < T > (
195
173
{ pointer, pointerOptions, options, addSource, queue } : CollectOptions < T > ,
196
174
next : StackNext ,
197
175
) {
198
- if ( env [ 'DEBUG' ] != null ) {
199
- console . time ( `@graphql-tools/load: collectDocumentString ${ pointer } ` ) ;
200
- }
176
+ debugTimerStart ( `@graphql-tools/load: collectDocumentString ${ pointer } ` ) ;
201
177
if ( isDocumentString ( pointer ) ) {
202
178
return queue ( ( ) => {
203
179
const source = parseGraphQLSDL ( `${ stringToHash ( pointer ) } .graphql` , pointer , {
@@ -211,9 +187,7 @@ function collectDocumentString<T>(
211
187
} ) ;
212
188
} ) ;
213
189
}
214
- if ( env [ 'DEBUG' ] != null ) {
215
- console . timeEnd ( `@graphql-tools/load: collectDocumentString ${ pointer } ` ) ;
216
- }
190
+ debugTimerEnd ( `@graphql-tools/load: collectDocumentString ${ pointer } ` ) ;
217
191
218
192
next ( ) ;
219
193
}
@@ -224,18 +198,14 @@ function collectCustomLoader<T>(
224
198
) {
225
199
if ( pointerOptions . loader ) {
226
200
return queue ( async ( ) => {
227
- if ( env [ 'DEBUG' ] != null ) {
228
- console . time ( `@graphql-tools/load: collectCustomLoader ${ pointer } ` ) ;
229
- }
201
+ debugTimerStart ( `@graphql-tools/load: collectCustomLoader ${ pointer } ` ) ;
230
202
await Promise . all ( asArray ( pointerOptions . require ) . map ( m => import ( m ) ) ) ;
231
203
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
232
204
// @ts -ignore TODO options.cwd is possibly undefined, but it seems like no test covers this path
233
205
const loader = await useCustomLoader ( pointerOptions . loader , options . cwd ) ;
234
206
const result = await loader ( pointer , { ...options , ...pointerOptions } , pointerOptionMap ) ;
235
207
236
- if ( env [ 'DEBUG' ] != null ) {
237
- console . timeEnd ( `@graphql-tools/load: collectCustomLoader ${ pointer } ` ) ;
238
- }
208
+ debugTimerEnd ( `@graphql-tools/load: collectCustomLoader ${ pointer } ` ) ;
239
209
if ( ! result ) {
240
210
return ;
241
211
}
@@ -253,9 +223,7 @@ function collectCustomLoaderSync<T>(
253
223
) {
254
224
if ( pointerOptions . loader ) {
255
225
return queue ( ( ) => {
256
- if ( env [ 'DEBUG' ] != null ) {
257
- console . time ( `@graphql-tools/load: collectCustomLoaderSync ${ pointer } ` ) ;
258
- }
226
+ debugTimerStart ( `@graphql-tools/load: collectCustomLoaderSync ${ pointer } ` ) ;
259
227
const cwdRequire = createRequire ( options . cwd || cwd ( ) ) ;
260
228
for ( const m of asArray ( pointerOptions . require ) ) {
261
229
cwdRequire ( m ) ;
@@ -265,9 +233,7 @@ function collectCustomLoaderSync<T>(
265
233
const loader = useCustomLoaderSync ( pointerOptions . loader , options . cwd ) ;
266
234
const result = loader ( pointer , { ...options , ...pointerOptions } , pointerOptionMap ) ;
267
235
268
- if ( env [ 'DEBUG' ] != null ) {
269
- console . timeEnd ( `@graphql-tools/load: collectCustomLoaderSync ${ pointer } ` ) ;
270
- }
236
+ debugTimerEnd ( `@graphql-tools/load: collectCustomLoaderSync ${ pointer } ` ) ;
271
237
if ( result ) {
272
238
addResultOfCustomLoader ( { pointer, result, addSource } ) ;
273
239
}
@@ -285,9 +251,7 @@ function collectFallback<T>({
285
251
addSource,
286
252
} : CollectOptions < T > ) {
287
253
return queue ( async ( ) => {
288
- if ( env [ 'DEBUG' ] != null ) {
289
- console . time ( `@graphql-tools/load: collectFallback ${ pointer } ` ) ;
290
- }
254
+ debugTimerStart ( `@graphql-tools/load: collectFallback ${ pointer } ` ) ;
291
255
const sources = await loadFile ( pointer , {
292
256
...options ,
293
257
...pointerOptions ,
@@ -298,9 +262,7 @@ function collectFallback<T>({
298
262
addSource ( { source, pointer } ) ;
299
263
}
300
264
}
301
- if ( env [ 'DEBUG' ] != null ) {
302
- console . timeEnd ( `@graphql-tools/load: collectFallback ${ pointer } ` ) ;
303
- }
265
+ debugTimerEnd ( `@graphql-tools/load: collectFallback ${ pointer } ` ) ;
304
266
} ) ;
305
267
}
306
268
@@ -312,9 +274,7 @@ function collectFallbackSync<T>({
312
274
addSource,
313
275
} : CollectOptions < T > ) {
314
276
return queue ( ( ) => {
315
- if ( env [ 'DEBUG' ] != null ) {
316
- console . time ( `@graphql-tools/load: collectFallbackSync ${ pointer } ` ) ;
317
- }
277
+ debugTimerStart ( `@graphql-tools/load: collectFallbackSync ${ pointer } ` ) ;
318
278
const sources = loadFileSync ( pointer , {
319
279
...options ,
320
280
...pointerOptions ,
@@ -325,8 +285,6 @@ function collectFallbackSync<T>({
325
285
addSource ( { source, pointer } ) ;
326
286
}
327
287
}
328
- if ( env [ 'DEBUG' ] != null ) {
329
- console . timeEnd ( `@graphql-tools/load: collectFallbackSync ${ pointer } ` ) ;
330
- }
288
+ debugTimerEnd ( `@graphql-tools/load: collectFallbackSync ${ pointer } ` ) ;
331
289
} ) ;
332
290
}
0 commit comments