Skip to content

Commit bdffc92

Browse files
committed
Add support for autocut
1 parent ebad76d commit bdffc92

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/graphql/getter.test.ts

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

78+
test('a simple query with autocut', () => {
79+
const mockClient: any = {
80+
query: jest.fn(),
81+
};
82+
83+
const expectedQuery = `{Get{Person(where:{operator:Equal,valueText:"hawaii",path:["name"]},autocut:10){name}}}`;
84+
85+
new Getter(mockClient)
86+
.withClassName('Person')
87+
.withAutocut(10)
88+
.withWhere({
89+
operator: 'Equal',
90+
valueText: 'hawaii',
91+
path: ['name'],
92+
})
93+
.withFields('name')
94+
.do();
95+
96+
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
97+
});
98+
7899
describe('query with consistency level', () => {
79100
test('One', () => {
80101
const mockClient: any = {

src/graphql/getter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default class GraphQLGetter extends CommandBase {
3636
private consistencyLevel?: ConsistencyLevel;
3737
private groupByString?: string;
3838
private tenant?: string;
39+
private autocut?: number;
3940

4041
constructor(client: Connection) {
4142
super(client);
@@ -171,6 +172,11 @@ export default class GraphQLGetter extends CommandBase {
171172
return this;
172173
};
173174

175+
withAutocut = (autocut: number) => {
176+
this.autocut = autocut;
177+
return this;
178+
};
179+
174180
withSort = (args: SortArgs[]) => {
175181
this.sortString = new Sort(args).toString();
176182
return this;
@@ -264,6 +270,10 @@ export default class GraphQLGetter extends CommandBase {
264270
args = [...args, `offset:${this.offset}`];
265271
}
266272

273+
if (this.autocut) {
274+
args = [...args, `autocut:${this.autocut}`];
275+
}
276+
267277
if (this.sortString) {
268278
args = [...args, `sort:[${this.sortString}]`];
269279
}

src/graphql/journey.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,22 @@ describe('the graphql journey', () => {
310310
});
311311
});
312312

313+
test('graphql get nearText with autocut', () => {
314+
return client.graphql
315+
.get()
316+
.withClassName('Article')
317+
.withNearText({ concepts: ['Article'] })
318+
.withAutocut(3)
319+
.withFields('_additional { id }')
320+
.do()
321+
.then((res: any) => {
322+
expect(res.data.Get.Article.length).toBe(3);
323+
})
324+
.catch((e: any) => {
325+
throw new Error('it should not have errord' + e);
326+
});
327+
});
328+
313329
test('graphql get hybrid with query (no vector, alpha 0)', () => {
314330
return client.graphql
315331
.get()

0 commit comments

Comments
 (0)