Skip to content

Commit

Permalink
docs(query): make sure people use the right name (#10)
Browse files Browse the repository at this point in the history
fixes #6
  • Loading branch information
Haroenv committed Sep 28, 2018
1 parent 506f399 commit 2b47488
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $ yarn add gatsby-plugin-algolia

```js
// gatsby-config.js
const query = `{
const myQuery = `{
allSitePage {
edges {
node {
Expand All @@ -39,7 +39,7 @@ const query = `{

const queries = [
{
query,
query: myQuery,
transformer: ({ data }) => data.allSitePage.edges.map(({ node }) => node), // optional
indexName: 'index name to target', // overrides main index name, optional
},
Expand Down
6 changes: 6 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ exports.onPostBuild = async function(
query,
transformer = identity,
}) {
if (!query) {
report.panic(`failed to index to Algolia. You did not give "query" to this query`)
}
const index = client.initIndex(indexName);
const tmpIndex = client.initIndex(`${indexName}_tmp`);

await scopedCopyIndex(client, index, tmpIndex);

const result = await graphql(query);
if (result.errors) {
report.panic(`failed to index to Algolia`, result.errors);
}
const objects = transformer(result);
const chunks = chunk(objects, chunkSize);

Expand Down

0 comments on commit 2b47488

Please sign in to comment.