@incubrain/client
Version:
A type-safe GraphQL client for Hasura, optimized for Node.js and Nuxt environments with full TypeScript support.
61 lines (60 loc) • 2.57 kB
TypeScript
import { BaseClient } from "./base.client.js";
import type { DocumentNode } from "graphql";
import type { ClientConfig, FindManyArgs, FindUniqueArgs, Operation, CreateArgs, UpdateArgs, DeleteArgs, FieldSelection, QueryOptions } from "./types.js";
export type SelectableField = {
[key: string]: boolean | SelectableField;
};
export type EntityConfig = {
fields: readonly string[];
relations: {
[key: string]: {
fields?: readonly string[];
defaultInclude?: boolean;
};
};
};
/**
* Base class for entity-specific clients with CRUD operations
* @template TEntity - The entity type (e.g., User, Post)
* @template TInsertInput - The input type for create operations
* @template TSetInput - The input type for update operations
* @template TWhereInput - The variables type for operations
*/
export declare abstract class EntityClient<TEntity, TInsertInput, TSetInput, // Input type for update operations (e.g., UserUpdateInput)
TWhereInput> extends BaseClient {
protected entityName: string;
protected config: EntityConfig;
constructor(config: ClientConfig, entityName: string, entityConfig: EntityConfig);
protected buildFieldSelection(selection?: FieldSelection<TEntity>): string;
/**
* Find multiple entities matching the given criteria
*/
findMany(args?: FindManyArgs<TEntity>): Promise<TEntity[]>;
findUnique(args: FindUniqueArgs<TEntity>): Promise<TEntity | null>;
/**
* Find a unique entity by its identifier
*/
/**
* Create a new entity
*/
create(args: CreateArgs<TInsertInput, TEntity>): Promise<TEntity>;
/**
* Update an existing entity
*/
update(args: UpdateArgs<TSetInput, TWhereInput>): Promise<TEntity>;
/**
* Delete an entity
*/
delete(args: DeleteArgs<TEntity, TWhereInput>): Promise<TEntity>;
protected executeOperation<T>(operation: Operation, args: TWhereInput & QueryOptions): Promise<T>;
protected getOperationDocument(operationKey: string, selection: string): DocumentNode;
protected abstract getFindManyDocument(selection: string): DocumentNode;
protected abstract getFindUniqueDocument(selection: string): DocumentNode;
protected abstract getCreateDocument(selection: string): DocumentNode;
protected abstract getUpdateDocument(selection: string): DocumentNode;
protected abstract getDeleteDocument(selection: string): DocumentNode;
/**
* Get the response key for a given operation
*/
protected getResponseKey(operation: string): string;
}