Skip to content

Commit

Permalink
Merge pull request #21 from thematters/develop
Browse files Browse the repository at this point in the history
Release: v1.2.1
  • Loading branch information
robertu7 authored Aug 10, 2020
2 parents d3514df + adb4560 commit e04b624
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@matters/apollo-response-cache",
"version": "1.2.0",
"version": "1.2.1",
"description": "Caching and invalidation mechanisms (plugins, directives) of Apollo GraphQL",
"author": "Matters <hi@matters.news>",
"license": "MIT",
Expand Down
23 changes: 16 additions & 7 deletions src/directives/purgeCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ export const PurgeCacheDirective = ({
return result
}

const extraNodes = extraNodesPath ? get(result, extraNodesPath, []) : []
const nodes = Array.isArray(result)
? [...extraNodes, ...result]
: [...extraNodes, result]

nodes.forEach((node) => {
// parse results
const results = Array.isArray(result) ? [...result] : [result]
const parsedResults: Node[] = []
results.map((node) => {
const nodeType = typeResolver ? typeResolver(type, node) : type
const nodeId =
get(node, identifier) || get(node, 'id') || get(node, '_id')
Expand All @@ -71,8 +69,19 @@ export const PurgeCacheDirective = ({
return
}

parsedResults.push({ type: nodeType, id: nodeId })
})

// merge results and extras
const extraNodes: Node[] = extraNodesPath
? get(result, extraNodesPath, [])
: []
const nodes = [...extraNodes, ...parsedResults]

// invalidate
nodes.forEach((node) => {
invalidateFQC({
node: { type: nodeType, id: nodeId },
node,
redis: __redis,
})
})
Expand Down

0 comments on commit e04b624

Please sign in to comment.