diff --git a/lib/resolvers/crud/read.js b/lib/resolvers/crud/read.js index 4c8c8b96..e74d7028 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) { diff --git a/package.json b/package.json index 6a6f9755..5485103d 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" } } diff --git a/test/resources/annotations/package.json b/test/resources/annotations/package.json index d3aa051f..b87d22ed 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 feae891a..8b38e8b0 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 0e0b6de2..5e7113e1 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 a713a269..768a96c1 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 a713a269..768a96c1 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 aa93bde8..db0204a2 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 00000000..580c138c --- /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 a713a269..768a96c1 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 83fbf746..0a6173f6 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 00000000..717be87e --- /dev/null +++ b/test/resources/types/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "@cap-js/sqlite": "*" + } +} \ No newline at end of file diff --git a/test/tests/queries/filter.test.js b/test/tests/queries/filter.test.js index 9a7d9a6c..fa8b4b55 100644 --- a/test/tests/queries/filter.test.js +++ b/test/tests/queries/filter.test.js @@ -290,7 +290,7 @@ describe('graphql - filter', () => { 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 @@ -468,10 +468,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 { diff --git a/test/tests/queries/paging-offset.test.js b/test/tests/queries/paging-offset.test.js index 5e4c7ae2..67ef4f97 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 }) }) }) @@ -139,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 ee47312c..07f75366 100644 --- a/test/tests/queries/totalCount.test.js +++ b/test/tests/queries/totalCount.test.js @@ -160,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 () => {