import { DocumentNode, GraphQLSchema } from 'graphql'; export type TrustedDocumentVariant = { /** The stable id a client sends in place of the operation. */ id: string; /** The printed, normalised operation, with every fragment it depends on. */ body: string; }; export type TrustedDocument = TrustedDocumentVariant & { /** * The same operation as an Apollo client will send it. * * Apollo Client runs every operation through `addTypenameToDocument` before the link chain sees * it, so what a browser puts on the wire - and hashes - always carries `__typename` on every * selection set. That is never the operation as written, so a client hashing its own documents * would agree with nothing in the manifest. Both variants go into the safelist and either is * accepted; the server executes whichever one the client actually asked for, which matters * because `InMemoryCache` cannot normalise a result that came back without `__typename`. * * Undefined when the transform changes nothing - an operation selecting no nested fields, say - * because then the two variants are the same document and one entry covers both. */ apollo?: TrustedDocumentVariant; operationName?: string; operationType: 'query' | 'mutation' | 'subscription'; /** Where this came from, so build failures can point somewhere useful. */ source: string; }; export type ExtractedDocument = { document: DocumentNode; source: string; }; export declare class TrustedDocumentError extends Error { } export declare const hashDocument: (body: string) => string; /** * Turn loaded documents into trusted documents: one entry per operation, each carrying the * fragments it needs, validated against the schema and keyed by a hash of its printed body. */ export type BuildOptions = { /** * What to do with a document that doesn't validate against the schema. * * `throw` for anything the developer wrote: a typo should fail the build rather than quietly * dropping an operation their app depends on. * * `skip` for the documents we generate for the Admin UI. That enumeration is a superset of * what the Admin UI can actually send - it offers a create mutation for every entity, say, * including read only ones that have none. If the schema has no such operation then the Admin * UI can't send it either, so dropping it is right, and the schema is a better authority on * that than trying to mirror the Admin UI's own conditions here. */ onInvalid?: 'throw' | 'skip'; }; export declare const buildTrustedDocuments: (extracted: ExtractedDocument[], schema?: GraphQLSchema, { onInvalid }?: BuildOptions) => TrustedDocument[];