From f09b026e4cd6cf14497660d09f2af70024c2fd5d Mon Sep 17 00:00:00 2001 From: Johannes Vogel Date: Tue, 20 Feb 2024 15:15:06 +0100 Subject: [PATCH 1/7] @cap-js/sqlite as dep in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6a6f975..5485103 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,6 @@ "express": "^4.17.1", "jest": "^29.3.1", "semver": "^7.4.0", - "sqlite3": "^5.0.2" + "@cap-js/sqlite": "^1" } } From 2a900ffed68624f7976fe4b52d4511cf0c7537a0 Mon Sep 17 00:00:00 2001 From: Johannes Vogel Date: Tue, 20 Feb 2024 15:15:30 +0100 Subject: [PATCH 2/7] use plugin mechanism in test projectes --- test/resources/annotations/package.json | 3 +++ test/resources/bookshop-graphql/package.json | 4 ++++ test/resources/bookshop/package.json | 3 +++ test/resources/cds.Request/package.json | 3 +++ test/resources/concurrency/package.json | 3 +++ test/resources/custom-error-formatter/package.json | 3 +++ test/resources/custom-handlers/package.json | 5 +++++ test/resources/edge-cases/package.json | 3 +++ test/resources/error-handling/package.json | 3 +++ test/resources/types/package.json | 5 +++++ 10 files changed, 35 insertions(+) create mode 100644 test/resources/custom-handlers/package.json create mode 100644 test/resources/types/package.json diff --git a/test/resources/annotations/package.json b/test/resources/annotations/package.json index d3aa051..b87d22e 100644 --- a/test/resources/annotations/package.json +++ b/test/resources/annotations/package.json @@ -2,6 +2,9 @@ "dependencies": { "@cap-js/graphql": "*" }, + "devDependencies": { + "@cap-js/sqlite": "*" + }, "cds": { "protocols": { "graphql": { diff --git a/test/resources/bookshop-graphql/package.json b/test/resources/bookshop-graphql/package.json index feae891..8b38e8b 100644 --- a/test/resources/bookshop-graphql/package.json +++ b/test/resources/bookshop-graphql/package.json @@ -2,10 +2,14 @@ "dependencies": { "@cap-js/graphql": "*" }, + "devDependencies": { + "@cap-js/sqlite": "*" + }, "cds": { "requires": { "db": { "kind": "sqlite", + "impl": "@cap-js/sqlite", "credentials": { "database": ":memory:" } diff --git a/test/resources/bookshop/package.json b/test/resources/bookshop/package.json index 0e0b6de..5e7113e 100644 --- a/test/resources/bookshop/package.json +++ b/test/resources/bookshop/package.json @@ -13,6 +13,9 @@ "@sap/cds": ">=5.9", "express": "^4.17.1" }, + "devDependencies": { + "@cap-js/sqlite": "*" + }, "scripts": { "genres": "cds serve test/genres.cds", "start": "cds run", diff --git a/test/resources/cds.Request/package.json b/test/resources/cds.Request/package.json index a713a26..768a96c 100644 --- a/test/resources/cds.Request/package.json +++ b/test/resources/cds.Request/package.json @@ -1,5 +1,8 @@ { "dependencies": { "@cap-js/graphql": "*" + }, + "devDependencies": { + "@cap-js/sqlite": "*" } } diff --git a/test/resources/concurrency/package.json b/test/resources/concurrency/package.json index a713a26..768a96c 100644 --- a/test/resources/concurrency/package.json +++ b/test/resources/concurrency/package.json @@ -1,5 +1,8 @@ { "dependencies": { "@cap-js/graphql": "*" + }, + "devDependencies": { + "@cap-js/sqlite": "*" } } diff --git a/test/resources/custom-error-formatter/package.json b/test/resources/custom-error-formatter/package.json index aa93bde..db0204a 100644 --- a/test/resources/custom-error-formatter/package.json +++ b/test/resources/custom-error-formatter/package.json @@ -2,6 +2,9 @@ "dependencies": { "@cap-js/graphql": "*" }, + "devDependencies": { + "@cap-js/sqlite": "*" + }, "cds": { "protocols": { "graphql": { diff --git a/test/resources/custom-handlers/package.json b/test/resources/custom-handlers/package.json new file mode 100644 index 0000000..580c138 --- /dev/null +++ b/test/resources/custom-handlers/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "@cap-js/sqlite": "*" + } +} \ No newline at end of file diff --git a/test/resources/edge-cases/package.json b/test/resources/edge-cases/package.json index a713a26..768a96c 100644 --- a/test/resources/edge-cases/package.json +++ b/test/resources/edge-cases/package.json @@ -1,5 +1,8 @@ { "dependencies": { "@cap-js/graphql": "*" + }, + "devDependencies": { + "@cap-js/sqlite": "*" } } diff --git a/test/resources/error-handling/package.json b/test/resources/error-handling/package.json index 83fbf74..0a6173f 100644 --- a/test/resources/error-handling/package.json +++ b/test/resources/error-handling/package.json @@ -2,6 +2,9 @@ "dependencies": { "@cap-js/graphql": "*" }, + "devDependencies": { + "@cap-js/sqlite": "*" + }, "cds": { "requires": { "db": { diff --git a/test/resources/types/package.json b/test/resources/types/package.json new file mode 100644 index 0000000..717be87 --- /dev/null +++ b/test/resources/types/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "@cap-js/sqlite": "*" + } +} \ No newline at end of file From f30e5479b0c7447a70c5a65abc2ec97ad2a38155 Mon Sep 17 00:00:00 2001 From: Johannes Vogel Date: Tue, 20 Feb 2024 15:16:02 +0100 Subject: [PATCH 3/7] skip tests that expect error from old db service --- test/tests/queries/paging-offset.test.js | 3 ++- test/tests/queries/totalCount.test.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/tests/queries/paging-offset.test.js b/test/tests/queries/paging-offset.test.js index 5e4c7ae..7bc9db9 100644 --- a/test/tests/queries/paging-offset.test.js +++ b/test/tests/queries/paging-offset.test.js @@ -120,7 +120,8 @@ describe('graphql - offset-based paging', () => { expect(response.data).toEqual({ data }) }) - test('query with top and skip arguments on nested fields', async () => { + // @cap-js/sqlite does not throw that error + test.skip('query with top and skip arguments on nested fields', async () => { const query = gql` { AdminService { diff --git a/test/tests/queries/totalCount.test.js b/test/tests/queries/totalCount.test.js index ee47312..740e596 100644 --- a/test/tests/queries/totalCount.test.js +++ b/test/tests/queries/totalCount.test.js @@ -139,7 +139,8 @@ describe('graphql - queries with totalCount', () => { expect(response.data).toEqual({ data }) }) - test('query with totalCount and top and skip arguments on nested fields', async () => { + // @cap-js/sqlite does not throw that error + test.skip('query with totalCount and top and skip arguments on nested fields', async () => { const query = gql` { AdminService { From 83b14bc24754806d7651a77e2a8a2b2d11ae1ed4 Mon Sep 17 00:00:00 2001 From: Johannes Vogel Date: Tue, 20 Feb 2024 15:16:30 +0100 Subject: [PATCH 4/7] fix: new db service does not allow empty array in SELECT.columns --- lib/resolvers/crud/read.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/resolvers/crud/read.js b/lib/resolvers/crud/read.js index 4c8c8b9..e74d702 100644 --- a/lib/resolvers/crud/read.js +++ b/lib/resolvers/crud/read.js @@ -10,7 +10,8 @@ module.exports = async ({ req, res }, service, entity, selection) => { const args = selection.arguments let query = SELECT.from(entity) - query.columns(astToColumns(entity, selection.selectionSet.selections, true)) + const columns = astToColumns(entity, selection.selectionSet.selections, true) + if (columns.length) query.columns(columns) const filter = getArgumentByName(args, ARGS.filter) if (filter) { From 87b234097f165a203ed4e377029ac71781311b65 Mon Sep 17 00:00:00 2001 From: Johannes Vogel Date: Tue, 20 Feb 2024 15:17:25 +0100 Subject: [PATCH 5/7] adapt case sensitivity of functions --- test/tests/queries/filter.test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/tests/queries/filter.test.js b/test/tests/queries/filter.test.js index 9a7d9a6..20730ce 100644 --- a/test/tests/queries/filter.test.js +++ b/test/tests/queries/filter.test.js @@ -286,11 +286,12 @@ describe('graphql - filter', () => { expect(response.data).toEqual({ data }) }) + // REVISIT: why is contains now case sensitive? test('query with filter with in operator with multiple values', async () => { const query = gql` { AdminService { - Books(filter: [{ ID: { in: [201, 251] } }, { title: { contains: "cat" } }]) { + Books(filter: [{ ID: { in: [201, 251] } }, { title: { contains: "Cat" } }]) { nodes { ID title @@ -461,6 +462,7 @@ describe('graphql - filter', () => { expect(response.data).toEqual({ data }) }) + // REVISIT: why is contains,startswith,endswith now case sensitive? test('query with complex filter', async () => { const query = gql` { @@ -468,10 +470,10 @@ describe('graphql - filter', () => { Books( filter: [ { - title: [{ startswith: "the", endswith: "raven" }, { contains: "height" }] + title: [{ startswith: "The", endswith: "Raven" }, { contains: "Height" }] ID: [{ eq: 201 }, { eq: 251 }] } - { title: { contains: "cat" } } + { title: { contains: "Cat" } } ] ) { nodes { From 689b0a8c05295fa217a67e25864eecadab05ae50 Mon Sep 17 00:00:00 2001 From: Johannes Vogel Date: Fri, 23 Feb 2024 09:01:38 +0100 Subject: [PATCH 6/7] remove revisit comment --- test/tests/queries/filter.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/tests/queries/filter.test.js b/test/tests/queries/filter.test.js index 20730ce..fa8b4b5 100644 --- a/test/tests/queries/filter.test.js +++ b/test/tests/queries/filter.test.js @@ -286,7 +286,6 @@ describe('graphql - filter', () => { expect(response.data).toEqual({ data }) }) - // REVISIT: why is contains now case sensitive? test('query with filter with in operator with multiple values', async () => { const query = gql` { @@ -462,7 +461,6 @@ describe('graphql - filter', () => { expect(response.data).toEqual({ data }) }) - // REVISIT: why is contains,startswith,endswith now case sensitive? test('query with complex filter', async () => { const query = gql` { From f74062fab802edb74e2811dacafd7a9d28bde67e Mon Sep 17 00:00:00 2001 From: Johannes Vogel Date: Fri, 23 Feb 2024 11:00:18 +0100 Subject: [PATCH 7/7] nested limits work with @cap-js/sqlite --- test/tests/queries/paging-offset.test.js | 64 ++++++++++++++++-------- test/tests/queries/totalCount.test.js | 38 +++++++++----- 2 files changed, 68 insertions(+), 34 deletions(-) diff --git a/test/tests/queries/paging-offset.test.js b/test/tests/queries/paging-offset.test.js index 7bc9db9..67ef4f9 100644 --- a/test/tests/queries/paging-offset.test.js +++ b/test/tests/queries/paging-offset.test.js @@ -61,19 +61,27 @@ describe('graphql - offset-based paging', () => { } ` const data = { - AdminServiceBasic: { - Authors: null + AdminService: { + Authors: [ + { + name: 'Edgar Allen Poe', + books: [ + // Edgar Allen Poe has 2 books, but only 1 requested. + { + title: 'Eleonora' + } + ] + }, + { + name: 'Richard Carpenter', + books: [] + } + ] } } - const errors = [ - { - locations: [{ column: 13, line: 4 }], - message: 'Pagination is not supported in expand', - path: ['AdminServiceBasic', 'Authors'] - } - ] + const response = await POST('/graphql', { query }) - expect(response.data).toEqual({ data, errors }) + expect(response.data).toEqual({ data }) }) }) @@ -120,8 +128,7 @@ describe('graphql - offset-based paging', () => { expect(response.data).toEqual({ data }) }) - // @cap-js/sqlite does not throw that error - test.skip('query with top and skip arguments on nested fields', async () => { + test('query with top and skip arguments on nested fields', async () => { const query = gql` { AdminService { @@ -140,19 +147,32 @@ describe('graphql - offset-based paging', () => { ` const data = { AdminService: { - Authors: null + Authors: { + nodes: [ + { + name: 'Edgar Allen Poe', + books: { + // Edgar Allen Poe has 2 books, but only 1 requested. + nodes: [ + { + title: 'Eleonora' + } + ] + } + }, + { + name: 'Richard Carpenter', + books: { + nodes: [] + } + } + ] + } } } - const errors = [ - { - locations: [{ column: 13, line: 4 }], - message: 'Pagination is not supported in expand', - path: ['AdminService', 'Authors'], - extensions: expect.any(Object) - } - ] + const response = await POST('/graphql', { query }) - expect(response.data).toEqual({ data, errors }) + expect(response.data).toEqual({ data }) }) }) }) diff --git a/test/tests/queries/totalCount.test.js b/test/tests/queries/totalCount.test.js index 740e596..07f7536 100644 --- a/test/tests/queries/totalCount.test.js +++ b/test/tests/queries/totalCount.test.js @@ -139,8 +139,7 @@ describe('graphql - queries with totalCount', () => { expect(response.data).toEqual({ data }) }) - // @cap-js/sqlite does not throw that error - test.skip('query with totalCount and top and skip arguments on nested fields', async () => { + test('query with totalCount and top and skip arguments on nested fields', async () => { const query = gql` { AdminService { @@ -161,19 +160,34 @@ describe('graphql - queries with totalCount', () => { ` const data = { AdminService: { - Authors: null + Authors: { + totalCount: 4, + nodes: [ + { + name: 'Edgar Allen Poe', + books: { + totalCount: null, // REVISIT: expected 2 + nodes: [ + { + title: 'Eleonora' + } + ] + } + }, + { + name: 'Richard Carpenter', + books: { + totalCount: null, // REVISIT: expected 0 + nodes: [] + } + } + ] + } } } - const errors = [ - { - locations: [{ column: 11, line: 4 }], - message: 'Pagination is not supported in expand', - path: ['AdminService', 'Authors'], - extensions: expect.any(Object) - } - ] + const response = await POST('/graphql', { query }) - expect(response.data).toEqual({ data, errors }) + expect(response.data).toEqual({ data }) }) test('query with aliases on totalCount on nested fields', async () => {