UNPKG

@nestjs/graphql

Version:

Nest - modern, fast, powerful node.js web framework (@graphql)

22 lines 1.18 kB
import { GqlTypeReference } from '../../interfaces'; import { EnumMetadata } from '../metadata'; /** * Normalizes a `defaultValue` declared on an argument / input field whose * type references a `registerEnumType`-registered enum. * * GraphQL serializes enum default values through the enum's internal value * lookup (see `GraphQLEnumType#serialize`), so the library must pass the * enum's internal VALUE (not its KEY) as `defaultValue`. When a user writes * `defaultValue: 'BOOKS'` for `enum Category { BOOKS = 'books' }`, the * produced SDL fails validation with * `Enum "Category" cannot represent value: "BOOKS"`. * * This helper keeps the value untouched whenever it already matches a * registered enum value, otherwise it checks whether the supplied string * matches an enum KEY and translates it to the matching enum value so * `astFromValue` can emit the correct SDL literal. * * See: https://github.com/nestjs/graphql/issues/3618 */ export declare function normalizeEnumDefaultValue<T = unknown>(defaultValue: T, typeRef: GqlTypeReference | undefined, enumsMetadata: EnumMetadata[]): T; //# sourceMappingURL=normalize-enum-default-value.helper.d.ts.map