Skip to content

Commit 3ca240f

Browse files
parkerduckworthaliszka
authored andcommitted
support gql get consistency level
1 parent 73db7a5 commit 3ca240f

File tree

5 files changed

+177
-2
lines changed

5 files changed

+177
-2
lines changed

ci/compose.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ function compose_down_all {
1919
}
2020

2121
function all_weaviate_ports {
22-
echo "8080 8081 8082 8083 8085 8086"
22+
echo "8080 8081 8082 8083 8085 8086 8087 8088"
2323
}

ci/docker-compose-cluster.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
version: '3.4'
3+
services:
4+
weaviate-node-1:
5+
image: semitechnologies/weaviate:preview-gql-handler-consistency-level-integration-4a12f55
6+
restart: on-failure:0
7+
ports:
8+
- "8087:8080"
9+
environment:
10+
CONTEXTIONARY_URL: contextionary:9999
11+
QUERY_DEFAULTS_LIMIT: 20
12+
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
13+
PERSISTENCE_DATA_PATH: "./weaviate-node-1"
14+
DEFAULT_VECTORIZER_MODULE: text2vec-contextionary
15+
ENABLE_MODULES: text2vec-contextionary
16+
CLUSTER_GOSSIP_BIND_PORT: "7110"
17+
CLUSTER_DATA_BIND_PORT: "7111"
18+
19+
contextionary:
20+
image: semitechnologies/contextionary:en0.16.0-v1.2.0
21+
ports:
22+
- "9797:9999"
23+
environment:
24+
OCCURRENCE_WEIGHT_LINEAR_FACTOR: 0.75
25+
EXTENSIONS_STORAGE_MODE: weaviate
26+
EXTENSIONS_STORAGE_ORIGIN: http://weaviate:8080
27+
NEIGHBOR_OCCURRENCE_IGNORE_PERCENTILE: 5
28+
ENABLE_COMPOUND_SPLITTING: 'false'
29+
30+
weaviate-node-2:
31+
init: true
32+
command:
33+
- --host
34+
- 0.0.0.0
35+
- --port
36+
- '8080'
37+
- --scheme
38+
- http
39+
image: semitechnologies/weaviate:preview-gql-handler-consistency-level-integration-4a12f55
40+
ports:
41+
- 8088:8080
42+
- 6061:6060
43+
restart: on-failure:0
44+
environment:
45+
CONTEXTIONARY_URL: contextionary:9999
46+
LOG_LEVEL: 'debug'
47+
QUERY_DEFAULTS_LIMIT: 20
48+
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
49+
PERSISTENCE_DATA_PATH: './weaviate-node-2'
50+
DEFAULT_VECTORIZER_MODULE: text2vec-contextionary
51+
ENABLE_MODULES: text2vec-contextionary
52+
CLUSTER_HOSTNAME: 'node2'
53+
CLUSTER_GOSSIP_BIND_PORT: '7112'
54+
CLUSTER_DATA_BIND_PORT: '7113'
55+
CLUSTER_JOIN: 'weaviate-node-1:7110'
56+
...

src/graphql/getter.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,44 @@ test('a simple query with a group', () => {
7575
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
7676
});
7777

