@graphql-yoga/plugin-persisted-operations
Version:
Persisted Operations plugin for GraphQL Yoga.
48 lines (47 loc) • 2.05 kB
text/typescript
import { DocumentNode, GraphQLErrorOptions } from 'graphql';
import { GraphQLParams, Plugin, PromiseOrValue } from 'graphql-yoga';
import { OnParamsEventPayload } from 'graphql-yoga/src/plugins/types';
export type ExtractPersistedOperationId = (params: GraphQLParams) => null | string;
export declare const defaultExtractPersistedOperationId: ExtractPersistedOperationId;
type AllowArbitraryOperationsHandler = (request: Request) => PromiseOrValue<boolean>;
export type UsePersistedOperationsOptions = {
/**
* A function that fetches the persisted operation
*/
getPersistedOperation(key: string, request: Request): PromiseOrValue<DocumentNode | string | null>;
/**
* Whether to allow execution of arbitrary GraphQL operations aside from persisted operations.
*/
allowArbitraryOperations?: boolean | AllowArbitraryOperationsHandler;
/**
* The path to the persisted operation id
*/
extractPersistedOperationId?: ExtractPersistedOperationId;
/**
* Whether to skip validation of the persisted operation
*/
skipDocumentValidation?: boolean;
/**
* Custom errors to be thrown
*/
customErrors?: CustomPersistedQueryErrors;
};
export type CustomErrorFactory = string | (GraphQLErrorOptions & {
message: string;
}) | ((payload: OnParamsEventPayload) => Error);
export type CustomPersistedQueryErrors = {
/**
* Error to be thrown when the persisted operation is not found
*/
notFound?: CustomErrorFactory;
/**
* Error to be thrown when rejecting non-persisted operations
*/
persistedQueryOnly?: CustomErrorFactory;
/**
* Error to be thrown when the extraction of the persisted operation id failed
*/
keyNotFound?: CustomErrorFactory;
};
export declare function usePersistedOperations<TPluginContext extends Record<string, any>>({ allowArbitraryOperations, extractPersistedOperationId, getPersistedOperation, skipDocumentValidation, customErrors, }: UsePersistedOperationsOptions): Plugin<TPluginContext>;
export {};