1- import debugConfig from 'debug' ;
21import { buildFederatedSchema } from '@apollo/federation' ;
32import { GraphQLResolveInfo , GraphQLScalarType , GraphQLSchema } from 'graphql' ;
43
@@ -16,8 +15,6 @@ import { stitchSchemas } from '@graphql-tools/stitch';
1615import { addMocksToSchema , IMocks } from '@graphql-tools/mock' ;
1716import { SubschemaConfig } from '@graphql-tools/delegate' ;
1817
19- const debug = debugConfig ( 'graphql-component' ) ;
20-
2118export type ResolverFunction = ( _ : any , args : any , ctx : any , info : GraphQLResolveInfo ) => any ;
2219
2320export interface IGraphQLComponentConfigObject {
@@ -211,7 +208,6 @@ export default class GraphQLComponent<TContextType extends ComponentContext = Co
211208
212209 // Handle namespace context if present
213210 if ( context ) {
214- debug ( `building ${ context . namespace } context` ) ;
215211
216212 if ( ! ctx [ context . namespace ] ) {
217213 ctx [ context . namespace ] = { } ;
@@ -231,7 +227,6 @@ export default class GraphQLComponent<TContextType extends ComponentContext = Co
231227 get context ( ) : IContextWrapper {
232228 // Cache middleware array to avoid recreation
233229 const contextFn = async ( context : Record < string , unknown > ) : Promise < ComponentContext > => {
234- debug ( `building root context` ) ;
235230
236231 // Inject dataSources early so middleware can access them
237232 const dataSources = this . _dataSourceContextInject ( context ) ;
@@ -255,9 +250,8 @@ export default class GraphQLComponent<TContextType extends ComponentContext = Co
255250
256251 // Apply middleware more efficiently
257252 if ( this . _middleware . length > 0 ) {
258- for ( const { name, fn } of this . _middleware ) {
259- debug ( `applying ${ name } middleware` ) ;
260- processedContext = await fn ( processedContext ) ;
253+ for ( const mw of this . _middleware ) {
254+ processedContext = await mw . fn ( processedContext ) ;
261255 }
262256 }
263257
@@ -272,7 +266,7 @@ export default class GraphQLComponent<TContextType extends ComponentContext = Co
272266 fn = name ;
273267 name = 'unknown' ;
274268 }
275- debug ( `adding ${ name } middleware` ) ;
269+
276270 this . _middleware . push ( { name : name as string , fn : fn ! } ) ;
277271
278272 return contextFn ;
@@ -333,27 +327,22 @@ export default class GraphQLComponent<TContextType extends ComponentContext = Co
333327 }
334328
335329 if ( this . _mocks !== undefined && typeof this . _mocks === 'boolean' && this . _mocks === true ) {
336- debug ( `adding default mocks to the schema for ${ this . name } ` ) ;
337330 // if mocks are a boolean support simply applying default mocks
338331 this . _schema = addMocksToSchema ( { schema : this . _schema , preserveResolvers : true } ) ;
339332 }
340333 else if ( this . _mocks !== undefined && typeof this . _mocks === 'object' ) {
341- debug ( `adding custom mocks to the schema for ${ this . name } ` ) ;
342334 // else if mocks is an object, that means the user provided
343335 // custom mocks, with which we pass them to addMocksToSchema so they are applied
344336 this . _schema = addMocksToSchema ( { schema : this . _schema , mocks : this . _mocks , preserveResolvers : true } ) ;
345337 }
346338
347339 if ( this . _pruneSchema ) {
348- debug ( `pruning the schema for ${ this . name } ` ) ;
349340 this . _schema = pruneSchema ( this . _schema , this . _pruneSchemaOptions ) ;
350341 }
351342
352- debug ( `created schema for ${ this . name } ` ) ;
353-
354343 return this . _schema ;
355- } catch ( error ) {
356- debug ( `Error creating schema for ${ this . name } : ${ error } ` ) ;
344+ }
345+ catch ( error ) {
357346 throw new Error ( `Failed to create schema for component ${ this . name } : ${ error . message } ` ) ;
358347 }
359348 }
@@ -450,7 +439,6 @@ module.exports = GraphQLComponent;
450439 */
451440const createDataSourceContextInjector = ( dataSources : IDataSource [ ] , dataSourceOverrides : IDataSource [ ] ) : DataSourceInjectionFunction => {
452441 const intercept = ( instance : IDataSource , context : any ) => {
453- debug ( `intercepting ${ instance . constructor . name } ` ) ;
454442
455443 return new Proxy ( instance , {
456444 get ( target , key ) {
@@ -502,12 +490,9 @@ const memoize = function (parentType: string, fieldName: string, resolve: Resolv
502490 const path = info && info . path && info . path . key ;
503491 const key = `${ path } _${ JSON . stringify ( args ) } ` ;
504492
505- debug ( `executing ${ parentType } .${ fieldName } ` ) ;
506-
507493 let cached = _cache . get ( context ) ;
508494
509495 if ( cached && cached [ key ] ) {
510- debug ( `return cached result of memoized ${ parentType } .${ fieldName } ` ) ;
511496 return cached [ key ] ;
512497 }
513498
@@ -521,8 +506,6 @@ const memoize = function (parentType: string, fieldName: string, resolve: Resolv
521506
522507 _cache . set ( context , cached ) ;
523508
524- debug ( `cached ${ parentType } .${ fieldName } ` ) ;
525-
526509 return result ;
527510 } ;
528511} ;
@@ -541,7 +524,6 @@ const bindResolvers = function (bindContext: IGraphQLComponent, resolvers: IReso
541524 for ( const [ type , fields ] of Object . entries ( resolvers ) ) {
542525 // dont bind an object that is an instance of a graphql scalar
543526 if ( fields instanceof GraphQLScalarType ) {
544- debug ( `not binding ${ type } 's fields since ${ type } 's fields are an instance of GraphQLScalarType` )
545527 boundResolvers [ type ] = fields ;
546528 continue ;
547529 }
@@ -552,17 +534,14 @@ const bindResolvers = function (bindContext: IGraphQLComponent, resolvers: IReso
552534
553535 for ( const [ field , resolver ] of Object . entries ( fields ) ) {
554536 if ( [ 'Query' , 'Mutation' ] . indexOf ( type ) > - 1 ) {
555- debug ( `memoized ${ type } .${ field } ` ) ;
556537 boundResolvers [ type ] [ field ] = memoize ( type , field , resolver . bind ( bindContext ) ) ;
557538 }
558539 else {
559540 // only bind resolvers that are functions
560541 if ( typeof resolver === 'function' ) {
561- debug ( `binding ${ type } .${ field } ` ) ;
562542 boundResolvers [ type ] [ field ] = resolver . bind ( bindContext ) ;
563543 }
564544 else {
565- debug ( `not binding ${ type } .${ field } since ${ field } is not mapped to a function` ) ;
566545 boundResolvers [ type ] [ field ] = resolver ;
567546 }
568547 }
0 commit comments