78+
describe('query with consistency level', () => {
79+
test('One', () => {
80+
const mockClient: any = {
81+
query: jest.fn(),
82+
};
83+
84+
const expectedQuery = `{Get{Person(consistencyLevel:ONE){name}}}`;
85+
86+
new Getter(mockClient).withClassName('Person').withFields('name').withConsistencyLevel('ONE').do();
87+
88+
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
89+
});
90+
91+
test('Quorum', () => {
92+
const mockClient: any = {
93+
query: jest.fn(),
94+
};
95+
96+
const expectedQuery = `{Get{Person(consistencyLevel:QUORUM){name}}}`;
97+
98+
new Getter(mockClient).withClassName('Person').withFields('name').withConsistencyLevel('QUORUM').do();
99+
100+
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
101+
});
102+
103+
test('All', () => {
104+
const mockClient: any = {
105+
query: jest.fn(),
106+
};
107+
108+
const expectedQuery = `{Get{Person(consistencyLevel:ALL){name}}}`;
109+
110+
new Getter(mockClient).withClassName('Person').withFields('name').withConsistencyLevel('ALL').do();
111+
112+
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
113+
});
114+
});
115+
78116
describe('where filters', () => {
79117
test('a query with a valid where filter', () => {
80118
const mockClient: any = {

src/graphql/getter.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Connection from '../connection';
1212
import { CommandBase } from '../validation/commandBase';
1313
import { WhereFilter } from '../openapi/types';
1414
import { GenerateArgs, GraphQLGenerate } from './generate';
15+
import { ConsistencyLevel } from '../data';
1516

1617
export default class GraphQLGetter extends CommandBase {
1718
private after?: string;
@@ -31,6 +32,7 @@ export default class GraphQLGetter extends CommandBase {
3132
private sortString?: string;
3233
private whereString?: string;
3334
private generateString?: string;
35+
private consistencyLevel?: ConsistencyLevel;
3436

3537
constructor(client: Connection) {
3638
super(client);
@@ -176,6 +178,11 @@ export default class GraphQLGetter extends CommandBase {
176178
return this;
177179
};
178180

181+
withConsistencyLevel = (level: ConsistencyLevel) => {
182+
this.consistencyLevel = level;
183+
return this;
184+
};
185+
179186
validateIsSet = (prop: string | undefined | null, name: string, setter: string) => {
180187
if (prop == undefined || prop == null || prop.length == 0) {
181188
this.addError(`${name} must be set - set with ${setter}`);
@@ -256,6 +263,10 @@ export default class GraphQLGetter extends CommandBase {
256263
}
257264
}
258265

266+
if (this.consistencyLevel) {
267+
args = [...args, `consistencyLevel:${this.consistencyLevel}`];
268+
}
269+
259270
if (args.length > 0) {
260271
params = `(${args.join(',')})`;
261272
}

src/graphql/journey.test.ts

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ describe('query with generative search', () => {
12271227
.withClassName('Wine')
12281228
.withFields('name review')
12291229
.withGenerate({
1230-
singlePrompt: `Describe the following as a Facebook Ad:
1230+
singlePrompt: `Describe the following as a Facebook Ad:
12311231
Tastes like a fresh ocean breeze: {review}`,
12321232
})
12331233
.do()
@@ -1274,6 +1274,76 @@ Tastes like a fresh ocean breeze: {review}`,
12741274
});
12751275
});
12761276

1277+
describe('query cluster with consistency level', () => {
1278+
const client = weaviate.client({
1279+
scheme: 'http',
1280+
host: 'localhost:8087',
1281+
});
1282+
1283+
it('sets up replicated class', () => {
1284+
return setupReplicated(client);
1285+
});
1286+
1287+
test('One', () => {
1288+
return client.graphql
1289+
.get()
1290+
.withClassName('Article')
1291+
.withFields('_additional { id isConsistent }')
1292+
.withConsistencyLevel('ONE')
1293+
.do()
1294+
.then((res: any) => {
1295+
expect(res.data.Get.Article.length).toBeGreaterThan(0);
1296+
res.data.Get.Article.forEach((article: any) => {
1297+
expect(article._additional.isConsistent).toBeTruthy();
1298+
});
1299+
return res;
1300+
})
1301+
.catch((e: any) => {
1302+
throw new Error(`unexpected error: ${JSON.stringify(e)}`);
1303+
});
1304+
});
1305+
1306+
test('Quorum', () => {
1307+
return client.graphql
1308+
.get()
1309+
.withClassName('Article')
1310+
.withFields('_additional { id isConsistent }')
1311+
.withConsistencyLevel('QUORUM')
1312+
.do()
1313+
.then((res: any) => {
1314+
expect(res.data.Get.Article.length).toBeGreaterThan(0);
1315+
res.data.Get.Article.forEach((article: any) => {
1316+
expect(article._additional.isConsistent).toBeTruthy();
1317+
});
1318+
})
1319+
.catch((e: any) => {
1320+
throw new Error(`unexpected error: ${JSON.stringify(e)}`);
1321+
});
1322+
});
1323+
1324+
test('All', () => {
1325+
return client.graphql
1326+
.get()
1327+
.withClassName('Article')
1328+
.withFields('_additional { id isConsistent }')
1329+
.withConsistencyLevel('ALL')
1330+
.do()
1331+
.then((res: any) => {
1332+
expect(res.data.Get.Article.length).toBeGreaterThan(0);
1333+
res.data.Get.Article.forEach((article: any) => {
1334+
expect(article._additional.isConsistent).toBeTruthy();
1335+
});
1336+
})
1337+
.catch((e: any) => {
1338+
throw new Error(`unexpected error: ${JSON.stringify(e)}`);
1339+
});
1340+
});
1341+
1342+
it('tears down cluster schema', () => {
1343+
return Promise.all([client.schema.classDeleter().withClassName('Article').do()]);
1344+
});
1345+
});
1346+
12771347
const setup = async (client: WeaviateClient) => {
12781348
const thing = {
12791349
class: 'Article',

0 commit comments

Comments
 (0)