UNPKG

t-graphql

Version:

typed GraphQL - end-to-end type-safe GraphQL for TypeScript. Think tRPC, but GraphQL

76 lines (75 loc) 3.26 kB
import { NamedType } from '../NamedType.abstract'; import { AnyType } from '../types/AnyType.type'; import { Prettify } from '../types/Prettify.type'; import { AnyParamObjectType, ParamObjectType } from './ParamObjectType'; export declare class ObjectType<Name extends string, S extends Record<string, { type: AnyType; optional: boolean; params: AnyParamObjectType | null; }>> extends NamedType<Name> { schema: S; constructor(typename: Name, schema: S); field<K extends string, T extends AnyType>(key: K, type: T): ObjectType<Name, Prettify<S & { [k in K]: { type: T; optional: false; params: AnyParamObjectType | null; }; }>>; paramField<K extends string, Params extends ParamObjectType<Record<string, any>>, T extends AnyType>(key: K, paramBuilder: (params: ParamObjectType<Record<never, any>>) => Params, type: T): ObjectType<Name, Prettify<S & { [k in K]: { type: T; optional: false; params: Params; }; }>>; optionalField<K extends string, T extends AnyType>(key: K, type: T): ObjectType<Name, Prettify<S & { [k in K]: { type: T; optional: true; params: AnyParamObjectType | null; }; }>>; optionalParamField<K extends string, Params extends ParamObjectType<Record<string, any>>, T extends AnyType>(key: K, paramBuilder: (params: ParamObjectType<Record<never, any>>) => Params, type: T): ObjectType<Name, Prettify<S & { [k in K]: { type: T; optional: true; params: Params; }; }>>; listField<K extends string, Ts extends [AnyType] | [AnyType, null]>(key: K, itemTypes: Ts): ObjectType<Name, Prettify<S & { [k in K]: { type: Ts; optional: false; params: AnyParamObjectType | null; }; }>>; listParamField<K extends string, Params extends ParamObjectType<Record<string, any>>, Ts extends [AnyType] | [AnyType, null]>(key: K, paramBuilder: (params: ParamObjectType<Record<never, any>>) => Params, itemTypes: Ts): ObjectType<Name, Prettify<S & { [k in K]: { type: Ts; optional: false; params: Params; }; }>>; optionalListField<K extends string, Ts extends [AnyType] | [AnyType, null]>(key: K, itemTypes: Ts): ObjectType<Name, Prettify<S & { [k in K]: { type: Ts; optional: true; params: AnyParamObjectType | null; }; }>>; optionalListParamField<K extends string, Params extends ParamObjectType<Record<string, any>>, Ts extends [AnyType] | [AnyType, null]>(key: K, paramBuilder: (params: ParamObjectType<Record<never, any>>) => Params, itemTypes: Ts): ObjectType<Name, Prettify<S & { [k in K]: { type: Ts; optional: true; params: Params; }; }>>; } export declare function objectType<Name extends string>(typename: Name): ObjectType<Name, {}>; export type AnyObjectType = ObjectType<string, Record<string, { type: AnyType; optional: boolean; params: AnyParamObjectType | null; }>>; export type AnyObjectListType = [AnyObjectType] | [AnyObjectType, null];