import { assertValidName } from 'graphql' import { AllOutputTypesPossible } from '../typegenTypeHelpers' import { OutputDefinitionBlock } from './definitionBlocks' import { NexusTypes, withNexusSymbol } from './_types' import { IsSubscriptionType, SubscriptionBuilder } from './subscriptionType' export interface NexusExtendTypeConfig { type: TypeName definition( t: IsSubscriptionType extends true ? SubscriptionBuilder : OutputDefinitionBlock ): void } export class NexusExtendTypeDef { constructor( readonly name: TypeName, protected config: NexusExtendTypeConfig & { name: TypeName } ) { assertValidName(name) } get value() { return this.config } } withNexusSymbol(NexusExtendTypeDef, NexusTypes.ExtendObject) /** * Adds new fields to an existing objectType in the schema. Useful when * splitting your schema across several domains. * * @see https://nexusjs.org/docs/api/extend-type */ export function extendType(config: NexusExtendTypeConfig) { return new NexusExtendTypeDef(config.type, { ...config, name: config.type }) as NexusExtendTypeDef }