import { GraphQLInterfaceTypeConfig } from 'graphql'; import type { FieldResolver, GetGen, InterfaceFieldsFor, ModificationType } from '../typegenTypeHelpers'; import type { ArgsRecord } from './args'; import { OutputDefinitionBlock, OutputDefinitionBuilder } from './definitionBlocks'; import { AbstractTypes, Maybe, NonNullConfig, SourceTypingDef } from './_types'; export declare type Implemented = GetGen<'interfaceNames'> | NexusInterfaceTypeDef; export interface FieldModification { type?: ModificationType; /** The description to annotate the GraphQL SDL */ description?: Maybe; /** The resolve method we should be resolving the field with */ resolve?: FieldResolver; /** You are allowed to add non-required args when modifying a field */ args?: Maybe; /** * Custom extensions, as supported in graphql-js * * @see https://github.com/graphql/graphql-js/issues/1527 */ extensions?: GraphQLInterfaceTypeConfig['extensions']; } export interface FieldModificationDef extends FieldModification { field: FieldName; } export declare type NexusInterfaceTypeConfig = { name: TypeName; definition(t: InterfaceDefinitionBlock): void; /** * Configures the nullability for the type, check the documentation's "Getting Started" section to learn * more about GraphQL Nexus's assumptions and configuration on nullability. */ nonNullDefaults?: NonNullConfig; /** The description to annotate the GraphQL SDL */ description?: Maybe; /** Source type information for this type */ sourceType?: SourceTypingDef; /** * Custom extensions, as supported in graphql-js * * @see https://github.com/graphql/graphql-js/issues/1527 */ extensions?: GraphQLInterfaceTypeConfig['extensions']; /** Adds this type as a method on the Object/Interface definition blocks */ asNexusMethod?: string; } & AbstractTypes.MaybeTypeDefConfigFieldResolveType; export interface InterfaceDefinitionBuilder extends OutputDefinitionBuilder { addInterfaces(toAdd: Implemented[]): void; addModification(toAdd: FieldModificationDef): void; } export declare class InterfaceDefinitionBlock extends OutputDefinitionBlock { protected typeBuilder: InterfaceDefinitionBuilder; constructor(typeBuilder: InterfaceDefinitionBuilder); /** @param interfaceName */ implements(...interfaceName: Array): void; /** Modifies a field added via an interface */ modify, string>>(field: FieldName, modifications: FieldModification): void; } export declare class NexusInterfaceTypeDef { readonly name: TypeName; protected config: NexusInterfaceTypeConfig; constructor(name: TypeName, config: NexusInterfaceTypeConfig); get value(): NexusInterfaceTypeConfig; } /** * [API Docs](https://nxs.li/docs/api/interface-type) | [Abstract Types * Guide](https://nxs.li/guides/abstract-types) | [2018 GraphQL * Spec](https://spec.graphql.org/June2018/#sec-Interfaces) * * Defines an Interface type. * * Interface types are one of the two abstract type in GraphQL. They let you express polymorphic fields * wherein the field may return a number of different object types but they all share some subset of fields. * Interface types in Nexus also serve as a way to share a set of fields amongst different object types. * * @example * export const Media = interfaceType({ * name: 'Media', * resolveType(source) { * return 'director' in source ? 'Movie' : 'Song' * }, * definition(t) { * t.string('url') * }, * }) * * export const Movie = objectType({ * name: 'Movie', * definition(t) { * t.implements('Media') * t.string('director') * }, * }) * * export const Song = objectType({ * name: 'Song', * definition(t) { * t.implements('Media') * t.string('album') * }, * }) * * // GraphQL SDL * // ----------- * // * // interface Media { * // url: String * // } * // * // type Movie implements Media { * // director: String * // url: String * // } * // * // type Song implements Media { * // album: String * // url: String * // } * * @param config Specify your interface's name, its fields, and more. See each config property's jsDoc for more detail. */ export declare function interfaceType(config: NexusInterfaceTypeConfig): NexusInterfaceTypeDef;