diff --git a/.cursor/rules/examples.mdc b/.cursor/rules/examples.mdc index 4caecb1..931de5d 100644 --- a/.cursor/rules/examples.mdc +++ b/.cursor/rules/examples.mdc @@ -218,14 +218,13 @@ const resolvers = { ### Example Scripts - Add npm scripts for running examples -- Use DEBUG environment variable - Include clear naming ```json { "scripts": { - "start-composition": "DEBUG=graphql-component ts-node examples/composition/server/index.ts", - "start-federation": "DEBUG=graphql-component ts-node examples/federation/run-federation-example.ts" + "start-composition": "ts-node examples/composition/server/index.ts", + "start-federation": "ts-node examples/federation/run-federation-example.ts" } } ``` diff --git a/.cursor/rules/overview.mdc b/.cursor/rules/overview.mdc index 3147638..f64b435 100644 --- a/.cursor/rules/overview.mdc +++ b/.cursor/rules/overview.mdc @@ -48,7 +48,6 @@ The library supports both traditional schema stitching for monolithic applicatio - **tape** - Testing framework for unit tests - **eslint** - Code linting with TypeScript support - **prettier** - Code formatting -- **debug** - Runtime debugging utilities - **ts-node** - TypeScript execution for examples and development ## Example Dependencies diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eb6169..0182085 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [TESTS] Added test to verify dataSources availability in middleware - [PERFORMANCE] Enhanced context building with parallel import processing, and middleware optimization - [TESTS] Added comprehensive performance regression tests to validate optimization correctness and prevent breaking changes +- [SECURITY] Removed `debug` ### v6.0.1 diff --git a/README.md b/README.md index 3d66a59..280cf9b 100644 --- a/README.md +++ b/README.md @@ -265,13 +265,6 @@ Both examples are accessible at `http://localhost:4000/graphql` when running. You can find the complete example code in the [`examples/`](./examples/) directory. -## Debugging - -Enable debug logging with: -```bash -DEBUG=graphql-component:* node your-app.js -``` - ## Repository Structure - `src/` - Core library code diff --git a/package.json b/package.json index a98102b..979f54d 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "build": "tsc", "prepublish": "npm run build", "test": "tape -r ts-node/register \"test/**/*.ts\"", - "start-composition": "DEBUG=graphql-component ts-node examples/composition/server/index.ts", - "start-federation": "DEBUG=graphql-component ts-node examples/federation/run-federation-example.ts", + "start-composition": "ts-node examples/composition/server/index.ts", + "start-federation": "ts-node examples/federation/run-federation-example.ts", "lint": "npx eslint src/index.ts", "cover": "nyc npm test", "update-deps": "ncu -u && npm install", @@ -33,8 +33,7 @@ "@graphql-tools/mock": "^9.0.6", "@graphql-tools/schema": "^10.0.8", "@graphql-tools/stitch": "^9.4.0", - "@graphql-tools/utils": "^10.5.6", - "debug": "^4.3.7" + "@graphql-tools/utils": "^10.5.6" }, "peerDependencies": { "graphql": "^16.0.0" diff --git a/src/index.ts b/src/index.ts index 3e86874..b880dce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -import debugConfig from 'debug'; import { buildFederatedSchema } from '@apollo/federation'; import { GraphQLResolveInfo, GraphQLScalarType, GraphQLSchema } from 'graphql'; @@ -16,8 +15,6 @@ import { stitchSchemas } from '@graphql-tools/stitch'; import { addMocksToSchema, IMocks } from '@graphql-tools/mock'; import { SubschemaConfig } from '@graphql-tools/delegate'; -const debug = debugConfig('graphql-component'); - export type ResolverFunction = (_: any, args: any, ctx: any, info: GraphQLResolveInfo) => any; export interface IGraphQLComponentConfigObject { @@ -211,7 +208,6 @@ export default class GraphQLComponent): Promise => { - debug(`building root context`); // Inject dataSources early so middleware can access them const dataSources = this._dataSourceContextInject(context); @@ -255,9 +250,8 @@ export default class GraphQLComponent 0) { - for (const { name, fn } of this._middleware) { - debug(`applying ${name} middleware`); - processedContext = await fn(processedContext); + for (const mw of this._middleware) { + processedContext = await mw.fn(processedContext); } } @@ -272,7 +266,7 @@ export default class GraphQLComponent { const intercept = (instance: IDataSource, context: any) => { - debug(`intercepting ${instance.constructor.name}`); return new Proxy(instance, { get(target, key) { @@ -502,12 +490,9 @@ const memoize = function (parentType: string, fieldName: string, resolve: Resolv const path = info && info.path && info.path.key; const key = `${path}_${JSON.stringify(args)}`; - debug(`executing ${parentType}.${fieldName}`); - let cached = _cache.get(context); if (cached && cached[key]) { - debug(`return cached result of memoized ${parentType}.${fieldName}`); return cached[key]; } @@ -521,8 +506,6 @@ const memoize = function (parentType: string, fieldName: string, resolve: Resolv _cache.set(context, cached); - debug(`cached ${parentType}.${fieldName}`); - return result; }; }; @@ -541,7 +524,6 @@ const bindResolvers = function (bindContext: IGraphQLComponent, resolvers: IReso for (const [type, fields] of Object.entries(resolvers)) { // dont bind an object that is an instance of a graphql scalar if (fields instanceof GraphQLScalarType) { - debug(`not binding ${type}'s fields since ${type}'s fields are an instance of GraphQLScalarType`) boundResolvers[type] = fields; continue; } @@ -552,17 +534,14 @@ const bindResolvers = function (bindContext: IGraphQLComponent, resolvers: IReso for (const [field, resolver] of Object.entries(fields)) { if (['Query', 'Mutation'].indexOf(type) > -1) { - debug(`memoized ${type}.${field}`); boundResolvers[type][field] = memoize(type, field, resolver.bind(bindContext)); } else { // only bind resolvers that are functions if (typeof resolver === 'function') { - debug(`binding ${type}.${field}`); boundResolvers[type][field] = resolver.bind(bindContext); } else { - debug(`not binding ${type}.${field} since ${field} is not mapped to a function`); boundResolvers[type][field] = resolver; } }