Skip to content

Commit

Permalink
Allow for fragments within static queries
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcaloon committed Jun 16, 2020
1 parent 8cafe81 commit c80276f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ exports.useGroqQuery = query => {

const hash = murmurhash( query );


try {
const result = require( `${process.env.GROQ_DIR}/${hash}.json` );
return result;
Expand All @@ -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 = {} ) => {

Expand All @@ -61,6 +60,8 @@ exports.runQuery = async ( rawQuery, dataset, options = {} ) => {
query = processFragments( query, fragments );
}

const queryToHash = query;

query = processJoins( query );

try {
Expand All @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"keywords": [
"gatsby"
Expand Down

0 comments on commit c80276f

Please sign in to comment.