Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1648294
Update README.md
meili-bot Jun 9, 2022
2b55301
Update meilisearch-js to v0.27.0-beta0 for v0.28.0
bidoubiwa Jul 6, 2022
8fd466d
Merge pull request #145 from meilisearch/update_meilisearch_dependencies
bidoubiwa Jul 6, 2022
92b73b9
Update the meilisearch api with changes of v0.28.0
bidoubiwa Jul 6, 2022
c8ba723
Pass client agent to meilisearch-js
bidoubiwa Jul 7, 2022
ee06198
Merge pull request #146 from meilisearch/fix_api_changes_v0.28.0
bidoubiwa Jul 7, 2022
baf9431
Merge pull request #147 from meilisearch/add_user_agent_in_client
bidoubiwa Jul 7, 2022
b3d80c0
Merge branch 'main' of https://github.com/meilisearch/gatsby-plugin-m…
bidoubiwa Jul 11, 2022
ad7aee0
Update meilisearch-js to v0.27.0
bidoubiwa Jul 11, 2022
ce83b36
Merge pull request #153 from meilisearch/update_meilisearch_js_to_v0.…
bidoubiwa Jul 12, 2022
d291710
Fix variable naming using instantmeilisearch in agent method
bidoubiwa Jul 12, 2022
3fdefb1
Merge branch 'bump-meilisearch-v0.28.0' of https://github.com/meilise…
bidoubiwa Jul 12, 2022
4d18256
Update instant-meilisearch in playground to v0.8.0
bidoubiwa Jul 12, 2022
20c8a32
Merge pull request #154 from meilisearch/update_instant_meilisearch_t…
bidoubiwa Jul 12, 2022
a6fb0df
Update github actions versions
bidoubiwa Jul 19, 2022
eee51cc
Add missing file in package.json
bidoubiwa Jul 19, 2022
13517f1
Rollback cypress CI
bidoubiwa Jul 19, 2022
82d61b2
Add missing file
bidoubiwa Jul 19, 2022
45fa73b
Merge branch 'bump-meilisearch-v0.28.0' of github.com:meilisearch/gat…
bidoubiwa Jul 19, 2022
58ae985
Update cypress CI
bidoubiwa Jul 19, 2022
d4d3f8a
Add a sleep between server start and tests in CI
bidoubiwa Jul 19, 2022
086e3b2
Merge pull request #158 from meilisearch/update_github_actions
bidoubiwa Jul 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ Full usage example:

**Supported Meilisearch versions**:

This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).
This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0).

**Node / NPM versions**:

Expand Down
15 changes: 9 additions & 6 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { MeiliSearch } = require('meilisearch')

