UNPKG

@miragejs/graphql

Version:

A library for handling GraphQL requests with Mirage JS

66 lines (65 loc) 2.4 kB
import type Model from "miragejs/lib/orm/model.ts"; import type { GraphQLObjectLike, QueryArgs } from "./@types/index.js"; import type { GraphQLType } from "graphql"; type CursorEncoder = (s: string) => string; export type RelayConnection = { edges: RelayEdge[]; pageInfo: RelayPageInfo; totalCount: number; }; export type RelayEdge = { cursor: string | number; node: { [key: string]: any; }; }; export type RelayPageInfo = { hasPreviousPage: boolean; hasNextPage: boolean; startCursor: string | null; endCursor: string | null; }; declare const NON_RELAY_ARGS_KEY = "nonRelayArgs"; declare const RELAY_ARGS_KEY = "relayArgs"; /** * Given a list of records and a hash of Relay pagination arguments, it creates * a list of filtered Relay connection edges. It also accepts an encoding * function to create cursors. If no encoding function is passed in, a default * is used. * * @see {@link https://relay.dev/graphql/connections.htm#sec-Edge-Types} */ export declare function getEdges(records: Model[], args: QueryArgs, typeName: string, encode?: CursorEncoder): RelayEdge[]; /** * Given a list of records and a list of edges, this function compares the two * lists and builds page info for a Relay connection. * * @see {@link https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo} */ export declare function getPageInfo(records: Model[], edges: RelayEdge[]): RelayPageInfo; /** * Given a list of arguments, it separates Relay pagination args (first, last, * after, before) from any other arguments. */ export declare function getRelayArgs(args: QueryArgs): { [NON_RELAY_ARGS_KEY]: QueryArgs; [RELAY_ARGS_KEY]: QueryArgs; }; /** * Utility function to determine if a given type is a Relay connection. */ export declare function isRelayConnectionType(type: GraphQLObjectLike): boolean; /** * Utility function to determine if a given type is a Relay connection edge. */ export declare function isRelayEdgeType(type: GraphQLObjectLike): boolean; /** * Utility function to determine if a given type is Relay connection page info. */ export declare function isRelayPageInfoType(type: GraphQLObjectLike): boolean; /** * Utility function to determine if a given type is a Relay connection, a Relay * connection edge or Relay connection page info. */ export declare function isRelayType(type: GraphQLType): boolean; export {};