Comments (10)
I've now got this working. The suggestion to make a repo was a very good one! It worked out of the box. So i've tried to step back though the settings I had originally to find the problem.
By adding an id
into the graphQL it worked, this was the only issue.
In the example up top I am only getting a single field, displayName
- effectively the title
. It seems Algolia needs an id
.
This makes some sense, but perhaps a more useful error can be produced if this happens? Also if there's some advanced way of debugging this that would be helpful.
I've created a repo here that works perfectly with Sanity and Algolia, you can reproduce the error using this and following the instructions below:
https://github.com/amcc/gatsby-sanity-algolia
By removing id
from web/gatsby-config.js (line 16) you'll see the error. You'll have to add credentials for a Sanity blog (you need the Sanity project id), plus the Algolia credentials of course.
from gatsby-plugin-algolia.
@Haroenv yep that's my quandary too! I'm making a repo now to try to replicate and share. I was wondering whether there were any fundamental problems with my code. I'll post the repo asap
from gatsby-plugin-algolia.
I had a very similar issue that took me a few days to finally resolve. Mine was a tad more complex in that I was breaking my GraphQL results down into small chunks. Algolia was deduplicating those chunks because I was passing the same ID (many Algolia records for my one record). I had to append the index
to my ID
in order to give Algolia a unique ID.
const chunkBlocks = input => {
return input.map(({ node: { slug, _rawBody, id, ...rest } }) => {
return _rawBody.map((body, index) => {
const bodyContent = extractContent(body)
const objectID = id + index
return {type: "page", objectID, ...slug, bodyContent, ...rest}
})
}).flat()
}
I agree that it could be called out more clearly that each record requires a unique ID that we are responsible for sending. Hopefully this post saves someone else the trouble.
from gatsby-plugin-algolia.
I came across the same issue again yesterday, on a different project, found my own issue and remembered the fix!
from gatsby-plugin-algolia.
These logs don't seem to point to a specific problem or line with the error. Could you make this reproducible in a GitHub project please?
from gatsby-plugin-algolia.
Interesting, I expect there to be a clear error in that case "id or objectID required", do you see that now or was it swallowed by something?
from gatsby-plugin-algolia.
I think its getting swallowed, or not there, here's the output from the basic sanity site i made:
...
success Building static HTML for pages - 1.668 s — 9/9 43.51 pages/second
Algolia: 1 queries to index
Algolia: query 0: executing query
lerna ERR! npm run build stderr:
error failed to index to Algolia. Query results do not have 'objectID' or 'id' key
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `gatsby build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/alistairmcclymont/.npm/_logs/2020-05-06T09_47_49_965Z-debug.log
lerna ERR! npm run build exited 1 in 'sanity-gatsby-blog-web'
lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `lerna run build --parallel`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/alistairmcclymont/.npm/_logs/2020-05-06T09_47_50_057Z-debug.log
The terminal process terminated with exit code: 1
here's the second log referenced in the terminal output above, the two logs are identical (except one references the web directory - sanity uses a monorepo with a sanity directory and a web directory for Gatsby):
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli '/Users/alistairmcclymont/.nvm/versions/node/v13.13.0/bin/node',
1 verbose cli '/Users/alistairmcclymont/.nvm/versions/node/v13.13.0/bin/npm',
1 verbose cli 'run',
1 verbose cli 'build'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 info lifecycle [email protected]~build: [email protected]
7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~build: PATH: /Users/alistairmcclymont/.nvm/versions/node/v13.13.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/alistairmcclymont/Sites/RCA/test/gatsby-sanity-algolia/web/node_modules/.bin:/Users/alistairmcclymont/Sites/RCA/test/gatsby-sanity-algolia/web/node_modules/.bin:/Users/alistairmcclymont/Sites/RCA/test/gatsby-sanity-algolia/node_modules/.bin:/Users/alistairmcclymont/Sites/RCA/test/node_modules/.bin:/Users/alistairmcclymont/Sites/RCA/node_modules/.bin:/Users/alistairmcclymont/Sites/node_modules/.bin:/Users/alistairmcclymont/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/alistairmcclymont/.nvm/versions/node/v13.13.0/bin:/Users/alistairmcclymont/.nvm/versions/node/v13.13.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/alistairmcclymont/Sites/RCA/test/gatsby-sanity-algolia/node_modules/.bin:/Users/alistairmcclymont/.nvm/versions/node/v13.13.0/bin:/Applications/MAMP/bin/php/php7.1.8/bin:/Applications/MAMP/Library/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/local/bin
9 verbose lifecycle [email protected]~build: CWD: /Users/alistairmcclymont/Sites/RCA/test/gatsby-sanity-algolia/web
10 silly lifecycle [email protected]~build: Args: [ '-c', 'gatsby build' ]
11 silly lifecycle [email protected]~build: Returned: code: 1 signal: null
12 info lifecycle [email protected]~build: Failed to exec build script
13 verbose stack Error: [email protected] build: `gatsby build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/Users/alistairmcclymont/.nvm/versions/node/v13.13.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:315:20)
13 verbose stack at ChildProcess.<anonymous> (/Users/alistairmcclymont/.nvm/versions/node/v13.13.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:315:20)
13 verbose stack at maybeClose (internal/child_process.js:1026:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid [email protected]
15 verbose cwd /Users/alistairmcclymont/Sites/RCA/test/gatsby-sanity-algolia/web
16 verbose Darwin 19.4.0
17 verbose argv "/Users/alistairmcclymont/.nvm/versions/node/v13.13.0/bin/node" "/Users/alistairmcclymont/.nvm/versions/node/v13.13.0/bin/npm" "run" "build"
18 verbose node v13.13.0
19 verbose npm v6.14.4
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] build: `gatsby build`
22 error Exit status 1
23 error Failed at the [email protected] build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
from gatsby-plugin-algolia.
Here's a working version from a basic repo:
https://github.com/amcc/gatsby-sanity-algolia
The issue was leaving out the id
from the graphql
from gatsby-plugin-algolia.
I'm going to reopen this so I can investigate why the error wasn't shown later. Glad you found your solution though!
from gatsby-plugin-algolia.
I agree a better error should be shown here. Either the error from Algolia could be shown again, or we can do an isUnique on the objectIds before sending. Open for contributions here!
from gatsby-plugin-algolia.
Related Issues (20)
- Question re: Algolia Search HOT 6
- Unreachable hosts Error HOT 6
- Algolia transformer returns nulls for images that are correctly displayed in built site HOT 1
- Support for Gatsby 5 HOT 2
- Gatsby 4 build broken gatsby-plugin-algolia v1.0.0 HOT 2
- failed to index to Algolia Cannot read properties of undefined (reading 'contentDigest') HOT 3
- Plugin breaking in Gatsby 5 HOT 5
- JavaScript heap out of memory HOT 5
- Add indexName to the gatsby cache key HOT 4
- Why partial partial update is no more optional ? HOT 6
- Enrich your records with Google Analytics data HOT 1
- Request for skipIndexing Option to Avoid Unwanted API Access During CI Builds HOT 2
- Extracting chunks of long text as its own record HOT 2
- Adding headers to graphql query HOT 3
- Error: cannot apply the batch operation on a replica index
- Plugin is deleting Sanity document from index if edited. HOT 3
- Adding new data to existing records is ignored HOT 3
- Gatsby internal.contentDigest is a poor source for deciding whether content needs to be updated HOT 6
- Do we still need the MatchFields and enablePartialUpdate options in config? HOT 2
- Partially update not updating existing object in index HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gatsby-plugin-algolia.