Parsing & Validation Caching

By default, Hive Gateway maintains a parsing and validation cache. If requests contain documents that have been executed before, they will not be parsed and validated again.

Using the parser cache can improve performance up to ~60%, and using the validation cache up to ~50% (based on benchmarks).

This behavior is built-in and can be optionally disabled using the parserAndValidationCache options:

gateway.config.ts
import { defineConfig } from "@graphql-hive/gateway";

export const gatewayConfig = defineConfig({
  // disable parse and validate caching
  parserAndValidationCache: false,
});

Furthermore, you can provide your own cache store to both of these plugins by implementing the following interface:

interface CacheStore<T> {
  get(key: string): T | undefined;
  set(key: string, value: T): void;
}

You can then pass your cache store to the parserAndValidationCache options:

gateway.config.ts
import { defineConfig } from "@graphql-hive/gateway";

export const gatewayConfig = defineConfig({
  parserAndValidationCache: {
    documentCache: documentCacheStore as CacheStore<DocumentNode>,
    errorCache: errorCacheStore as CacheStore<Error>,
    validationCache: validationCacheStore as CacheStore<typeof validate>,
  },
});