Skip to content

Commit 8e5e528

Browse files
committed
fix(graphql-server): restore ApiOptions type for api middleware
1 parent af56e78 commit 8e5e528

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

graphql/server/src/middleware/api.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
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';
54
import { parseUrl } from '@constructive-io/url-domains';
65
import { NextFunction, Request, Response } from 'express';
76
import { Pool } from 'pg';
87
import { getPgPool } from 'pg-cache';
98

109
import errorPage50x from '../errors/50x';
1110
import errorPage404Message from '../errors/404-message';
12-
import { ApiConfigResult, ApiError, ApiStructure, RlsModule } from '../types';
11+
import { ApiConfigResult, ApiError, ApiOptions, ApiStructure, RlsModule } from '../types';
1312
import './types';
1413

1514
const log = new Logger('api');
@@ -123,7 +122,7 @@ interface ApiListRow {
123122
}
124123

125124
interface ResolveContext {
126-
opts: ConstructiveOptions;
125+
opts: ApiOptions;
127126
pool: Pool;
128127
domain: string;
129128
subdomain: string | null;
@@ -167,7 +166,7 @@ export const getSubdomain = (subdomains: string[]): string | null => {
167166
return filtered.length ? filtered.join('.') : null;
168167
};
169168

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

@@ -196,7 +195,7 @@ const toRlsModule = (row: RlsModuleRow | null): RlsModule | undefined => {
196195
};
197196
};
198197

199-
const toApiStructure = (row: ApiRow, opts: ConstructiveOptions, rlsModuleRow?: RlsModuleRow | null): ApiStructure => ({
198+
const toApiStructure = (row: ApiRow, opts: ApiOptions, rlsModuleRow?: RlsModuleRow | null): ApiStructure => ({
200199
apiId: row.api_id,
201200
dbname: row.dbname || opts.pg?.database || '',
202201
anonRole: row.anon_role || 'anon',
@@ -210,7 +209,7 @@ const toApiStructure = (row: ApiRow, opts: ConstructiveOptions, rlsModuleRow?: R
210209
});
211210

212211
const createAdminStructure = (
213-
opts: ConstructiveOptions,
212+
opts: ApiOptions,
214213
schemas: string[],
215214
databaseId?: string
216215
): ApiStructure => ({
@@ -409,7 +408,7 @@ const buildDevFallbackError = async (
409408
// =============================================================================
410409

411410
export const getApiConfig = async (
412-
opts: ConstructiveOptions,
411+
opts: ApiOptions,
413412
req: Request
414413
): Promise<ApiConfigResult> => {
415414
const pool = getPgPool(opts.pg);
@@ -501,7 +500,7 @@ export const getApiConfig = async (
501500
// Express Middleware
502501
// =============================================================================
503502

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

graphql/server/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import type { PgpmOptions } from '@pgpmjs/types';
2+
import type { ApiOptions as ApiConfig } from '@constructive-io/graphql-types';
3+
14
export interface CorsModuleData {
25
urls: string[];
36
}
@@ -43,3 +46,5 @@ export interface ApiStructure {
4346

4447
export type ApiError = { errorHtml: string };
4548
export type ApiConfigResult = ApiStructure | ApiError | null;
49+
50+
export type ApiOptions = PgpmOptions & { api?: ApiConfig };

0 commit comments

Comments
 (0)