1 | import {
|
2 | InputDefinitionBlock,
|
3 | OutputDefinitionBlock,
|
4 | } from "./definitions/definitionBlocks";
|
5 | import { withNexusSymbol, NexusTypes } from "./definitions/_types";
|
6 | import { PluginBuilderLens } from "./builder";
|
7 |
|
8 | export type OutputFactoryConfig<T> = {
|
9 | stage: "walk" | "build";
|
10 | args: any[];
|
11 | builder: PluginBuilderLens;
|
12 | typeDef: OutputDefinitionBlock<any>;
|
13 | |
14 |
|
15 |
|
16 | typeName: string;
|
17 | };
|
18 |
|
19 | export type InputFactoryConfig<T> = {
|
20 | args: any[];
|
21 | builder: PluginBuilderLens;
|
22 | typeDef: InputDefinitionBlock<any>;
|
23 | |
24 |
|
25 |
|
26 | typeName: string;
|
27 | };
|
28 |
|
29 | export interface BaseExtensionConfig<T extends string> {
|
30 | |
31 |
|
32 |
|
33 |
|
34 | name: T;
|
35 | |
36 |
|
37 |
|
38 |
|
39 | typeDefinition?: string;
|
40 | }
|
41 |
|
42 | export interface DynamicOutputMethodConfig<T extends string>
|
43 | extends BaseExtensionConfig<T> {
|
44 | |
45 |
|
46 |
|
47 | factory(config: OutputFactoryConfig<T>): any;
|
48 | }
|
49 |
|
50 | export interface DynamicInputMethodConfig<T extends string>
|
51 | extends BaseExtensionConfig<T> {
|
52 | |
53 |
|
54 |
|
55 | factory(config: InputFactoryConfig<T>): any;
|
56 | }
|
57 |
|
58 | export class DynamicInputMethodDef<Name extends string> {
|
59 | constructor(
|
60 | readonly name: Name,
|
61 | protected config: DynamicInputMethodConfig<Name>
|
62 | ) {}
|
63 | get value() {
|
64 | return this.config;
|
65 | }
|
66 | }
|
67 | withNexusSymbol(DynamicInputMethodDef, NexusTypes.DynamicInput);
|
68 |
|
69 | export class DynamicOutputMethodDef<Name extends string> {
|
70 | constructor(
|
71 | readonly name: Name,
|
72 | protected config: DynamicOutputMethodConfig<Name>
|
73 | ) {}
|
74 | get value() {
|
75 | return this.config;
|
76 | }
|
77 | }
|
78 | withNexusSymbol(DynamicOutputMethodDef, NexusTypes.DynamicOutputMethod);
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | export function dynamicOutputMethod<T extends string>(
|
96 | config: DynamicOutputMethodConfig<T>
|
97 | ) {
|
98 | return new DynamicOutputMethodDef(config.name, config);
|
99 | }
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | export function dynamicInputMethod<T extends string>(
|
106 | config: DynamicInputMethodConfig<T>
|
107 | ) {
|
108 | return new DynamicInputMethodDef(config.name, config);
|
109 | }
|