Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions graphql/getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export default class Getter {
return this;
};

withOffset = (offset) => {
this.offset = offset;
return this;
};

validateIsSet = (prop, name, setter) => {
if (prop == undefined || prop == null || prop.length == 0) {
this.errors = [
Expand Down Expand Up @@ -127,6 +132,7 @@ export default class Getter {
this.askString ||
this.nearImageString ||
this.limit ||
this.offset ||
this.groupString
) {
let args = [];
Expand Down Expand Up @@ -163,6 +169,10 @@ export default class Getter {
args = [...args, `limit:${this.limit}`];
}

if (this.offset) {
args = [...args, `offset:${this.offset}`];
}

params = `(${args.join(",")})`;
}

Expand Down
17 changes: 17 additions & 0 deletions graphql/getter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ test("a simple query with a limit", () => {
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
});

test("a simple query with a limit and offset", () => {
const mockClient = {
query: jest.fn(),
};

const expectedQuery = `{Get{Person(limit:7,offset:2){name}}}`;

new Getter(mockClient)
.withClassName("Person")
.withFields("name")
.withOffset(2)
.withLimit(7)
.do();

expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
});

test("a simple query with a group", () => {
const mockClient = {
query: jest.fn(),
Expand Down