Skip to content

persisted-documents

@evolve-storefront/persisted-documents · v1.0.0

Compute the id a trusted-documents router expects, for a document that carries none.

Get started

  1. Install the package with the peer dependencies it needs. It comes from the Evolve registry, which needs a one-time sign-in.

    pnpm add @evolve-storefront/persisted-documents graphql
    Requirements1
    graphql^16 || ^17

Then render it on a page:

import { documentId } from "@evolve-storefront/persisted-documents";
import { initClientFetcher } from "@labdigital/graphql-fetcher";
// Every feature operation now posts an id the router's trusted-documents list knows.
export const fetcher = initClientFetcher("https://gateway.example/graphql", {
createDocumentId: documentId,
});

Functions

documentIdRead an embedded id, or derive one from a GraphQL AST by stripping client-only selections, printing canonically and hashing.
import { documentId } from "@evolve-storefront/persisted-documents";
function documentId(query: unknown): string | undefined

Returns string | undefined

documentIdHashThe bare hex sha256 digest of a printed document.
import { documentIdHash } from "@evolve-storefront/persisted-documents";
function documentIdHash(operation: string): string

Returns string

Constants

persistedDocumentsSet as the client preset's presetConfig.persistedDocuments to publish matching ids and embed them where documentId reads them, including in string documents.
import { persistedDocuments } from "@evolve-storefront/persisted-documents";
const persistedDocuments: { readonly mode: "embedHashInDocument"; readonly hashPropertyName: "documentId"; readonly hashAlgorithm: (operation: string) => string; }