gatsby 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -164,9 +164,18 @@ async function queryRunner(graphqlRunner, queryJob, parentSpan) {
|
|
|
164
164
|
const resultHash = _crypto.default.createHash(`sha1`).update(resultJSON).digest(`base64`);
|
|
165
165
|
|
|
166
166
|
const resultHashCache = getResultHashCache();
|
|
167
|
+
let resultHashCacheKey = queryJob.id;
|
|
168
|
+
|
|
169
|
+
if (queryJob.queryType === `static`) {
|
|
170
|
+
// For static queries we use hash for a file path we output results to.
|
|
171
|
+
// With automatic sort and aggregation graphql codemod it is possible
|
|
172
|
+
// to have same result, but different query text hashes which would skip
|
|
173
|
+
// writing out file to disk if we don't check query hash as well
|
|
174
|
+
resultHashCacheKey += `-${queryJob.hash}`;
|
|
175
|
+
}
|
|
167
176
|
|
|
168
|
-
if (resultHash !== (await resultHashCache.get(
|
|
169
|
-
await resultHashCache.set(
|
|
177
|
+
if (resultHash !== (await resultHashCache.get(resultHashCacheKey)) || queryJob.queryType === `page` && !(0, _pageData.pageDataExists)(_path.default.join(program.directory, `public`), queryJob.id)) {
|
|
178
|
+
await resultHashCache.set(resultHashCacheKey, resultHash);
|
|
170
179
|
|
|
171
180
|
if (queryJob.queryType === `page` || queryJob.queryType === `slice`) {
|
|
172
181
|
// We need to save this temporarily in cache because
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-runner.js","names":["resultHashCache","getResultHashCache","GatsbyCacheLmdb","name","encoding","init","reportLongRunningQueryJob","queryJob","messageParts","componentPath","isPage","path","context","push","JSON","stringify","report","warn","join","panicQueryJobError","errors","urlPath","undefined","queryContext","plugin","pluginCreatorId","queryType","structuredErrors","map","e","structuredError","errorParser","message","filePath","location","error","codeFrame","getCodeFrame","query","locations","line","column","panicOnBuild","startQueryJob","graphqlRunner","parentSpan","isPending","timeoutId","setTimeout","queryName","id","finally","clearTimeout","queryRunner","program","store","getState","dispatch","actions","queryStart","result","Object","assign","pageContext","internalComponentName","component","componentChunkName","updatedAt","pluginCreator___NODE","isCreatedByStatefulCreatePages","matchPath","mode","slices","resultJSON","resultHash","crypto","createHash","update","digest","get","pageDataExists","directory","set","savePageQueryResult","type","payload","substring","resultPath","hash","fs","outputFile","pageQueryRun","queryHash"],"sources":["../../src/query/query-runner.ts"],"sourcesContent":["import { Span } from \"opentracing\"\nimport _ from \"lodash\"\nimport fs from \"fs-extra\"\nimport report from \"gatsby-cli/lib/reporter\"\nimport crypto from \"crypto\"\nimport { ExecutionResult, GraphQLError } from \"graphql\"\n\nimport path from \"path\"\nimport { store } from \"../redux\"\nimport { actions } from \"../redux/actions\"\nimport { getCodeFrame } from \"./graphql-errors-codeframe\"\nimport errorParser from \"./error-parser\"\n\nimport { GraphQLRunner } from \"./graphql-runner\"\nimport { IExecutionResult, PageContext } from \"./types\"\nimport { pageDataExists, savePageQueryResult } from \"../utils/page-data\"\nimport GatsbyCacheLmdb from \"../utils/cache-lmdb\"\n\nlet resultHashCache: GatsbyCacheLmdb | undefined\nfunction getResultHashCache(): GatsbyCacheLmdb {\n if (!resultHashCache) {\n resultHashCache = new GatsbyCacheLmdb({\n name: `query-result-hashes`,\n encoding: `string`,\n }).init()\n }\n return resultHashCache\n}\n\nexport interface IQueryJob {\n id: string\n hash?: string\n query: string\n componentPath: string\n context: PageContext\n queryType: \"page\" | \"static\" | \"slice\"\n pluginCreatorId?: string\n}\n\nfunction reportLongRunningQueryJob(queryJob): void {\n const messageParts = [\n `This query took more than 15s to run — which is unusually long and might indicate you're querying too much or have some unoptimized code:`,\n `File path: ${queryJob.componentPath}`,\n ]\n\n if (queryJob.isPage) {\n const { path, context } = queryJob.context\n messageParts.push(`URL path: ${path}`)\n\n if (!_.isEmpty(context)) {\n messageParts.push(`Context: ${JSON.stringify(context, null, 4)}`)\n }\n }\n\n report.warn(messageParts.join(`\\n`))\n}\n\nfunction panicQueryJobError(\n queryJob: IQueryJob,\n errors: ReadonlyArray<GraphQLError>\n): void {\n let urlPath = undefined\n let queryContext = {}\n const plugin = queryJob.pluginCreatorId || `none`\n\n if (queryJob.queryType === `page`) {\n urlPath = queryJob.context.path\n queryContext = queryJob.context.context\n }\n\n const structuredErrors = errors.map(e => {\n const structuredError = errorParser({\n message: e.message,\n filePath: undefined,\n location: undefined,\n error: e,\n })\n\n structuredError.context = {\n ...structuredError.context,\n codeFrame: getCodeFrame(\n queryJob.query,\n e.locations && e.locations[0].line,\n e.locations && e.locations[0].column\n ),\n filePath: queryJob.componentPath,\n ...(urlPath ? { urlPath } : {}),\n ...queryContext,\n plugin,\n }\n\n return structuredError\n })\n\n report.panicOnBuild(structuredErrors)\n}\n\nasync function startQueryJob(\n graphqlRunner: GraphQLRunner,\n queryJob: IQueryJob,\n parentSpan: Span | undefined\n): Promise<ExecutionResult> {\n let isPending = true\n\n // Print out warning when query takes too long\n const timeoutId = setTimeout(() => {\n if (isPending) {\n reportLongRunningQueryJob(queryJob)\n }\n }, 15000)\n\n return graphqlRunner\n .query(queryJob.query, queryJob.context, {\n parentSpan,\n queryName: queryJob.id,\n componentPath: queryJob.componentPath,\n })\n .finally(() => {\n isPending = false\n clearTimeout(timeoutId)\n })\n}\n\nexport async function queryRunner(\n graphqlRunner: GraphQLRunner,\n queryJob: IQueryJob,\n parentSpan: Span | undefined\n): Promise<IExecutionResult> {\n const { program } = store.getState()\n\n store.dispatch(\n actions.queryStart({\n path: queryJob.id,\n componentPath: queryJob.componentPath,\n isPage: queryJob.queryType === `page`,\n })\n )\n\n // Run query\n let result: IExecutionResult\n // Nothing to do if the query doesn't exist.\n if (!queryJob.query || queryJob.query === ``) {\n result = {}\n } else {\n result = await startQueryJob(graphqlRunner, queryJob, parentSpan)\n }\n\n if (result.errors) {\n // If there's a graphql error then log the error and exit\n panicQueryJobError(queryJob, result.errors)\n }\n\n // Add the page/slice context onto the results.\n if (queryJob) {\n if (queryJob.queryType === `page`) {\n result[`pageContext`] = Object.assign({}, queryJob.context)\n } else if (queryJob.queryType === `slice`) {\n result[`sliceContext`] = Object.assign({}, queryJob.context)\n }\n }\n\n // Delete internal data from pageContext\n if (result.pageContext) {\n delete result.pageContext.path\n delete result.pageContext.internalComponentName\n delete result.pageContext.component\n delete result.pageContext.componentChunkName\n delete result.pageContext.updatedAt\n delete result.pageContext.pluginCreator___NODE\n delete result.pageContext.pluginCreatorId\n delete result.pageContext.componentPath\n delete result.pageContext.context\n delete result.pageContext.isCreatedByStatefulCreatePages\n delete result.pageContext.matchPath\n delete result.pageContext.mode\n delete result.pageContext.slices\n }\n\n const resultJSON = JSON.stringify(result)\n const resultHash = crypto\n .createHash(`sha1`)\n .update(resultJSON)\n .digest(`base64`)\n\n const resultHashCache = getResultHashCache()\n if (\n resultHash !== (await resultHashCache.get(queryJob.id)) ||\n (queryJob.queryType === `page` &&\n !pageDataExists(path.join(program.directory, `public`), queryJob.id))\n ) {\n await resultHashCache.set(queryJob.id, resultHash)\n\n if (queryJob.queryType === `page` || queryJob.queryType === `slice`) {\n // We need to save this temporarily in cache because\n // this might be incomplete at the moment\n await savePageQueryResult(queryJob.id, resultJSON)\n if (queryJob.queryType === `page`) {\n store.dispatch({\n type: `ADD_PENDING_PAGE_DATA_WRITE`,\n payload: {\n path: queryJob.id,\n },\n })\n } else if (queryJob.queryType === `slice`) {\n store.dispatch({\n type: `ADD_PENDING_SLICE_DATA_WRITE`,\n payload: {\n name: queryJob.id.substring(7), // remove \"slice--\" prefix\n },\n })\n }\n } else if (queryJob.queryType === `static`) {\n const resultPath = path.join(\n program.directory,\n `public`,\n `page-data`,\n `sq`,\n `d`,\n `${queryJob.hash}.json`\n )\n await fs.outputFile(resultPath, resultJSON)\n }\n }\n\n // Broadcast that a page's query has run.\n store.dispatch(\n actions.pageQueryRun({\n path: queryJob.id,\n componentPath: queryJob.componentPath,\n queryType: queryJob.queryType,\n resultHash,\n queryHash: queryJob.hash,\n })\n )\n\n return result\n}\n"],"mappings":";;;;;;;;;AAEA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AAErF,QAAQ,CAACiF;EALD,CAArB,CADF;;EAUA,OAAO5B,MAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"query-runner.js","names":["resultHashCache","getResultHashCache","GatsbyCacheLmdb","name","encoding","init","reportLongRunningQueryJob","queryJob","messageParts","componentPath","isPage","path","context","push","JSON","stringify","report","warn","join","panicQueryJobError","errors","urlPath","undefined","queryContext","plugin","pluginCreatorId","queryType","structuredErrors","map","e","structuredError","errorParser","message","filePath","location","error","codeFrame","getCodeFrame","query","locations","line","column","panicOnBuild","startQueryJob","graphqlRunner","parentSpan","isPending","timeoutId","setTimeout","queryName","id","finally","clearTimeout","queryRunner","program","store","getState","dispatch","actions","queryStart","result","Object","assign","pageContext","internalComponentName","component","componentChunkName","updatedAt","pluginCreator___NODE","isCreatedByStatefulCreatePages","matchPath","mode","slices","resultJSON","resultHash","crypto","createHash","update","digest","resultHashCacheKey","hash","get","pageDataExists","directory","set","savePageQueryResult","type","payload","substring","resultPath","fs","outputFile","pageQueryRun","queryHash"],"sources":["../../src/query/query-runner.ts"],"sourcesContent":["import { Span } from \"opentracing\"\nimport _ from \"lodash\"\nimport fs from \"fs-extra\"\nimport report from \"gatsby-cli/lib/reporter\"\nimport crypto from \"crypto\"\nimport { ExecutionResult, GraphQLError } from \"graphql\"\n\nimport path from \"path\"\nimport { store } from \"../redux\"\nimport { actions } from \"../redux/actions\"\nimport { getCodeFrame } from \"./graphql-errors-codeframe\"\nimport errorParser from \"./error-parser\"\n\nimport { GraphQLRunner } from \"./graphql-runner\"\nimport { IExecutionResult, PageContext } from \"./types\"\nimport { pageDataExists, savePageQueryResult } from \"../utils/page-data\"\nimport GatsbyCacheLmdb from \"../utils/cache-lmdb\"\n\nlet resultHashCache: GatsbyCacheLmdb | undefined\nfunction getResultHashCache(): GatsbyCacheLmdb {\n if (!resultHashCache) {\n resultHashCache = new GatsbyCacheLmdb({\n name: `query-result-hashes`,\n encoding: `string`,\n }).init()\n }\n return resultHashCache\n}\n\nexport interface IQueryJob {\n id: string\n hash?: string\n query: string\n componentPath: string\n context: PageContext\n queryType: \"page\" | \"static\" | \"slice\"\n pluginCreatorId?: string\n}\n\nfunction reportLongRunningQueryJob(queryJob): void {\n const messageParts = [\n `This query took more than 15s to run — which is unusually long and might indicate you're querying too much or have some unoptimized code:`,\n `File path: ${queryJob.componentPath}`,\n ]\n\n if (queryJob.isPage) {\n const { path, context } = queryJob.context\n messageParts.push(`URL path: ${path}`)\n\n if (!_.isEmpty(context)) {\n messageParts.push(`Context: ${JSON.stringify(context, null, 4)}`)\n }\n }\n\n report.warn(messageParts.join(`\\n`))\n}\n\nfunction panicQueryJobError(\n queryJob: IQueryJob,\n errors: ReadonlyArray<GraphQLError>\n): void {\n let urlPath = undefined\n let queryContext = {}\n const plugin = queryJob.pluginCreatorId || `none`\n\n if (queryJob.queryType === `page`) {\n urlPath = queryJob.context.path\n queryContext = queryJob.context.context\n }\n\n const structuredErrors = errors.map(e => {\n const structuredError = errorParser({\n message: e.message,\n filePath: undefined,\n location: undefined,\n error: e,\n })\n\n structuredError.context = {\n ...structuredError.context,\n codeFrame: getCodeFrame(\n queryJob.query,\n e.locations && e.locations[0].line,\n e.locations && e.locations[0].column\n ),\n filePath: queryJob.componentPath,\n ...(urlPath ? { urlPath } : {}),\n ...queryContext,\n plugin,\n }\n\n return structuredError\n })\n\n report.panicOnBuild(structuredErrors)\n}\n\nasync function startQueryJob(\n graphqlRunner: GraphQLRunner,\n queryJob: IQueryJob,\n parentSpan: Span | undefined\n): Promise<ExecutionResult> {\n let isPending = true\n\n // Print out warning when query takes too long\n const timeoutId = setTimeout(() => {\n if (isPending) {\n reportLongRunningQueryJob(queryJob)\n }\n }, 15000)\n\n return graphqlRunner\n .query(queryJob.query, queryJob.context, {\n parentSpan,\n queryName: queryJob.id,\n componentPath: queryJob.componentPath,\n })\n .finally(() => {\n isPending = false\n clearTimeout(timeoutId)\n })\n}\n\nexport async function queryRunner(\n graphqlRunner: GraphQLRunner,\n queryJob: IQueryJob,\n parentSpan: Span | undefined\n): Promise<IExecutionResult> {\n const { program } = store.getState()\n\n store.dispatch(\n actions.queryStart({\n path: queryJob.id,\n componentPath: queryJob.componentPath,\n isPage: queryJob.queryType === `page`,\n })\n )\n\n // Run query\n let result: IExecutionResult\n // Nothing to do if the query doesn't exist.\n if (!queryJob.query || queryJob.query === ``) {\n result = {}\n } else {\n result = await startQueryJob(graphqlRunner, queryJob, parentSpan)\n }\n\n if (result.errors) {\n // If there's a graphql error then log the error and exit\n panicQueryJobError(queryJob, result.errors)\n }\n\n // Add the page/slice context onto the results.\n if (queryJob) {\n if (queryJob.queryType === `page`) {\n result[`pageContext`] = Object.assign({}, queryJob.context)\n } else if (queryJob.queryType === `slice`) {\n result[`sliceContext`] = Object.assign({}, queryJob.context)\n }\n }\n\n // Delete internal data from pageContext\n if (result.pageContext) {\n delete result.pageContext.path\n delete result.pageContext.internalComponentName\n delete result.pageContext.component\n delete result.pageContext.componentChunkName\n delete result.pageContext.updatedAt\n delete result.pageContext.pluginCreator___NODE\n delete result.pageContext.pluginCreatorId\n delete result.pageContext.componentPath\n delete result.pageContext.context\n delete result.pageContext.isCreatedByStatefulCreatePages\n delete result.pageContext.matchPath\n delete result.pageContext.mode\n delete result.pageContext.slices\n }\n\n const resultJSON = JSON.stringify(result)\n const resultHash = crypto\n .createHash(`sha1`)\n .update(resultJSON)\n .digest(`base64`)\n\n const resultHashCache = getResultHashCache()\n\n let resultHashCacheKey = queryJob.id\n if (queryJob.queryType === `static`) {\n // For static queries we use hash for a file path we output results to.\n // With automatic sort and aggregation graphql codemod it is possible\n // to have same result, but different query text hashes which would skip\n // writing out file to disk if we don't check query hash as well\n resultHashCacheKey += `-${queryJob.hash}`\n }\n\n if (\n resultHash !== (await resultHashCache.get(resultHashCacheKey)) ||\n (queryJob.queryType === `page` &&\n !pageDataExists(path.join(program.directory, `public`), queryJob.id))\n ) {\n await resultHashCache.set(resultHashCacheKey, resultHash)\n\n if (queryJob.queryType === `page` || queryJob.queryType === `slice`) {\n // We need to save this temporarily in cache because\n // this might be incomplete at the moment\n await savePageQueryResult(queryJob.id, resultJSON)\n if (queryJob.queryType === `page`) {\n store.dispatch({\n type: `ADD_PENDING_PAGE_DATA_WRITE`,\n payload: {\n path: queryJob.id,\n },\n })\n } else if (queryJob.queryType === `slice`) {\n store.dispatch({\n type: `ADD_PENDING_SLICE_DATA_WRITE`,\n payload: {\n name: queryJob.id.substring(7), // remove \"slice--\" prefix\n },\n })\n }\n } else if (queryJob.queryType === `static`) {\n const resultPath = path.join(\n program.directory,\n `public`,\n `page-data`,\n `sq`,\n `d`,\n `${queryJob.hash}.json`\n )\n await fs.outputFile(resultPath, resultJSON)\n }\n }\n\n // Broadcast that a page's query has run.\n store.dispatch(\n actions.pageQueryRun({\n path: queryJob.id,\n componentPath: queryJob.componentPath,\n queryType: queryJob.queryType,\n resultHash,\n queryHash: queryJob.hash,\n })\n )\n\n return result\n}\n"],"mappings":";;;;;;;;;AAEA;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAIA;;AACA;;AAEA,IAAIA,eAAJ;;AACA,SAASC,kBAAT,GAA+C;EAC7C,IAAI,CAACD,eAAL,EAAsB;IACpBA,eAAe,GAAG,IAAIE,kBAAJ,CAAoB;MACpCC,IAAI,EAAG,qBAD6B;MAEpCC,QAAQ,EAAG;IAFyB,CAApB,EAGfC,IAHe,EAAlB;EAID;;EACD,OAAOL,eAAP;AACD;;AAYD,SAASM,yBAAT,CAAmCC,QAAnC,EAAmD;EACjD,MAAMC,YAAY,GAAG,CAClB,2IADkB,EAElB,cAAaD,QAAQ,CAACE,aAAc,EAFlB,CAArB;;EAKA,IAAIF,QAAQ,CAACG,MAAb,EAAqB;IACnB,MAAM;MAAEC,IAAF;MAAQC;IAAR,IAAoBL,QAAQ,CAACK,OAAnC;IACAJ,YAAY,CAACK,IAAb,CAAmB,aAAYF,IAAK,EAApC;;IAEA,IAAI,CAAC,uBAAUC,OAAV,CAAL,EAAyB;M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;QACzC6B,YAAA,CAAME,QAAN,CAAe;UACb6B,IAAI,EAAG,8BADM;UAEbC,OAAO,EAAE;YACPpF,IAAI,EAAEI,QAAQ,CAAC2C,EAAT,CAAYsC,SAAZ,CAAsB,CAAtB,CADC,CACyB;;UADzB;QAFI,CAAf;MAMD;IACF,CAnBD,MAmBO,IAAIjF,QAAQ,CAACmB,SAAT,KAAwB,QAA5B,EAAqC;MAC1C,MAAM+D,UAAU,GAAG9E,aAAA,CAAKO,IAAL,CACjBoC,OAAO,CAAC6B,SADS,EAEhB,QAFgB,EAGhB,WAHgB,EAIhB,IAJgB,EAKhB,GALgB,EAMhB,GAAE5E,QAAQ,CAACyE,IAAK,OANA,CAAnB;;MAQA,MAAMU,gBAAA,CAAGC,UAAH,CAAcF,UAAd,EAA0BhB,UAA1B,CAAN;IACD;EACF,CAzG0B,CA2G3B;;;EACAlB,YAAA,CAAME,QAAN,CACEC,gBAAA,CAAQkC,YAAR,CAAqB;IACnBjF,IAAI,EAAEJ,QAAQ,CAAC2C,EADI;IAEnBzC,aAAa,EAAEF,QAAQ,CAACE,aAFL;IAGnBiB,SAAS,EAAEnB,QAAQ,CAACmB,SAHD;IAInBgD,UAJmB;IAKnBmB,SAAS,EAAEtF,QAAQ,CAACyE;EALD,CAArB,CADF;;EAUA,OAAOpB,MAAP;AACD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby",
|
|
3
3
|
"description": "Blazing fast modern site generator for React",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.1",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"bin": {
|
|
7
7
|
"gatsby": "./cli.js"
|
|
@@ -277,5 +277,5 @@
|
|
|
277
277
|
"yargs": {
|
|
278
278
|
"boolean-negation": false
|
|
279
279
|
},
|
|
280
|
-
"gitHead": "
|
|
280
|
+
"gitHead": "3007cd39c045ba0a1069a03f8ba343cc7af6ed69"
|
|
281
281
|
}
|