@terabits/grapi
Version:
Grapi Schema Generator For GraphQL Server
113 lines (112 loc) • 3.86 kB
TypeScript
import { IObjectTypeResolver } from 'graphql-tools';
export interface Pagination {
last?: number;
first?: number;
before?: string;
after?: string;
perPage?: number;
page?: number;
take?: number;
skip?: number;
}
declare type PromiseOrScalar<T> = T | (() => Promise<T>);
export interface PaginatedResponse {
data: any[];
total: PromiseOrScalar<number>;
hasNextPage: PromiseOrScalar<boolean>;
hasPreviousPage: PromiseOrScalar<boolean>;
}
export declare enum Operator {
eq = "eq",
contains = "contains",
notcontains = "notcontains",
neq = "neq",
gt = "gt",
gte = "gte",
lt = "lt",
lte = "lte",
in = "in",
notIn = "nin",
all = "all",
between = "between",
or = "OR",
and = "AND",
object = "object",
size = "size",
elementMatch = "elementMatch",
elementMatchObject = "elementMatchObject"
}
export declare enum WhereOperator {
base = "BaseFilter",
relation = "RelationFilter"
}
export declare enum OrderType {
ASC = 1,
DESC = -1
}
export declare type Where = Record<string, Record<string, any>>;
export declare type OrderBy = Record<string, OrderType>;
export interface ListFindQuery {
pagination?: Pagination;
where?: Where;
orderBy?: OrderBy;
}
export interface ListReadable {
find(query?: ListFindQuery, context?: any): Promise<PaginatedResponse>;
findOne({ where }: {
where: Where;
}, context?: any): Promise<any>;
findOneById(id: string, context?: any): Promise<any>;
}
export declare enum ArrayOperator {
set = "set",
add = "add",
remove = "remove"
}
export interface ArrayOperation {
fieldName: string;
value: any;
operator: ArrayOperator;
model: string;
isList: boolean;
}
export interface Mutation {
getData(): Record<string, any>;
addField(name: string, value: any): void;
getArrayOperations(): ArrayOperation[];
}
export interface ListMutable {
findOneById(id: string): Promise<any>;
create(mutation: Mutation, context?: any): Promise<any>;
update(where: Where, mutation: Mutation, context?: any): Promise<any>;
delete(where: Where, context?: any): Promise<any>;
}
export interface MapReadable {
getMap?(): Promise<Record<string, any>>;
}
export interface MapMutable {
updateMap?(mutation: Mutation): Promise<void>;
}
export interface ToOneRelation {
findOneByRelation(foreignKey: string, foreignId: string, context: any): Promise<any>;
updateOneRelation(id: string, foreignKey: string, foreignId: string, context: any): Promise<void>;
}
export interface EmbeddableRelation {
addEmbedIds?(foreignKey: string, ids: string[], context: any): any;
removeEmbedIds?(foreignKey: string, ids: string[], context: any): any;
findOneByEmbedId?(foreignKey: string, foreignId: string, context: any): Promise<any>;
findManyByEmbedId?(foreignKey: string, foreignId: string, context: any): Promise<any[]>;
}
export interface OneToManyRelation {
findManyFromOneRelation(listFindQuery: ListFindQuery, context: any): Promise<any[]>;
}
export interface ManyToManyRelation {
findManyFromManyRelation(sourceSideName: string, targetSideName: string, sourceSideId: string, listFindQuery: ListFindQuery, context: any): Promise<any[]>;
addIdToManyRelation(sourceSideName: string, targetSideName: string, sourceSideId: string, targetSideId: string, context: any): Promise<void>;
removeIdFromManyRelation(sourceSideName: string, targetSideName: string, sourceSideId: string, targetSideId: string, context: any): Promise<void>;
}
export interface FieldResolvable {
resolveFields?(): IObjectTypeResolver;
}
export declare type DataSource = ListReadable & ListMutable & MapReadable & MapMutable & ToOneRelation & OneToManyRelation & ManyToManyRelation & EmbeddableRelation & FieldResolvable;
export {};