Skip to content

Commit af56e78

Browse files
committed
refactor: remove duplicative re-exports and options from graphql packages
- Delete graphql/server/src/options.ts (type re-exports, duplicate defaults, unused type guards, legacy detection) - Remove export * from '@pgpmjs/types' in graphql/types/src/index.ts - Remove all re-exports from graphql/env/src/index.ts (was re-exporting @pgpmjs/env and @constructive-io/graphql-types) - Remove duplicate ApiOptions type from graphql/server/src/types.ts - Replace normalizeServerOptions with direct getEnvOptions call in server.ts - Update middleware imports: getNodeEnv from @pgpmjs/env, ApiOptions -> ConstructiveOptions - Add @pgpmjs/env as direct dependency of graphql/server
1 parent eebb09e commit af56e78

13 files changed

Lines changed: 2626 additions & 7878 deletions

File tree

graphql/env/src/index.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
// Re-export core env utilities from @pgpmjs/env
2-
export {
3-
loadConfigSync,
4-
loadConfigFileSync,
5-
loadConfigSyncFromDir,
6-
resolvePgpmPath,
7-
getConnEnvOptions,
8-
getDeploymentEnvOptions,
9-
getNodeEnv
10-
} from '@pgpmjs/env';
11-
121
// Export Constructive-specific env functions
132
export { getEnvOptions, getConstructiveEnvOptions } from './merge';
143
export { getGraphQLEnvVars } from './env';
15-
16-
// Re-export types for convenience
17-
export type { ConstructiveOptions, ConstructiveGraphQLOptions } from '@constructive-io/graphql-types';
18-
export { constructiveDefaults, constructiveGraphqlDefaults } from '@constructive-io/graphql-types';

graphql/server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@constructive-io/url-domains": "workspace:^",
4747
"@graphile-contrib/pg-many-to-many": "2.0.0-rc.1",
4848
"@graphile/simplify-inflection": "8.0.0-rc.3",
49+
"@pgpmjs/env": "workspace:^",
4950
"@pgpmjs/logger": "workspace:^",
5051
"@pgpmjs/server-utils": "workspace:^",
5152
"@pgpmjs/types": "workspace:^",

graphql/server/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
export * from './server';
22

3-
// Export options module - types, defaults, type guards, and utility functions
4-
export * from './options';
5-
63
// Export middleware for use in testing packages
74
export { createApiMiddleware, getSubdomain, getApiConfig } from './middleware/api';
85
export { createAuthenticateMiddleware } from './middleware/auth';

graphql/server/src/middleware/api.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { getNodeEnv } from '@constructive-io/graphql-env';
1+
import { getNodeEnv } from '@pgpmjs/env';
22
import { Logger } from '@pgpmjs/logger';
33
import { svcCache } from '@pgpmjs/server-utils';
4+
import type { ConstructiveOptions } from '@constructive-io/graphql-types';
45
import { parseUrl } from '@constructive-io/url-domains';
56
import { NextFunction, Request, Response } from 'express';
67
import { Pool } from 'pg';
78
import { getPgPool } from 'pg-cache';
89

910
import errorPage50x from '../errors/50x';
1011
import errorPage404Message from '../errors/404-message';
11-
import { ApiConfigResult, ApiError, ApiOptions, ApiStructure, RlsModule } from '../types';
12+
import { ApiConfigResult, ApiError, ApiStructure, RlsModule } from '../types';
1213
import './types';
1314

1415
const log = new Logger('api');
@@ -122,7 +123,7 @@ interface ApiListRow {
122123
}
123124

124125
interface ResolveContext {
125-
opts: ApiOptions;
126+
opts: ConstructiveOptions;
126127
pool: Pool;
127128
domain: string;
128129
subdomain: string | null;
@@ -166,7 +167,7 @@ export const getSubdomain = (subdomains: string[]): string | null => {
166167
return filtered.length ? filtered.join('.') : null;
167168
};
168169

169-
export const getSvcKey = (opts: ApiOptions, req: Request): string => {
170+
export const getSvcKey = (opts: ConstructiveOptions, req: Request): string => {
170171
const { domain, subdomains } = getUrlDomains(req);
171172
const baseKey = subdomains.filter((n) => n !== 'www').concat(domain).join('.');
172173

@@ -195,7 +196,7 @@ const toRlsModule = (row: RlsModuleRow | null): RlsModule | undefined => {
195196
};
196197
};
197198

198-
const toApiStructure = (row: ApiRow, opts: ApiOptions, rlsModuleRow?: RlsModuleRow | null): ApiStructure => ({
199+
const toApiStructure = (row: ApiRow, opts: ConstructiveOptions, rlsModuleRow?: RlsModuleRow | null): ApiStructure => ({
199200
apiId: row.api_id,
200201
dbname: row.dbname || opts.pg?.database || '',
201202
anonRole: row.anon_role || 'anon',
@@ -209,7 +210,7 @@ const toApiStructure = (row: ApiRow, opts: ApiOptions, rlsModuleRow?: RlsModuleR
209210
});
210211

211212
const createAdminStructure = (
212-
opts: ApiOptions,
213+
opts: ConstructiveOptions,
213214
schemas: string[],
214215
databaseId?: string
215216
): ApiStructure => ({
@@ -408,7 +409,7 @@ const buildDevFallbackError = async (
408409
// =============================================================================
409410

410411
export const getApiConfig = async (
411-
opts: ApiOptions,
412+
opts: ConstructiveOptions,
412413
req: Request
413414
): Promise<ApiConfigResult> => {
414415
const pool = getPgPool(opts.pg);
@@ -500,7 +501,7 @@ export const getApiConfig = async (
500501
// Express Middleware
501502
// =============================================================================
502503

503-
export const createApiMiddleware = (opts: ApiOptions) => {
504+
export const createApiMiddleware = (opts: ConstructiveOptions) => {
504505
return async (req: Request, res: Response, next: NextFunction): Promise<void> => {
505506
log.debug(`[api-middleware] ${req.method} ${req.path}`);
506507

graphql/server/src/middleware/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getNodeEnv } from '@constructive-io/graphql-env';
1+
import { getNodeEnv } from '@pgpmjs/env';
22
import { Logger } from '@pgpmjs/logger';
33
import { PgpmOptions } from '@pgpmjs/types';
44
import { NextFunction, Request, RequestHandler, Response } from 'express';

graphql/server/src/middleware/debug-memory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getNodeEnv } from '@constructive-io/graphql-env';
1+
import { getNodeEnv } from '@pgpmjs/env';
22
import { Logger } from '@pgpmjs/logger';
33
import { svcCache } from '@pgpmjs/server-utils';
44
import type { RequestHandler } from 'express';

graphql/server/src/middleware/error-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getNodeEnv } from '@constructive-io/graphql-env';
1+
import { getNodeEnv } from '@pgpmjs/env';
22
import { Logger } from '@pgpmjs/logger';
33
import type { ErrorRequestHandler, NextFunction, Request, Response } from 'express';
44

graphql/server/src/middleware/graphile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import crypto from 'node:crypto';
2-
import { getNodeEnv } from '@constructive-io/graphql-env';
2+
import { getNodeEnv } from '@pgpmjs/env';
33
import type { ConstructiveOptions } from '@constructive-io/graphql-types';
44
import { Logger } from '@pgpmjs/logger';
55
import type { NextFunction, Request, RequestHandler, Response } from 'express';

0 commit comments

Comments
 (0)