Skip to content

Commit 7acfd71

Browse files
authored
Merge pull request #113 from tlivings/patch-602
Removed the debug module dependency.
2 parents b6b88f3 + 30bba5c commit 7acfd71

File tree

6 files changed

+11
-41
lines changed

6 files changed

+11
-41
lines changed

.cursor/rules/examples.mdc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,13 @@ const resolvers = {
218218

219219
### Example Scripts
220220
- Add npm scripts for running examples
221-
- Use DEBUG environment variable
222221
- Include clear naming
223222

224223
```json
225224
{
226225
"scripts": {
227-
"start-composition": "DEBUG=graphql-component ts-node examples/composition/server/index.ts",
228-
"start-federation": "DEBUG=graphql-component ts-node examples/federation/run-federation-example.ts"
226+
"start-composition": "ts-node examples/composition/server/index.ts",
227+
"start-federation": "ts-node examples/federation/run-federation-example.ts"
229228
}
230229
}
231230
```

.cursor/rules/overview.mdc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ The library supports both traditional schema stitching for monolithic applicatio
4848
- **tape** - Testing framework for unit tests
4949
- **eslint** - Code linting with TypeScript support
5050
- **prettier** - Code formatting
51-
- **debug** - Runtime debugging utilities
5251
- **ts-node** - TypeScript execution for examples and development
5352

5453
## Example Dependencies

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [TESTS] Added test to verify dataSources availability in middleware
55
- [PERFORMANCE] Enhanced context building with parallel import processing, and middleware optimization
66
- [TESTS] Added comprehensive performance regression tests to validate optimization correctness and prevent breaking changes
7+
- [SECURITY] Removed `debug`
78

89
### v6.0.1
910

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,6 @@ Both examples are accessible at `http://localhost:4000/graphql` when running.
265265

266266
You can find the complete example code in the [`examples/`](./examples/) directory.
267267

268-
## Debugging
269-
270-
Enable debug logging with:
271-
```bash
272-
DEBUG=graphql-component:* node your-app.js
273-
```
274-
275268
## Repository Structure
276269

277270
- `src/` - Core library code

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"build": "tsc",
1515
"prepublish": "npm run build",
1616
"test": "tape -r ts-node/register \"test/**/*.ts\"",
17-
"start-composition": "DEBUG=graphql-component ts-node examples/composition/server/index.ts",
18-
"start-federation": "DEBUG=graphql-component ts-node examples/federation/run-federation-example.ts",
17+
"start-composition": "ts-node examples/composition/server/index.ts",
18+
"start-federation": "ts-node examples/federation/run-federation-example.ts",
1919
"lint": "npx eslint src/index.ts",
2020
"cover": "nyc npm test",
2121
"update-deps": "ncu -u && npm install",
@@ -33,8 +33,7 @@
3333
"@graphql-tools/mock": "^9.0.6",
3434
"@graphql-tools/schema": "^10.0.8",
3535
"@graphql-tools/stitch": "^9.4.0",
36-
"@graphql-tools/utils": "^10.5.6",
37-
"debug": "^4.3.7"
36+
"@graphql-tools/utils": "^10.5.6"
3837
},
3938
"peerDependencies": {
4039
"graphql": "^16.0.0"

src/index.ts

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import debugConfig from 'debug';
21
import { buildFederatedSchema } from '@apollo/federation';
32
import { GraphQLResolveInfo, GraphQLScalarType, GraphQLSchema } from 'graphql';
43

@@ -16,8 +15,6 @@ import { stitchSchemas } from '@graphql-tools/stitch';
1615
import { addMocksToSchema, IMocks } from '@graphql-tools/mock';
1716
import { SubschemaConfig } from '@graphql-tools/delegate';
1817

19-
const debug = debugConfig('graphql-component');
20-
2118
export type ResolverFunction = (_: any, args: any, ctx: any, info: GraphQLResolveInfo) => any;
2219

2320
export 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
*/
451440
const 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

Comments
 (0)