import { ClientOptions } from 'graphql-ws'; import { RxReplicationWriteToMasterRow } from '../replication-protocol.ts'; import { ById, MaybePromise } from '../util.ts'; import { ReplicationOptions, ReplicationPullHandlerResult, ReplicationPullOptions, ReplicationPushHandlerResult, ReplicationPushOptions } from './replication.ts'; export interface RxGraphQLReplicationQueryBuilderResponseObject { query: string; operationName?: string; variables: any; } export type RxGraphQLReplicationClientState = { headers: ById; credentials: RequestCredentials | undefined; }; export type RxGraphQLReplicationQueryBuilderResponse = RxGraphQLReplicationQueryBuilderResponseObject | Promise; export type RxGraphQLReplicationPushQueryBuilder = ( // typed 'any' because the data might be modified by the push.modifier. rows: RxReplicationWriteToMasterRow[] ) => RxGraphQLReplicationQueryBuilderResponse; export type RxGraphQLPullWSOptions = Omit; export type RxGraphQLReplicationPullQueryBuilder = ( latestPulledCheckpoint: CheckpointType | undefined, limit: number ) => RxGraphQLReplicationQueryBuilderResponse; export type GraphQLSyncPullOptions = Omit< ReplicationPullOptions, 'handler' | 'stream$' > & { queryBuilder: RxGraphQLReplicationPullQueryBuilder; streamQueryBuilder?: RxGraphQLReplicationPullStreamQueryBuilder; /** * The path to the data in the GraphQL response. * If set, the data will be taken from the response at this path. * @example ['data', 'foo', 'bar'] or 'data.foo.bar' */ dataPath?: string | string[]; responseModifier?: RxGraphQLPullResponseModifier; includeWsHeaders?: boolean; wsOptions?: RxGraphQLPullWSOptions; }; export type RxGraphQLPullResponseModifier = ( // the exact response that was returned from the server plainResponse: ReplicationPullHandlerResult | any, // either 'handler' if it came from the pull.handler, or 'stream' if it came from the pull.stream origin: 'handler' | 'stream', requestCheckpoint?: CheckpointType ) => MaybePromise>; export type RxGraphQLPushResponseModifier = ( // the exact response that was returned from the server plainResponse: ReplicationPushHandlerResult | any, ) => MaybePromise>; export type RxGraphQLReplicationPullStreamQueryBuilder = (headers: { [k: string]: string; }) => RxGraphQLReplicationQueryBuilderResponse; export type GraphQLSyncPushOptions = Omit< ReplicationPushOptions, 'handler' > & { queryBuilder: RxGraphQLReplicationPushQueryBuilder; /** * The path to the data in the GraphQL response. * If set, the data will be taken from the response at this path. * @example ['data', 'foo', 'bar'] or 'data.foo.bar' */ dataPath?: string | string[]; responseModifier?: RxGraphQLPushResponseModifier; }; export type GraphQLServerUrl = { http?: string; ws?: string; }; export type SyncOptionsGraphQL = Omit< ReplicationOptions, 'pull' | 'push' > & { url: GraphQLServerUrl; fetch?: WindowOrWorkerGlobalScope['fetch']; headers?: { [k: string]: string; }; // send with all requests to the endpoint credentials?: RequestCredentials; pull?: GraphQLSyncPullOptions; push?: GraphQLSyncPushOptions; };