import { DocumentNode } from 'graphql'; import { ContextService } from '../context/contextService'; import { CustomFunctionLogger } from '../logger'; export interface GraphQLArgument { [key: string]: string | number | boolean | string[] | null | undefined; } export interface GraphQLRecord extends GraphQLArgument { UID: string; } export type GraphQLArgumentAssertion = { [P in keyof T]: T[P] extends (string | null | undefined) ? T[P] : T[P] extends (number | null | undefined) ? T[P] : T[P] extends (boolean | null | undefined) ? T[P] : T[P] extends (string[] | null | undefined) ? T[P] : never; }; export type GraphQLRecordAssertion = GraphQLArgumentAssertion & { UID: string; }; interface IBaseGraphQLError { message: string; path?: string[]; locations?: { line: number; column: number; }[]; } export interface IGraphQLErrorDefault extends IBaseGraphQLError { } export interface IGraphQLErrorOther extends IBaseGraphQLError { extensions: { errorType: string; }; } export interface IGraphQLErrorMutation extends IBaseGraphQLError { extensions: { errorType: 'mutation_errors'; mutation_errors: { type: string; message: string; }[]; }; } export type IGraphQLError = IGraphQLErrorDefault | IGraphQLErrorMutation | IGraphQLErrorOther; interface GraphQLMutationResult { schema: { [operationName: string]: string; }; } export interface GraphQLRequest { query: string; variables?: Record; } export type GraphQLQueryFields = string[]; export type GraphQLInput = 'after' | 'first' | 'filter' | 'orderBy' | 'offset'; export interface GraphQLFilters { after?: string; first?: number; filter?: string; orderBy?: string; offset?: number; } /** A structured, equality-only filter: `{ Field: value }` → `Field == AND …`. */ export type StructuredFilter = Record; export interface GetRecordsInput { /** PascalCase schema/API name — the same string used as `schema` in executeOperations, e.g. 'JobTasks'. */ objectName: string; /** Node fields to select, e.g. ['UID', 'Name', 'Seq']. At least one required. */ fields: string[]; /** Raw EQL string (`JobId == "abc"`) passed through verbatim, or a structured equality object. */ filters?: string | StructuredFilter; /** EQL orderBy clause, e.g. 'Seq ASC'. */ order?: string; /** Page size → GraphQL `first`. Capped at 200; use executeFetchAutoPagination for more. */ limit?: number; } export interface ResultWithCursor { nodes: T[]; lastCursor: string; hasNextPage: boolean; offset: number; } export declare enum GraphOperationType { insert = "insert", update = "update", delete = "delete" } interface BaseGraphOperation { schema: string; operation: GraphOperationType; data: string | GraphQLArgument | GraphQLRecord; } export interface GraphCreateOperation extends BaseGraphOperation { data: GraphQLArgument; alias?: string; } export interface GraphUpdateOperation extends BaseGraphOperation { data: GraphQLRecord; } export interface GraphDeleteOperation extends BaseGraphOperation { data: string; } export type GraphOperation = GraphCreateOperation | GraphUpdateOperation | GraphDeleteOperation; export declare function isGraphCreateOperation(x: GraphOperation): x is GraphCreateOperation; export declare function isGraphUpdateOperation(x: GraphOperation): x is GraphUpdateOperation; export declare function isGraphDeleteOperation(x: GraphOperation): x is GraphDeleteOperation; export interface AutoPaginationResponse { page: { totalCount: number; edges: { node: T; }[]; }; } export type UnwrapAutoPagination> = T extends AutoPaginationResponse ? U : never; export interface AutoPaginationVariables { offset?: number | null; filter?: string | null; orderBy?: string | null; } declare abstract class BaseGraphQLError extends Error { constructor(); abstract getErrors(): string[]; } export declare class GraphQLDefaultError extends BaseGraphQLError { private errors; constructor(errors: IGraphQLErrorDefault[]); getErrors(): string[]; } export declare class GraphQLMutationError extends BaseGraphQLError { private errors; private rawData; constructor(errors: IGraphQLErrorMutation[], rawData: _.Dictionary[]); getErrors(): string[]; getErrorsWithInput(): any; } export declare class GraphQLNetworkError { statusCode: number; message: string; constructor(statusCode: number, message: string); } export declare function sanitizeData(data: T): { [P in keyof T]: T[keyof T] | Exclude, null | undefined>; }; export declare function flattenGraphQlEdges(object: { edges: { node: V; }[]; }): V[]; export declare function transformMutationResultToAliasIdMap(result: GraphQLMutationResult, rawOrderedOps: GraphOperation[]): { [aliasId: string]: string; }; export declare class GraphQLService { private _contextService; private _logger; private graphQLSchema; constructor(_contextService: ContextService, _logger: CustomFunctionLogger); buildSchema(): Promise; /** * Although, the "http-link" API supports graphQL streaming results, * it won't currently work because we're not using a caching layer * of any sort. For now, we're going to keep this as private since * the regular `fetch` method uses this. * * The backend dosen't really support it all that well either since mutations * only return the UID and nothing else. */ private _executeQuery; private _executeBatchQuery; private _buildMutationWithAliases; executeQueryForDocument(query: DocumentNode, variables: V): Promise; executeQuery(queryString: string, variables: V): Promise; executeOperations(operations: GraphOperation[]): Promise<{ [id: string]: string; }>; /** * Auto pagination GraphQl Request * @param query * @param variables * @example example is in boilerplates/jp-mobile-fn/src/data.ts * sample query in boilerplates/jp-typegen-library/src/queries/queries.graphql */ executeFetchAutoPaginationForDocument, V extends AutoPaginationVariables, U extends { UID: string; } = UnwrapAutoPagination>(query: DocumentNode, variables: Omit): Promise; executeFetchAutoPagination, V extends AutoPaginationVariables, U extends { UID: string; } = UnwrapAutoPagination>(queryString: string, variables: Omit): Promise; private _fetchFromUID; private getObjectType; getFieldsFromName(name: string): import("graphql").GraphQLFieldMap; /** * Fetch records without hand-writing a query string or unwrapping the `edges/node` envelope. * Builds the Skedulo connection query from `objectName` + `fields`, runs it through `executeQuery`, * and returns a flat array of nodes. * * `filters` is either a raw EQL string (`JobId == "abc"`) used verbatim, or a structured equality * object (`{ JobId: 'abc', IsActive: true }`) → `JobId == "abc" AND IsActive == true`. * * Single page only: `limit` maps to GraphQL `first` and is capped at 200. For larger reads use * `executeFetchAutoPagination`. * * @example * const rows = await graphqlService.getRecords({ * objectName: 'JobTasks', * fields: ['UID', 'Name', 'Seq'], * filters: { JobId: context.contextObjectId }, * order: 'Seq ASC', * limit: 50 * }) */ getRecords(input: GetRecordsInput): Promise; } export {}; //# sourceMappingURL=graphqlService.d.ts.map