UNPKG

@apollo/generate-persisted-query-manifest

Version:

Creates a Persisted Query Manifest from an Apollo Client Web project

124 lines 4.36 kB
import type { FragmentRegistryAPI } from "@apollo/client/cache"; import type { DocumentTransform as RealDocumentTransform } from "@apollo/client/core"; import { type DocumentNode } from "graphql"; import type { VFile } from "vfile"; type OperationType = "query" | "mutation" | "subscription"; type DocumentTransform = any extends RealDocumentTransform ? never : RealDocumentTransform; interface CreateOperationIdOptions { operationName: string; type: OperationType; createDefaultId: () => string; } export interface PersistedQueryManifestConfig { /** * Paths to your GraphQL documents: queries, mutations, subscriptions, and fragments. * Prefix the pattern with `!` to specify a path that should be ignored. */ documents?: string | string[] | CustomDocumentSourceConfig; /** * A `DocumentTransform` instance that will be used to transform the GraphQL * document before it is saved to the manifest. * * For more information about document transforms, see the [Document * transforms](https://www.apollographql.com/docs/react/data/document-transforms) * documentation page. * * IMPORTANT: You must be running `@apollo/client` 3.8.0 or greater to use * this feature. * * @example * ```ts * import { DocumentTransform } from "@apollo/client/core"; * * const config = { * documentTransform: new DocumentTransform((document) => { * // ... transform the document * * return transformedDocument; * }) * } * ``` * * @since 1.2.0 */ documentTransform?: DocumentTransform; /** * Path where the manifest file will be written. */ output?: string; /** * Whether to add `__typename` fields to selection sets in operations. * Defaults to true; set to false if you also pass `addTypename: false` to * your `InMemoryCache` constructor in your app. * * Note that the ability to pass `addTypename: false` will not be supported in * Apollo Client v4. */ addTypename?: boolean; /** * Function that generates a manifest operation ID for a given query. * * Defaults to a sha256 hash of the query. */ createOperationId?: (query: string, options: CreateOperationIdOptions) => string; } interface DocumentSourceConfig { fragmentRegistry?: FragmentRegistryAPI; sources: DocumentSource[]; } interface CustomDocumentSourceConfig { [CUSTOM_DOCUMENTS_SOURCE]: () => DocumentSourceConfig; } declare const CUSTOM_DOCUMENTS_SOURCE: unique symbol; export interface PersistedQueryManifestOperation { id: string; name: string; type: OperationType; body: string; } export interface PersistedQueryManifest { format: "apollo-persisted-query-manifest"; version: 1; operations: PersistedQueryManifestOperation[]; } /** * Source documents from a persisted documents manifest generated by [GraphQL * Codegen](https://the-guild.dev/graphql/codegen). Using this utility skips all file system traversal and uses the * documents defined in the persisted documents file. * * For more information see the [Persisted documents](https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#persisted-documents) documentation. * * @example * ```ts * import { * fromGraphQLCodegenPersistedDocuments * } from '@apollo/generate-persisted-query-manifest'; * * const config = { * documents: fromGraphQLCodegenPersistedDocuments('./path/to/persisted-documents.json') * }; * ``` * * @since 1.2.0 */ export declare function fromGraphQLCodegenPersistedDocuments(filepath: string): CustomDocumentSourceConfig; export declare const defaults: { documents: string[]; output: string; createOperationId: (query: string) => string; }; interface Location { line: number; column: number; } interface DocumentSource { node: DocumentNode | null; file: VFile; location: Location | undefined; } /** @internal */ export declare function getFilepaths(documents: string | string[] | CustomDocumentSourceConfig): Promise<string[]>; /** @internal */ export declare function generatePersistedQueryManifest(config: PersistedQueryManifestConfig | undefined, configFilePath: string | undefined): Promise<PersistedQueryManifest>; export {}; //# sourceMappingURL=index.d.ts.map