import { type GraphQLSchema } from 'graphql'; import type { Executor } from '@graphql-tools/utils'; import { applySchemaTransforms } from './applySchemaTransforms.js'; import { type BatchingOptions, type CreateProxyingResolverFn, type MergedTypeConfig, type SubschemaConfig, type Transform, } from './types.js'; export function isSubschema(value: any): value is Subschema { return Boolean(value.transformedSchema); } interface ISubschema< K = any, V = any, C = K, TContext = Record, > extends SubschemaConfig { transformedSchema: GraphQLSchema; } export class Subschema< K = any, V = any, C = K, TContext = Record, > implements ISubschema { public name?: string; public schema: GraphQLSchema; public executor?: Executor; public batch?: boolean; public batchingOptions?: BatchingOptions; public defer?: boolean; public createProxyingResolver?: CreateProxyingResolverFn; public transforms: Array>; private _transformedSchema: GraphQLSchema | undefined; public merge?: Record>; public rootValue?: any; constructor(config: SubschemaConfig) { this.name = config.name; this.schema = config.schema; this.executor = config.executor; this.batch = config.batch; this.batchingOptions = config.batchingOptions; this.defer = config.defer; this.rootValue = config.rootValue; this.createProxyingResolver = config.createProxyingResolver; this.transforms = config.transforms ?? []; this.merge = config.merge; } get transformedSchema(): GraphQLSchema { if (!this._transformedSchema) { if (globalThis.process?.env?.DEBUG != null) { console.warn('Transformed schema is not set yet. Returning a dummy one.'); } this._transformedSchema = applySchemaTransforms(this.schema, this); } return this._transformedSchema; } set transformedSchema(value: GraphQLSchema) { this._transformedSchema = value; } }