UNPKG

@quell/server

Version:

Quell is an open-source NPM package providing a light-weight caching layer implementation and cache invalidation for GraphQL responses on both the client- and server-side. Use Quell to prevent redundant client-side API requests and to minimize costly serv

72 lines 4.72 kB
import type { GraphQLSchema, DocumentNode } from "graphql"; import type { ProtoObjType, FragsType, MutationMapType, QueryMapType, FieldsMapType, ParseASTOptions, QueryObject, MergedResponse, DataResponse } from "../types/types"; /** * Traverses over a supplied query Object and uses the fields on there to create a query string reflecting the data. * This query string is a modified version of the query string received by Quell that has references to data found within the cache removed * so that the final query is faster and reduced in scope. * @param {Object} queryObject - A modified version of the prototype with only values we want to pass onto the queryString. * @param {string} operationType - A string indicating the GraphQL operation type- 'query', 'mutation', etc. */ export declare function createQueryStr(queryObject: QueryObject | ProtoObjType, operationType?: string): string; /** * Takes in a map of fields and true/false values (the prototype) and creates a query object containing any values missing from the cache. * The resulting queryObj is then used as a template to create GraphQL query strings. * @param {ProtoObjType} map - Map of fields and true/false values from initial request, should be the prototype. * @returns {Object} queryObject that includes only the values to be requested from GraphQL endpoint. */ export declare function createQueryObj(map: ProtoObjType): ProtoObjType; /** * Combines two objects containing results from separate sources and outputs a single object with information from both sources combined, * formatted to be delivered to the client, using the queryProto as a template for how to structure the final response object. * @param {Object} cacheResponse - Response data from the cache. * @param {Object} serverResponse - Response data from the server or external API. * @param {Object} queryProto - Current slice of the prototype being used as a template for final response object structure. * @param {boolean} fromArray - Whether or not the current recursive loop came from within an array (should NOT be supplied to function call). */ export declare function joinResponses(cacheResponse: DataResponse, serverResponse: DataResponse, queryProto: QueryObject | ProtoObjType, fromArray?: boolean): MergedResponse; /** * Traverses the abstract syntax tree depth-first to create a template for future operations, such as * request data from the cache, creating a modified query string for additional information needed, and joining cache and database responses. * @param {Object} AST - An abstract syntax tree generated by GraphQL library that we will traverse to build our prototype. * @param {Object} options - (not fully integrated) A field for user-supplied options. * @returns {Object} prototype object * @returns {string} operationType * @returns {Object} frags object */ export declare function parseAST(AST: DocumentNode, options?: ParseASTOptions): { proto: ProtoObjType; operationType: string; frags: FragsType; }; /** * Takes collected fragments and integrates them onto the prototype where referenced. * @param {Object} protoObj - Prototype before it has been updated with fragments. * @param {Object} frags - Fragments object to update prototype with. * @returns {Object} Updated prototype object. */ export declare function updateProtoWithFragment(protoObj: ProtoObjType, frags: FragsType): ProtoObjType; /** * Generates a map of mutation to GraphQL object types. This mapping is used * to identify references to cached data when mutation occurs. * @param {Object} schema - GraphQL defined schema that is used to facilitate caching by providing valid queries, * mutations, and fields. * @returns {Object} mutationMap - Map of mutations to GraphQL types. */ export declare function getMutationMap(schema: GraphQLSchema): MutationMapType; /** * Generates a map of queries to GraphQL object types. This mapping is used * to identify and create references to cached data. * @param {Object} schema - GraphQL defined schema that is used to facilitate caching by providing valid queries, * mutations, and fields. * @returns {Object} queryMap - Map of queries to GraphQL types. */ export declare function getQueryMap(schema: GraphQLSchema): QueryMapType; /** * Generates of map of fields to GraphQL types. This mapping is used to identify * and create references to cached data. * @param {Object} schema - GraphQL defined schema that is used to facilitate caching by providing valid queries, * mutations, and fields. * @returns {Object} fieldsMap - Map of fields to GraphQL types. */ export declare function getFieldsMap(schema: any): FieldsMapType; //# sourceMappingURL=quellHelpers.d.ts.map