/
Subschema.ts
45 lines (33 loc) · 1.46 KB
/
Subschema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { GraphQLSchema } from 'graphql';
import { SubschemaConfig, Transform, MergedTypeConfig, CreateProxyingResolverFn, BatchingOptions } from './types';
import { applySchemaTransforms } from './applySchemaTransforms';
import { Executor } from '@graphql-tools/utils';
export function isSubschema(value: any): value is Subschema {
return Boolean(value.transformedSchema);
}
interface ISubschema<K = any, V = any, C = K, TContext = Record<string, any>>
extends SubschemaConfig<K, V, C, TContext> {
transformedSchema: GraphQLSchema;
}
export class Subschema<K = any, V = any, C = K, TContext = Record<string, any>>
implements ISubschema<K, V, C, TContext>
{
public schema: GraphQLSchema;
public executor?: Executor<TContext>;
public batch?: boolean;
public batchingOptions?: BatchingOptions<K, V, C>;
public createProxyingResolver?: CreateProxyingResolverFn<TContext>;
public transforms: Array<Transform<any, TContext>>;
public transformedSchema: GraphQLSchema;
public merge?: Record<string, MergedTypeConfig<any, any, TContext>>;
constructor(config: SubschemaConfig<K, V, C, TContext>) {
this.schema = config.schema;
this.executor = config.executor;
this.batch = config.batch;
this.batchingOptions = config.batchingOptions;
this.createProxyingResolver = config.createProxyingResolver;
this.transforms = config.transforms ?? [];
this.transformedSchema = applySchemaTransforms(this.schema, config);
this.merge = config.merge;
}
}