diff --git a/gatsby-node.js b/gatsby-node.js index c575578..4f6205b 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -443,12 +443,12 @@ async function processFileStaticQueries( file, nodes, cache ) { for( let staticQuery of staticQueries ) { - const { result, finalQuery } = await runQuery( staticQuery, nodes, { file, fragments } ); + const { result, finalQuery, queryToHash } = await runQuery( staticQuery, nodes, { file, fragments } ); if( result instanceof Error ) { results.push( result ); } - const hash = hashQuery( staticQuery ); + const hash = hashQuery( queryToHash ); const json = JSON.stringify( result ); results.push( { hash, json } ); diff --git a/index.js b/index.js index 8d9c6d1..2ea2260 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,6 @@ exports.useGroqQuery = query => { const hash = murmurhash( query ); - try { const result = require( `${process.env.GROQ_DIR}/${hash}.json` ); return result; @@ -47,7 +46,7 @@ exports.useGroqQuery = query => { * @param {Object} options.fragments * @param {Object} options.params * @param {string} options.file For debugging. - * @return {Object} Array of results along with final query + * @return {Object} Array of results along with final query and query string to get hashed. */ exports.runQuery = async ( rawQuery, dataset, options = {} ) => { @@ -61,6 +60,8 @@ exports.runQuery = async ( rawQuery, dataset, options = {} ) => { query = processFragments( query, fragments ); } + const queryToHash = query; + query = processJoins( query ); try { @@ -70,7 +71,7 @@ exports.runQuery = async ( rawQuery, dataset, options = {} ) => { const value = await groq.evaluate( parsedQuery, { dataset } ); const result = await value.get(); - return { result, finalQuery: query } + return { result, finalQuery: query, queryToHash } } catch( err ) { diff --git a/package.json b/package.json index 1bee42c..5b3e715 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gatsby-plugin-groq", "description": "Gatsby plugin for using GROQ in place of GraphQL", - "version": "1.0.0-alpha.11", + "version": "1.0.0-alpha.12", "author": "Kevin McAloon ", "keywords": [ "gatsby"