mirror of
https://github.com/graphql-hive/console
synced 2026-05-23 09:08:34 +00:00
parent
50405d0bb3
commit
bd6e500532
4 changed files with 83 additions and 1 deletions
5
.changeset/tricky-ducks-yell.md
Normal file
5
.changeset/tricky-ducks-yell.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@graphql-hive/client': patch
|
||||
---
|
||||
|
||||
Fix the wrong cacheKey from #397
|
||||
|
|
@ -401,7 +401,13 @@ export function createCollector({
|
|||
};
|
||||
}
|
||||
|
||||
return cache(collect, cacheDocumentKey, LRU<CacheResult>(max, ttl));
|
||||
return cache(
|
||||
collect,
|
||||
function cacheKey(doc, variables) {
|
||||
return cacheDocumentKey(doc, processVariables === true ? variables : null);
|
||||
},
|
||||
LRU<CacheResult>(max, ttl)
|
||||
);
|
||||
}
|
||||
|
||||
function resolveTypeName(inputType: GraphQLType): string {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ export function cache<R, A, K, V>(
|
|||
return {
|
||||
key,
|
||||
value: cachedValue,
|
||||
cacheHit: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +49,7 @@ export function cache<R, A, K, V>(
|
|||
return {
|
||||
key,
|
||||
value,
|
||||
cacheHit: false,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -239,6 +239,75 @@ test('collect all input fields when `processVariables` has not been passed and i
|
|||
expect(info.fields).toContain(`PaginationInput.offset`);
|
||||
});
|
||||
|
||||
test('should get a cache hit when document is the same but variables are different (by default)', async () => {
|
||||
const collect = createCollector({
|
||||
schema,
|
||||
max: 1,
|
||||
});
|
||||
const doc = parse(/* GraphQL */ `
|
||||
query getProjects($pagination: PaginationInput!, $type: ProjectType!) {
|
||||
projects(filter: { pagination: $pagination, type: $type }) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`);
|
||||
const first = collect(doc, {
|
||||
pagination: {
|
||||
limit: 1,
|
||||
},
|
||||
type: 'STITCHING',
|
||||
});
|
||||
|
||||
const second = collect(doc, {
|
||||
pagination: {
|
||||
offset: 2,
|
||||
},
|
||||
type: 'STITCHING',
|
||||
});
|
||||
|
||||
expect(first.cacheHit).toBe(false);
|
||||
expect(second.cacheHit).toBe(true);
|
||||
});
|
||||
|
||||
test('(processVariables: true) should get a cache miss when document is the same but variables are different', async () => {
|
||||
const collect = createCollector({
|
||||
schema,
|
||||
max: 1,
|
||||
processVariables: true,
|
||||
});
|
||||
const doc = parse(/* GraphQL */ `
|
||||
query getProjects($pagination: PaginationInput!, $type: ProjectType!) {
|
||||
projects(filter: { pagination: $pagination, type: $type }) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`);
|
||||
const first = collect(doc, {
|
||||
pagination: {
|
||||
limit: 1,
|
||||
},
|
||||
type: 'STITCHING',
|
||||
});
|
||||
|
||||
const second = collect(doc, {
|
||||
pagination: {
|
||||
offset: 2,
|
||||
},
|
||||
type: 'STITCHING',
|
||||
});
|
||||
|
||||
const third = collect(doc, {
|
||||
pagination: {
|
||||
offset: 2,
|
||||
},
|
||||
type: 'STITCHING',
|
||||
});
|
||||
|
||||
expect(first.cacheHit).toBe(false);
|
||||
expect(second.cacheHit).toBe(false);
|
||||
expect(third.cacheHit).toBe(true);
|
||||
});
|
||||
|
||||
test('(processVariables: true) collect used-only input fields', async () => {
|
||||
const collect = createCollector({
|
||||
schema,
|
||||
|
|
|
|||
Loading…
Reference in a new issue