Documentation
Gateway
Other Features
Performance/Cache
Parsing and Validation Caching

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
})
💡

Due to the restrictions of the GraphQL execution flow, we cannot use an async cache storage as we use in other caching plugins. So the cache storage for the parser and validation cache should be synchronous, and it is an in-memory store by default.

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>
  }
})
💡

We’d recommend to keep the default behavior as-is since it’s already optimized for performance.