import { SchemaBuilder } from './builder' import { OutputDefinitionBlock } from './definitions/definitionBlocks' import { NexusTypes, withNexusSymbol } from './definitions/_types' import { BaseExtensionConfig } from './dynamicMethod' export type OutputPropertyFactoryConfig = { stage: 'walk' | 'build' builder: SchemaBuilder typeDef: OutputDefinitionBlock /** * The name of the type this field is being declared on */ typeName: string } export interface DynamicOutputPropertyConfig extends BaseExtensionConfig { /** * Invoked when the property is accessed (as a getter) */ factory(config: OutputPropertyFactoryConfig): any } export class DynamicOutputPropertyDef { constructor(readonly name: Name, protected config: DynamicOutputPropertyConfig) {} get value() { return this.config } } withNexusSymbol(DynamicOutputPropertyDef, NexusTypes.DynamicOutputProperty) /** * Defines a new property on the object definition block * for an output type, making it possible to build custom DSL's * on top of Nexus, e.g. in nexus-prisma * * t.model.posts() */ export function dynamicOutputProperty(config: DynamicOutputPropertyConfig) { return new DynamicOutputPropertyDef(config.name, config) }