@pothos/core
Version:
Pothos (formerly GiraphQL) is a plugin based schema builder for creating code-first GraphQL schemas in typescript
299 lines (265 loc) • 11.2 kB
text/typescript
import { SchemaBuilder as SchemaBuilderClass } from './builder';
import { FieldBuilder as InternalFieldBuilder } from './fieldUtils/builder';
import { InputFieldBuilder as InternalInputFieldBuilder } from './fieldUtils/input';
import { InterfaceFieldBuilder as InternalInterfaceFieldBuilder } from './fieldUtils/interface';
import { MutationFieldBuilder as InternalMutationFieldBuilder } from './fieldUtils/mutation';
import { ObjectFieldBuilder as InternalObjectFieldBuilder } from './fieldUtils/object';
import { QueryFieldBuilder as InternalQueryFieldBuilder } from './fieldUtils/query';
import { RootFieldBuilder as InternalRootFieldBuilder } from './fieldUtils/root';
import { SubscriptionFieldBuilder as InternalSubscriptionFieldBuilder } from './fieldUtils/subscription';
import { ArgumentRef as InternalArgumentRef } from './refs/arg';
import { BaseTypeRef as InternalBaseTypeRef } from './refs/base';
import { EnumRef as InternalEnumRef } from './refs/enum';
import { FieldRef as InternalFieldRef } from './refs/field';
import { InputFieldRef as InternalInputFieldRef } from './refs/input-field';
import { InputListRef as InternalInputListRef } from './refs/input-list';
import {
ImplementableInputObjectRef as InternalImplementableInputObjectRef,
InputObjectRef as InternalInputObjectRef,
} from './refs/input-object';
import {
ImplementableInterfaceRef as InternalImplementableInterfaceRef,
InterfaceRef as InternalInterfaceRef,
} from './refs/interface';
import { ListRef as InternalListRef } from './refs/list';
import {
ImplementableObjectRef as InternalImplementableObjectRef,
ObjectRef as InternalObjectRef,
} from './refs/object';
import { ScalarRef as InternalScalarRef } from './refs/scalar';
import { UnionRef as InternalUnionRef } from './refs/union';
import './types/global';
import type {
AddVersionedDefaultsToBuilderOptions,
FieldKind,
InputTypeParam,
NormalizeSchemeBuilderOptions,
PothosInputFieldConfig,
PothosOutputFieldConfig,
PothosTypeConfig,
RootName,
SchemaTypes,
TypeParam,
} from './types';
export * from './errors';
export * from './plugins';
export * from './types';
export * from './utils';
const SchemaBuilder = SchemaBuilderClass as unknown as {
registerPlugin: typeof SchemaBuilderClass.registerPlugin;
allowPluginReRegistration: boolean;
new <Types extends Partial<PothosSchemaTypes.UserSchemaTypes> = {}>(
options: Types extends { Defaults: 'v3' }
? AddVersionedDefaultsToBuilderOptions<PothosSchemaTypes.ExtendDefaultTypes<Types>, 'v3'>
: NormalizeSchemeBuilderOptions<PothosSchemaTypes.ExtendDefaultTypes<Types>>,
): PothosSchemaTypes.SchemaBuilder<PothosSchemaTypes.ExtendDefaultTypes<Types>>;
};
export default SchemaBuilder;
export const FieldBuilder = InternalFieldBuilder as new <
Types extends SchemaTypes,
ParentShape,
Kind extends Exclude<FieldKind, RootName> = Exclude<FieldKind, RootName>,
>(
builder: PothosSchemaTypes.SchemaBuilder<Types>,
kind: FieldKind,
graphqlKind: PothosSchemaTypes.PothosKindToGraphQLType[FieldKind],
) => PothosSchemaTypes.FieldBuilder<Types, ParentShape, Kind>;
export type RootFieldBuilder<
Types extends SchemaTypes,
ParentShape,
Kind extends FieldKind = FieldKind,
> = PothosSchemaTypes.RootFieldBuilder<Types, ParentShape, Kind>;
export const RootFieldBuilder = InternalRootFieldBuilder as new <
Types extends SchemaTypes,
ParentShape,
Kind extends FieldKind = FieldKind,
>(
builder: PothosSchemaTypes.SchemaBuilder<Types>,
kind: FieldKind,
graphqlKind: PothosSchemaTypes.PothosKindToGraphQLType[FieldKind],
) => PothosSchemaTypes.RootFieldBuilder<Types, ParentShape, Kind>;
export type QueryFieldBuilder<
Types extends SchemaTypes,
ParentShape,
> = PothosSchemaTypes.QueryFieldBuilder<Types, ParentShape>;
export const QueryFieldBuilder = InternalQueryFieldBuilder as new <
Types extends SchemaTypes,
ParentShape,
>(
builder: PothosSchemaTypes.SchemaBuilder<Types>,
) => PothosSchemaTypes.QueryFieldBuilder<Types, ParentShape>;
export type MutationFieldBuilder<
Types extends SchemaTypes,
ParentShape,
> = PothosSchemaTypes.MutationFieldBuilder<Types, ParentShape>;
export const MutationFieldBuilder = InternalMutationFieldBuilder as new <
Types extends SchemaTypes,
ParentShape,
>(
builder: PothosSchemaTypes.SchemaBuilder<Types>,
) => PothosSchemaTypes.MutationFieldBuilder<Types, ParentShape>;
export type SubscriptionFieldBuilder<
Types extends SchemaTypes,
ParentShape,
> = PothosSchemaTypes.SubscriptionFieldBuilder<Types, ParentShape>;
export const SubscriptionFieldBuilder = InternalSubscriptionFieldBuilder as new <
Types extends SchemaTypes,
ParentShape,
>(
builder: PothosSchemaTypes.SchemaBuilder<Types>,
) => PothosSchemaTypes.SubscriptionFieldBuilder<Types, ParentShape>;
export type ObjectFieldBuilder<
Types extends SchemaTypes,
ParentShape,
> = PothosSchemaTypes.ObjectFieldBuilder<Types, ParentShape>;
export const ObjectFieldBuilder = InternalObjectFieldBuilder as new <
Types extends SchemaTypes,
ParentShape,
>(
builder: PothosSchemaTypes.SchemaBuilder<Types>,
) => PothosSchemaTypes.ObjectFieldBuilder<Types, ParentShape>;
export type InterfaceFieldBuilder<
Types extends SchemaTypes,
ParentShape,
> = PothosSchemaTypes.InterfaceFieldBuilder<Types, ParentShape>;
export const InterfaceFieldBuilder = InternalInterfaceFieldBuilder as new <
Types extends SchemaTypes,
ParentShape,
>(
builder: PothosSchemaTypes.SchemaBuilder<Types>,
) => PothosSchemaTypes.InterfaceFieldBuilder<Types, ParentShape>;
export type InputFieldBuilder<
Types extends SchemaTypes,
Kind extends 'Arg' | 'InputObject' = 'Arg' | 'InputObject',
> = PothosSchemaTypes.InputFieldBuilder<Types, Kind>;
export const InputFieldBuilder = InternalInputFieldBuilder as new <
Types extends SchemaTypes,
Kind extends 'Arg' | 'InputObject' = 'Arg' | 'InputObject',
>(
builder: PothosSchemaTypes.SchemaBuilder<Types>,
kind: Kind,
) => PothosSchemaTypes.InputFieldBuilder<Types, Kind>;
export type BaseTypeRef<Types extends SchemaTypes, T> = PothosSchemaTypes.BaseTypeRef<Types, T>;
export const BaseTypeRef = InternalBaseTypeRef as new <Types extends SchemaTypes, T>(
kind: 'Enum' | 'InputObject' | 'Interface' | 'Object' | 'Scalar' | 'Union',
name: string,
) => PothosSchemaTypes.BaseTypeRef<Types, T>;
export type EnumRef<Types extends SchemaTypes, T, P = T> = PothosSchemaTypes.EnumRef<Types, T, P>;
export const EnumRef = InternalEnumRef as new <Types extends SchemaTypes, T, P = T>(
name: string,
) => PothosSchemaTypes.EnumRef<Types, T, P>;
export type InputObjectRef<Types extends SchemaTypes, T> = PothosSchemaTypes.InputObjectRef<
Types,
T
>;
export const InputObjectRef = InternalInputObjectRef as new <Types extends SchemaTypes, T>(
name: string,
) => PothosSchemaTypes.InputObjectRef<Types, T>;
export type ImplementableInputObjectRef<
Types extends SchemaTypes,
T extends object,
> = PothosSchemaTypes.ImplementableInputObjectRef<Types, T>;
export const ImplementableInputObjectRef = InternalImplementableInputObjectRef as new <
Types extends SchemaTypes,
T extends object,
>(
builder: PothosSchemaTypes.SchemaBuilder<Types>,
name: string,
) => PothosSchemaTypes.ImplementableInputObjectRef<Types, T>;
export type InputListRef<Types extends SchemaTypes, T> = PothosSchemaTypes.InputListRef<Types, T>;
export const InputListRef = InternalInputListRef as new <Types extends SchemaTypes, T>(
listType: InputTypeParam<Types>,
required: boolean,
) => PothosSchemaTypes.InputListRef<Types, T>;
export type InterfaceRef<Types extends SchemaTypes, T, P = T> = PothosSchemaTypes.InterfaceRef<
Types,
T,
P
>;
export const InterfaceRef = InternalInterfaceRef as new <Types extends SchemaTypes, T, P = T>(
name: string,
) => PothosSchemaTypes.InterfaceRef<Types, T, P>;
export type ImplementableInterfaceRef<
Types extends SchemaTypes,
T,
P = T,
> = PothosSchemaTypes.ImplementableInterfaceRef<Types, T, P>;
export const ImplementableInterfaceRef = InternalImplementableInterfaceRef as new <
Types extends SchemaTypes,
T,
P = T,
>(
builder: PothosSchemaTypes.SchemaBuilder<Types>,
name: string,
) => PothosSchemaTypes.ImplementableInterfaceRef<Types, T, P>;
export type ObjectRef<Types extends SchemaTypes, T, P = T> = PothosSchemaTypes.ObjectRef<
Types,
T,
P
>;
export const ObjectRef = InternalObjectRef as new <Types extends SchemaTypes, T, P = T>(
name: string,
) => PothosSchemaTypes.ObjectRef<Types, T, P>;
export type ImplementableObjectRef<
Types extends SchemaTypes,
T,
P = T,
> = PothosSchemaTypes.ImplementableObjectRef<Types, T, P>;
export const ImplementableObjectRef = InternalImplementableObjectRef as new <
Types extends SchemaTypes,
T,
P = T,
>(
builder: PothosSchemaTypes.SchemaBuilder<Types>,
name: string,
) => PothosSchemaTypes.ImplementableObjectRef<Types, T, P>;
export type ScalarRef<Types extends SchemaTypes, T, U, P = T> = PothosSchemaTypes.ScalarRef<
Types,
T,
U,
P
>;
export const ScalarRef = InternalScalarRef as new <Types extends SchemaTypes, T, U, P = T>(
name: string,
) => PothosSchemaTypes.ScalarRef<Types, T, U, P>;
export type UnionRef<Types extends SchemaTypes, T, P = T> = PothosSchemaTypes.UnionRef<Types, T, P>;
export const UnionRef = InternalUnionRef as new <Types extends SchemaTypes, T, P = T>(
name: string,
) => PothosSchemaTypes.UnionRef<Types, T, P>;
export type ListRef<Types extends SchemaTypes, T, P = T> = PothosSchemaTypes.ListRef<Types, T, P>;
export const ListRef = InternalListRef as new <Types extends SchemaTypes, T, P = T>(
listType: TypeParam<Types>,
nullable: boolean,
) => PothosSchemaTypes.ListRef<Types, T, P>;
export type FieldRef<
Types extends SchemaTypes,
T = unknown,
Kind extends FieldKind = FieldKind,
> = PothosSchemaTypes.FieldRef<Types, T, Kind>;
export const FieldRef = InternalFieldRef as new <
Types extends SchemaTypes,
T = unknown,
Kind extends FieldKind = FieldKind,
>(
kind: Kind,
initConfig: (name: string, typeConfig: PothosTypeConfig) => PothosOutputFieldConfig<Types>,
) => PothosSchemaTypes.FieldRef<Types, T, Kind>;
export type InputFieldRef<Types extends SchemaTypes, T> = PothosSchemaTypes.InputFieldRef<Types, T>;
export const InputFieldRef = InternalInputFieldRef as new <Types extends SchemaTypes, T>(
initConfig: (name: string, typeConfig: PothosTypeConfig) => PothosInputFieldConfig<Types>,
) => PothosSchemaTypes.InputFieldRef<Types, T>;
export type ArgumentRef<Types extends SchemaTypes, T> = PothosSchemaTypes.ArgumentRef<Types, T>;
export const ArgumentRef = InternalArgumentRef as new <Types extends SchemaTypes, T>(
initConfig: (
name: string,
field: string,
typeConfig: PothosTypeConfig,
) => PothosInputFieldConfig<Types>,
) => PothosSchemaTypes.ArgumentRef<Types, T>;
export { BuildCache } from './build-cache';
export { BuiltinScalarRef } from './refs/builtin-scalar';
export { InputTypeRef } from './refs/input';
export { MutationRef } from './refs/mutation';
export { OutputTypeRef } from './refs/output';
export { QueryRef } from './refs/query';
export { SubscriptionRef } from './refs/subscription';