Skip to content

Commit 6d7ee61

Browse files
authored
Merge pull request #51 from weaviate/uuid_support
Adds support for uuid and uuid[] data types
2 parents 7e6eaf1 + 04a8c60 commit 6d7ee61

File tree

2 files changed

+147
-2
lines changed

2 files changed

+147
-2
lines changed

src/data/journey.test.ts

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
22
import weaviate, { WeaviateClient } from '..';
3-
import { WeaviateObject, WeaviateObjectsList, WeaviateError, Properties } from '../openapi/types';
3+
import {
4+
WeaviateObject,
5+
WeaviateObjectsList,
6+
WeaviateError,
7+
Properties,
8+
WeaviateClass,
9+
} from '../openapi/types';
410

511
const thingClassName = 'DataJourneyTestThing';
612
const refSourceClassName = 'DataJourneyTestRefSource';
@@ -1079,6 +1085,73 @@ describe('data', () => {
10791085
});
10801086
});
10811087

1088+
describe('uuid support', () => {
1089+
const client = weaviate.client({
1090+
scheme: 'http',
1091+
host: 'localhost:8080',
1092+
});
1093+
1094+
it('creates class with properties of uuid and uuid[]', async () => {
1095+
const className = 'ClassUUID';
1096+
const id = 'abefd256-8574-442b-9293-9205193737ee';
1097+
1098+
await client.schema
1099+
.classCreator()
1100+
.withClass({
1101+
class: className,
1102+
properties: [
1103+
{
1104+
dataType: ['uuid'],
1105+
name: 'uuidProp',
1106+
},
1107+
{
1108+
dataType: ['uuid[]'],
1109+
name: 'uuidArrayProp',
1110+
},
1111+
],
1112+
})
1113+
.do()
1114+
.then((res: WeaviateClass) => {
1115+
expect(res).toBeTruthy();
1116+
});
1117+
1118+
await client.data
1119+
.creator()
1120+
.withClassName(className)
1121+
.withId(id)
1122+
.withProperties({
1123+
uuidProp: '7aaa79d3-a564-45db-8fa8-c49e20b8a39a',
1124+
uuidArrayProp: ['f70512a3-26cb-4ae4-9369-204555917f15', '9e516f40-fd54-4083-a476-f4675b2b5f92'],
1125+
})
1126+
.do()
1127+
.then((res: WeaviateObject) => {
1128+
expect(res).toBeTruthy();
1129+
});
1130+
1131+
await client.data
1132+
.getterById()
1133+
.withId(id)
1134+
.withClassName(className)
1135+
.do()
1136+
.then((res: WeaviateObject) => {
1137+
expect(res).toBeTruthy();
1138+
expect(res.properties).toHaveProperty('uuidProp', '7aaa79d3-a564-45db-8fa8-c49e20b8a39a');
1139+
expect(res.properties).toHaveProperty('uuidArrayProp', [
1140+
'f70512a3-26cb-4ae4-9369-204555917f15',
1141+
'9e516f40-fd54-4083-a476-f4675b2b5f92',
1142+
]);
1143+
});
1144+
1145+
return client.schema
1146+
.classDeleter()
1147+
.withClassName(className)
1148+
.do()
1149+
.then((res: void) => {
1150+
expect(res).toEqual(undefined);
1151+
});
1152+
});
1153+
});
1154+
10821155
const setup = async (client: WeaviateClient) => {
10831156
const thing = {
10841157
class: thingClassName,

src/graphql/journey.test.ts

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import weaviate, { Reference, WeaviateClient, WeaviateError, WeaviateObject } from '..';
1+
import weaviate, { Reference, WeaviateClient, WeaviateError, WeaviateObject, WeaviateClass } from '..';
22

33
describe('the graphql journey', () => {
44
let client: WeaviateClient;
@@ -1167,6 +1167,78 @@ describe('the graphql journey', () => {
11671167
});
11681168
});
11691169

1170+
it('search object with uuid and uuid props', async () => {
1171+
const client = weaviate.client({
1172+
scheme: 'http',
1173+
host: 'localhost:8080',
1174+
});
1175+
1176+
const className = 'ClassUUID';
1177+
const id = 'abefd256-8574-442b-9293-9205193737ee';
1178+
1179+
await client.schema
1180+
.classCreator()
1181+
.withClass({
1182+
class: className,
1183+
properties: [
1184+
{
1185+
dataType: ['uuid'],
1186+
name: 'uuidProp',
1187+
},
1188+
{
1189+
dataType: ['uuid[]'],
1190+
name: 'uuidArrayProp',
1191+
},
1192+
],
1193+
})
1194+
.do()
1195+
.then((res: WeaviateClass) => {
1196+
expect(res).toBeTruthy();
1197+
});
1198+
1199+
await client.data
1200+
.creator()
1201+
.withClassName(className)
1202+
.withId(id)
1203+
.withProperties({
1204+
uuidProp: '7aaa79d3-a564-45db-8fa8-c49e20b8a39a',
1205+
uuidArrayProp: ['f70512a3-26cb-4ae4-9369-204555917f15', '9e516f40-fd54-4083-a476-f4675b2b5f92'],
1206+
})
1207+
.do()
1208+
.then((res: WeaviateObject) => {
1209+
expect(res).toBeTruthy();
1210+
});
1211+
1212+
const expectObjectFound = async (propName: string, value: string) => {
1213+
await client.graphql
1214+
.get()
1215+
.withClassName(className)
1216+
.withFields('_additional { id }')
1217+
.withWhere({
1218+
path: [propName],
1219+
operator: 'Equal',
1220+
valueText: value,
1221+
})
1222+
.do()
1223+
.then((res: any) => {
1224+
expect(res.data.Get[className].length).toBeGreaterThan(0);
1225+
expect(res.data.Get[className][0]._additional.id).toEqual(id);
1226+
});
1227+
};
1228+
1229+
await expectObjectFound('uuidProp', '7aaa79d3-a564-45db-8fa8-c49e20b8a39a');
1230+
await expectObjectFound('uuidArrayProp', 'f70512a3-26cb-4ae4-9369-204555917f15');
1231+
await expectObjectFound('uuidArrayProp', '9e516f40-fd54-4083-a476-f4675b2b5f92');
1232+
1233+
return client.schema
1234+
.classDeleter()
1235+
.withClassName(className)
1236+
.do()
1237+
.then((res: void) => {
1238+
expect(res).toEqual(undefined);
1239+
});
1240+
});
1241+
11701242
it('tears down and cleans up', () => {
11711243
return Promise.all([client.schema.classDeleter().withClassName('Article').do()]);
11721244
});

0 commit comments

Comments
 (0)