Skip to content

feat: add cacheFactory option to createMockClient for custom cache support#648

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-cache-factory-support
Draft

feat: add cacheFactory option to createMockClient for custom cache support#648
Copilot wants to merge 2 commits intomainfrom
copilot/add-cache-factory-support

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 19, 2026

Summary

The @graphitation/apollo-mock-client package hardcodes InMemoryCache in createMockClient, preventing use of custom Apollo cache implementations like ForestRun. This PR adds a cacheFactory option so users can provide their own cache.

Changes

src/index.ts

  • Added cacheFactory option to createMockClient options:
    cacheFactory?: (possibleTypes: Record<string, string[]>) => ApolloCache<NormalizedCacheObject>
  • When cacheFactory is provided, it receives the computed possibleTypes (derived from the schema) and returns a custom cache instance
  • When cacheFactory is not provided, the default InMemoryCache behavior is preserved (fully backward compatible)

Tests

  • 3 unit tests for the generic cacheFactory option (default behavior, custom factory usage, possibleTypes passing)
  • 2 integration tests with ForestRun cache (instantiation and full query resolution with component rendering)

Usage

import { ForestRun } from "@graphitation/apollo-forest-run";
import { createMockClient } from "@graphitation/apollo-mock-client";

const client = createMockClient(schema, {
  cacheFactory: (possibleTypes) => new ForestRun({ possibleTypes }),
});

Copilot AI and others added 2 commits March 19, 2026 09:16
…pport

Co-authored-by: pavelglac <42679661+pavelglac@users.noreply.github.com>
Co-authored-by: pavelglac <42679661+pavelglac@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants