import { GraphQLObjectType, GraphQLInputObjectType, GraphQLResolveInfo, GraphQLFieldResolver, GraphQLFieldConfigMap, GraphQLFieldConfigArgumentMap, Thunk, GraphQLInputObjectTypeConfig, GraphQLOutputType, FieldDefinitionNode, GraphQLObjectTypeConfig, GraphQLInputFieldConfigMap } from "graphql"; import { PubSub } from "graphql-subscriptions"; declare type Maybe = null | undefined | T; /** * 查询的类型 */ export declare enum Query { ONE = "one", LIST = "list", AGGREGATE = "aggregate" } /** * mutation的类型 */ export declare enum Mutation { CREATE = "create", UPDATE = "update", REMOVE = "remove" } /** * 订阅事件的类型 */ export declare enum Subscription { CREATED = "created", UPDATED = "updated", REMOVED = "removed" } export interface BaseHook { /** * 调用方法前的钩子,可以重置args * @param source * @param args * @param context * @param info */ before?(source: TSource, args: TArgs, context: TContext, info: GraphQLResolveInfo): MaybePromise; /** * 调用方法后的钩子,可以重置response * @param response * @param source * @param args * @param context * @param info */ after?(response: M, source: TSource, args: TArgs, context: TContext, info: GraphQLResolveInfo): MaybePromise; } export declare type MaybePromise = T | null | Promise; export declare type Resolver = (resolve: GraphQLFieldResolver) => GraphQLFieldResolver; declare type GraphQLFieldConfigOptions = { description?: Maybe; type?: GraphQLOutputType; args?: GraphQLFieldConfigArgumentMap; resolve?: GraphQLFieldResolver; subscribe?: GraphQLFieldResolver; deprecationReason?: Maybe; extensions?: Maybe>>; astNode?: Maybe; }; export declare type BaseFieldConfig = GraphQLFieldConfigOptions & BaseHook & { name?: string; }; export interface BaseQuery { getOne?: BaseFieldConfig; getList?: BaseFieldConfig; getAggregate?: BaseFieldConfig; } export interface BaseMutation { create?: BaseFieldConfig; update?: BaseFieldConfig; remove?: BaseFieldConfig; } export declare type FilterFn = (rootValue: M, args: TArgs, context?: TContext, info?: any) => boolean | Promise; export interface BaseTypeConfig { /** *模型的字段,可以在此添加其它字段 */ modelFields?: Thunk>; modelTypeConfig?: GraphQLObjectTypeConfig; } export interface BaseType { modelType: GraphQLObjectType; pageType: GraphQLObjectType; } export interface BaseInputType { createType: GraphQLInputObjectType; updateType: GraphQLInputObjectType; } export interface BaseInputTypeConfig { createTypeConfig?: GraphQLInputObjectTypeConfig; updateTypeConfig?: GraphQLInputObjectTypeConfig; filterTypeConfig?: GraphQLInputObjectTypeConfig; } export declare type FilterActions = T[] | ((key: T) => boolean); export interface CommonConfig { /** * 包含的query,可以为布尔类型,可以传一个数组,或者传一个函数 */ includeQuery?: boolean | FilterActions; /** * 包含的mutation,可以为布尔类型,可以传一个数组,或者传一个函数 */ includeMutation?: boolean | FilterActions; /** * 包含的subscription,可以为布尔类型,可以传一个数组,或者传一个函数 */ includeSubscription?: boolean | FilterActions; /** * 不包含的query,可以传一个数组,或者传一个函数 */ excludeQuery?: FilterActions; /** * 不包含的mutation,可以传一个数组,或者传一个函数 */ excludeMutation?: FilterActions; /** * 不包含的subscription,可以传一个数组,或者传一个函数 */ excludeSubscription?: FilterActions; } export interface BaseFieldsConfig { /** * 自定义query字段 */ queryFields?: Thunk>; /** * 自定义mutation字段 */ mutationFields?: Thunk>; /** * 自定义subscription字段 */ subscriptionFields?: Thunk>; /** * 关联的字段 */ associationsFields?: Thunk>; /** * 新建参数的关联字段 */ associationsCreateFields?: Thunk; /** * 更新参数的关联字段 */ associationsUpdateFields?: Thunk; } export declare type BaseConfig = CommonConfig & BaseQuery & BaseMutation & BaseInputTypeConfig & BaseTypeConfig & BaseFieldsConfig & BaseHook & { /** * 设置基本名称,默认是以model的name属性 */ name?: Thunk; /** * 设置主键字段 */ primaryKey?: GraphQLFieldConfigArgumentMap; /** * 描述 */ description?: Thunk; /** * graphql-subscriptions 的实例 */ pubSub?: PubSub; /** * 增删改三个事件的通用过滤器,优先拦截 */ filterSubscription?: FilterFn; /** * 映射模型字段 * @param fields */ handleModelFields?: (fields: GraphQLFieldConfigMap) => GraphQLFieldConfigMap; /** * 映射创建参数字段 * @param fields */ handleCreateTypeFields?: (fields: GraphQLInputFieldConfigMap) => GraphQLInputFieldConfigMap; /** * 映射更新参数字段 * @param fields */ handleUpdateTypeFields?: (fields: GraphQLInputFieldConfigMap) => GraphQLInputFieldConfigMap; }; export interface BaseAdapterInterface, TArgs> extends BaseQuery, BaseMutation, BaseType, BaseInputType, BaseFieldsConfig { /** * model 的所有查询字段 */ queryFields: GraphQLFieldConfigMap; /** * model 的所有mutation */ mutationFields: GraphQLFieldConfigMap; } export {};