Skip to content

Commit fc06034

Browse files
committed
fix: updates
1 parent b69cce2 commit fc06034

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

shared/test/entity-caching.test.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import {
55
LATEST_ROUTER_COMPATIBILITY_VERSION,
66
parse,
77
} from '@wundergraph/composition';
8-
import { EntityCaching } from '@wundergraph/cosmo-connect/dist/node/v1/node_pb';
8+
import { EntityCachingConfiguration } from '@wundergraph/cosmo-connect/dist/node/v1/node_pb';
99
import { buildRouterConfig, ComposedSubgraph, SubgraphKind } from '../src';
1010

11-
// Drives a single subgraph through federation + buildRouterConfig and returns the EntityCaching
11+
// Drives a single subgraph through federation + buildRouterConfig and returns the EntityCachingConfiguration
1212
// proto message attached to its datasource configuration (or undefined when no caching directives
13-
// are present). Exercises builder.ts#toEntityCaching end-to-end.
14-
function buildEntityCaching(sdl: string): EntityCaching | undefined {
13+
// are present). Exercises builder.ts#extractEntityCachingConfiguration end-to-end.
14+
function buildEntityCaching(sdl: string): EntityCachingConfiguration | undefined {
1515
const result = federateSubgraphs({
1616
subgraphs: [{ name: 'test', url: '', definitions: parse(sdl) }],
1717
version: LATEST_ROUTER_COMPATIBILITY_VERSION,
@@ -38,11 +38,11 @@ function buildEntityCaching(sdl: string): EntityCaching | undefined {
3838
federatedSDL: sdl,
3939
schemaVersionId: '',
4040
});
41-
return routerConfig.engineConfig!.datasourceConfigurations[0].entityCaching;
41+
return routerConfig.engineConfig!.datasourceConfigurations[0].entityCachingConfiguration;
4242
}
4343

44-
describe('Entity caching router-config builder (toEntityCaching)', () => {
45-
test('maps every entity-caching directive type into the EntityCaching message', () => {
44+
describe('Entity caching router-config builder (extractEntityCachingConfiguration)', () => {
45+
test('maps every entity-caching directive type into the EntityCachingConfiguration message', () => {
4646
const ec = buildEntityCaching(`
4747
type Query {
4848
product(id: ID! @openfed__is(fields: "id")): Product @openfed__queryCache(maxAge: 30)
@@ -65,19 +65,19 @@ describe('Entity caching router-config builder (toEntityCaching)', () => {
6565
expect(ec).toBeDefined();
6666

6767
// @openfed__requestScoped
68-
expect(ec!.requestScopedFields).toHaveLength(1);
69-
expect(ec!.requestScopedFields[0].fieldName).toBe('me');
70-
expect(ec!.requestScopedFields[0].typeName).toBe('Query');
71-
expect(ec!.requestScopedFields[0].l1Key).toBe('test.u');
68+
expect(ec!.requestScopedConfigurations).toHaveLength(1);
69+
expect(ec!.requestScopedConfigurations[0].fieldName).toBe('me');
70+
expect(ec!.requestScopedConfigurations[0].typeName).toBe('Query');
71+
expect(ec!.requestScopedConfigurations[0].l1Key).toBe('test.u');
7272

7373
// @openfed__entityCache (Int args become BigInt; flag defaults preserved)
74-
expect(ec!.entityCacheConfigurations).toHaveLength(1);
75-
expect(ec!.entityCacheConfigurations[0].typeName).toBe('Product');
76-
expect(ec!.entityCacheConfigurations[0].maxAgeSeconds).toBe(60n);
77-
expect(ec!.entityCacheConfigurations[0].notFoundCacheTtlSeconds).toBe(5n);
78-
expect(ec!.entityCacheConfigurations[0].includeHeaders).toBe(true);
79-
expect(ec!.entityCacheConfigurations[0].partialCacheLoad).toBe(false);
80-
expect(ec!.entityCacheConfigurations[0].shadowMode).toBe(false);
74+
expect(ec!.entityCache).toHaveLength(1);
75+
expect(ec!.entityCache[0].typeName).toBe('Product');
76+
expect(ec!.entityCache[0].maxAgeSeconds).toBe(60n);
77+
expect(ec!.entityCache[0].notFoundCacheTtlSeconds).toBe(5n);
78+
expect(ec!.entityCache[0].includeHeaders).toBe(true);
79+
expect(ec!.entityCache[0].partialCacheLoad).toBe(false);
80+
expect(ec!.entityCache[0].shadowMode).toBe(false);
8181

8282
// @openfed__queryCache with @openfed__is mapping (non-batch)
8383
expect(ec!.queryCacheConfigurations).toHaveLength(1);
@@ -96,13 +96,13 @@ describe('Entity caching router-config builder (toEntityCaching)', () => {
9696
// @openfed__cacheInvalidate
9797
expect(ec!.cacheInvalidateConfigurations).toHaveLength(1);
9898
expect(ec!.cacheInvalidateConfigurations[0].fieldName).toBe('updateProduct');
99-
expect(ec!.cacheInvalidateConfigurations[0].operationType).toBe('Mutation');
99+
expect(ec!.cacheInvalidateConfigurations[0].operationType).toBe('mutation');
100100
expect(ec!.cacheInvalidateConfigurations[0].entityTypeName).toBe('Product');
101101

102102
// @openfed__cachePopulate with explicit maxAge
103103
expect(ec!.cachePopulateConfigurations).toHaveLength(1);
104104
expect(ec!.cachePopulateConfigurations[0].fieldName).toBe('createProduct');
105-
expect(ec!.cachePopulateConfigurations[0].operationType).toBe('Mutation');
105+
expect(ec!.cachePopulateConfigurations[0].operationType).toBe('mutation');
106106
expect(ec!.cachePopulateConfigurations[0].entityTypeName).toBe('Product');
107107
expect(ec!.cachePopulateConfigurations[0].maxAgeSeconds).toBe(45n);
108108
});
@@ -126,7 +126,7 @@ describe('Entity caching router-config builder (toEntityCaching)', () => {
126126
expect(fm.isBatch).toBe(true);
127127
});
128128

129-
test('a Subscription @openfed__cachePopulate without maxAge omits maxAgeSeconds', () => {
129+
test('a Subscription @openfed__cachePopulate without maxAge falls back to the entityCache TTL', () => {
130130
const ec = buildEntityCaching(`
131131
type Query {
132132
dummy: String!
@@ -144,10 +144,10 @@ describe('Entity caching router-config builder (toEntityCaching)', () => {
144144
expect(ec!.cachePopulateConfigurations).toHaveLength(1);
145145
const cp = ec!.cachePopulateConfigurations[0];
146146
expect(cp.fieldName).toBe('productStream');
147-
expect(cp.operationType).toBe('Subscription');
147+
expect(cp.operationType).toBe('subscription');
148148
expect(cp.entityTypeName).toBe('Product');
149-
// maxAge omitted on the directive → builder passes undefined, leaving the optional proto field unset.
150-
expect(cp.maxAgeSeconds).toBeUndefined();
149+
// maxAge omitted on the directive → composition falls back to the entity's @openfed__entityCache TTL (60s).
150+
expect(cp.maxAgeSeconds).toBe(60n);
151151
});
152152

153153
test('a subgraph with no entity-caching directives omits the EntityCaching message', () => {

0 commit comments

Comments
 (0)