const { constructClientAgents } = require('./src/agents')
const {
validatePluginOptions,
validateIndexOptions,
Expand Down Expand Up @@ -27,6 +27,7 @@ exports.onPostBuild = async function ({ graphql, reporter }, config) {
skipIndexing = false,
batchSize = 1000,
indexes,
clientAgents = [],
} = config

if (skipIndexing) {
Expand Down Expand Up @@ -59,14 +60,15 @@ exports.onPostBuild = async function ({ graphql, reporter }, config) {
const client = new MeiliSearch({
host: host,
apiKey: apiKey,
clientAgents: constructClientAgents(clientAgents),
})

const index = client.index(currentIndex.indexUid)
await index.delete()

// Add settings to Index
if (currentIndex.settings) {
const { uid: settingsUid } = await index.updateSettings(
const { taskUid: settingsUid } = await index.updateSettings(
currentIndex.settings
)
index.waitForTask(settingsUid)
Expand All @@ -89,10 +91,11 @@ exports.onPostBuild = async function ({ graphql, reporter }, config) {

// Wait for indexation to be completed
for (const enqueuedUpdate of enqueuedUpdates) {
await index.waitForTask(enqueuedUpdate.uid)
const res = await index.getTask(enqueuedUpdate.uid)
if (res.status === 'failed') {
throw getErrorMsg(`${res.error.message} (${res.error.code})`)
await index.waitForTask(enqueuedUpdate.taskUid)
const task = await index.getTask(enqueuedUpdate.taskUid)

if (task.status === 'failed') {
throw getErrorMsg(`${task.error?.message} (${task.error?.code})`)
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@
"wait-port": "^0.2.9"
},
"dependencies": {
"meilisearch": "^0.25.1"
"meilisearch": "^0.27.0"
}
}
11 changes: 11 additions & 0 deletions src/agents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { version } = require('../package.json')

const constructClientAgents = (clientAgents = []) => {
const instantMeilisearchAgent = `Meilisearch Gatsby (v${version})`

return clientAgents.concat(instantMeilisearchAgent)
}

module.exports = {
constructClientAgents,
}
29 changes: 15 additions & 14 deletions tests/index-to-meilisearch.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* eslint-disable no-undef */
const { MeiliSearch } = require('meilisearch')
const { onPostBuild } = require('../gatsby-node.js')
const { fakeConfig, fakeGraphql, fakeReporter } = require('./utils')
const {
fakeConfig,
fakeGraphql,
fakeReporter,
clearAllIndexes,
} = require('./utils')

const activity = fakeReporter.activityTimer()

Expand All @@ -12,15 +17,10 @@ const client = new MeiliSearch({

describe('Index to Meilisearch', () => {
beforeEach(async () => {
try {
await Promise.all(
fakeConfig.indexes.map(
async index => await client.deleteIndex(index.indexUid)
)
)
} catch (e) {
return
}
return clearAllIndexes({
host: fakeConfig.host,
apiKey: fakeConfig.apiKey,
})
})

test('Should fail if the indexes field is not provided', async () => {
Expand Down Expand Up @@ -205,8 +205,9 @@ describe('Index to Meilisearch', () => {
],
}
)
const indexes = await client.getIndexes()
expect(indexes).toHaveLength(2)
const { results } = await client.getIndexes()

expect(results).toHaveLength(2)
})

test('Should delete index and recreate a new one', async () => {
Expand Down Expand Up @@ -252,7 +253,7 @@ describe('Index to Meilisearch', () => {
.index(fakeConfig.indexes[0].indexUid)
.search('Axolotl')

expect(firstQueryResult.nbHits).toBe(1)
expect(firstQueryResult.estimatedTotalHits).toBe(1)

await onPostBuild(
{ graphql: fakeGraphql, reporter: fakeReporter },
Expand All @@ -271,7 +272,7 @@ describe('Index to Meilisearch', () => {
.index(fakeConfig.indexes[0].indexUid)
.search('Axolotl')

expect(secondQueryResult.nbHits).toBe(0)
expect(secondQueryResult.estimatedTotalHits).toBe(0)
})

test('Should succeed and index with good config format', async () => {
Expand Down
16 changes: 16 additions & 0 deletions tests/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-undef */
const { MeiliSearch } = require('meilisearch')

const fakeConfig = {
host: process.env.MEILI_HTTP_ADDR || 'http://localhost:7700',
Expand Down Expand Up @@ -54,8 +55,23 @@ const fakeReporter = {
error: jest.fn(() => {}),
}

const clearAllIndexes = async config => {
const client = new MeiliSearch(config)

const { results } = await client.getRawIndexes()
const indexes = results.map(elem => elem.uid)

const taskIds = []
for (const indexUid of indexes) {
const { taskUid } = await client.index(indexUid).delete()
taskIds.push(taskUid)
}
await client.waitForTasks(taskIds)
}

module.exports = {
fakeConfig,
fakeGraphql,
clearAllIndexes,
fakeReporter,
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9387,10 +9387,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
integrity sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=

meilisearch@^0.25.1:
version "0.25.1"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.25.1.tgz#0dc25ffad64e6e50eb3da6c0691b0ff54f8578bf"
integrity sha512-20jO0pK9BhghxHSkOLbdoYn58h/Z0PNL3JQcRq7ipNIeqrxkAetCZZ6ttJC3uxcz0jVglmiFoSXu3Z/lEOLOLQ==
meilisearch@^0.27.0:
version "0.27.0"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.27.0.tgz#8bd57ddb77b975f93e054cb977b951c488ece297"
integrity sha512-kZOZFIuSO7c6xRf+Y2/9/h6A9pl0sCl/G44X4KuaSwxGbruOZPhmxbeVEgLHBv4pUFvQ56rNVTA/2d/5GCU1YA==
dependencies:
cross-fetch "^3.1.5"

Expand Down