Skip to content

Commit

Permalink
fix(gatsby): write out sq files when result doesn't change but query …
Browse files Browse the repository at this point in the history
…hash changes (#36997)

Co-authored-by: Lennart <[email protected]>
  • Loading branch information
pieh and LekoArts authored Nov 9, 2022
1 parent b93564a commit 3e87026
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/gatsby/src/query/query-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,22 @@ export async function queryRunner(
.digest(`base64`)

const resultHashCache = getResultHashCache()

let resultHashCacheKey = queryJob.id
if (queryJob.queryType === `static`) {
// For static queries we use hash for a file path we output results to.
// With automatic sort and aggregation graphql codemod it is possible
// to have same result, but different query text hashes which would skip
// writing out file to disk if we don't check query hash as well
resultHashCacheKey += `-${queryJob.hash}`
}

if (
resultHash !== (await resultHashCache.get(queryJob.id)) ||
resultHash !== (await resultHashCache.get(resultHashCacheKey)) ||
(queryJob.queryType === `page` &&
!pageDataExists(path.join(program.directory, `public`), queryJob.id))
) {
await resultHashCache.set(queryJob.id, resultHash)
await resultHashCache.set(resultHashCacheKey, resultHash)

if (queryJob.queryType === `page` || queryJob.queryType === `slice`) {
// We need to save this temporarily in cache because
Expand Down

0 comments on commit 3e87026

Please sign in to comment.