From 2c828a5ddc245a566861772ec0ca296d198b7e28 Mon Sep 17 00:00:00 2001 From: Marcin Antas Date: Mon, 29 Nov 2021 20:57:09 +0100 Subject: [PATCH] gh-36 Add support for offset param Changes made: - added support for offset param --- graphql/getter.js | 10 ++++++++++ graphql/getter.test.js | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/graphql/getter.js b/graphql/getter.js index b6b4f20..e9077f1 100644 --- a/graphql/getter.js +++ b/graphql/getter.js @@ -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 = [ @@ -127,6 +132,7 @@ export default class Getter { this.askString || this.nearImageString || this.limit || + this.offset || this.groupString ) { let args = []; @@ -163,6 +169,10 @@ export default class Getter { args = [...args, `limit:${this.limit}`]; } + if (this.offset) { + args = [...args, `offset:${this.offset}`]; + } + params = `(${args.join(",")})`; } diff --git a/graphql/getter.test.js b/graphql/getter.test.js index 5a9f06c..5fb5aff 100644 --- a/graphql/getter.test.js +++ b/graphql/getter.test.js @@ -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(),