From 7372ed82a7f96a5323dafb54b1fca895b3f139ba Mon Sep 17 00:00:00 2001 From: Kervin Date: Thu, 7 Apr 2022 21:49:17 -0700 Subject: [PATCH] add node field and update tests --- src/index.ts | 1 + src/interfaces.ts | 1 + tests/__snapshots__/index.spec.ts.snap | 1423 ++++++++++++++++++++++++ tests/index.spec.ts | 12 + 4 files changed, 1437 insertions(+) diff --git a/src/index.ts b/src/index.ts index e82d476f..305dd329 100644 --- a/src/index.ts +++ b/src/index.ts @@ -98,6 +98,7 @@ export async function findManyCursorConnection< cursor: encodeCursor(record, options), } as CustomEdge) ), + nodes: records as unknown[] as Node[], pageInfo: { hasNextPage, hasPreviousPage, startCursor, endCursor }, totalCount: totalCount, } diff --git a/src/interfaces.ts b/src/interfaces.ts index 694dadb0..3439cf8b 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -28,6 +28,7 @@ export interface ConnectionArguments { // Relay Response export interface Connection = Edge> { + nodes: T[] edges: Array pageInfo: PageInfo totalCount: number diff --git a/tests/__snapshots__/index.spec.ts.snap b/tests/__snapshots__/index.spec.ts.snap index c145020d..96218058 100644 --- a/tests/__snapshots__/index.spec.ts.snap +++ b/tests/__snapshots__/index.spec.ts.snap @@ -204,6 +204,108 @@ exports[`prisma-relay-cursor-connection custom edge fields returns all todos 1`] }, }, ], + "nodes": [ + { + "id": "id_01", + "isCompleted": false, + "text": "veritatis molestias qui", + }, + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + { + "id": "id_05", + "isCompleted": true, + "text": "voluptatem sint ipsam", + }, + { + "id": "id_06", + "isCompleted": true, + "text": "ut sunt consequuntur", + }, + { + "id": "id_07", + "isCompleted": false, + "text": "accusamus aut labore", + }, + { + "id": "id_08", + "isCompleted": true, + "text": "et quo quia", + }, + { + "id": "id_09", + "isCompleted": true, + "text": "accusantium a excepturi", + }, + { + "id": "id_10", + "isCompleted": true, + "text": "deserunt rerum occaecati", + }, + { + "id": "id_11", + "isCompleted": false, + "text": "unde et quasi", + }, + { + "id": "id_12", + "isCompleted": false, + "text": "et autem sapiente", + }, + { + "id": "id_13", + "isCompleted": false, + "text": "deleniti fuga et", + }, + { + "id": "id_14", + "isCompleted": true, + "text": "ea molestiae similique", + }, + { + "id": "id_15", + "isCompleted": false, + "text": "doloribus ea aut", + }, + { + "id": "id_16", + "isCompleted": true, + "text": "ut molestias veniam", + }, + { + "id": "id_17", + "isCompleted": true, + "text": "a placeat aperiam", + }, + { + "id": "id_18", + "isCompleted": true, + "text": "quos rerum aut", + }, + { + "id": "id_19", + "isCompleted": false, + "text": "ullam a voluptatem", + }, + { + "id": "id_20", + "isCompleted": true, + "text": "dolorum deserunt quis", + }, + ], "pageInfo": { "endCursor": "id_20", "hasNextPage": false, @@ -268,6 +370,33 @@ exports[`prisma-relay-cursor-connection custom edge fields returns the first 5 t }, }, ], + "nodes": [ + { + "id": "id_01", + "isCompleted": false, + "text": "veritatis molestias qui", + }, + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + { + "id": "id_05", + "isCompleted": true, + "text": "voluptatem sint ipsam", + }, + ], "pageInfo": { "endCursor": "id_05", "hasNextPage": true, @@ -332,6 +461,33 @@ exports[`prisma-relay-cursor-connection custom edge fields returns the first 5 t }, }, ], + "nodes": [ + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + { + "id": "id_05", + "isCompleted": true, + "text": "voluptatem sint ipsam", + }, + { + "id": "id_06", + "isCompleted": true, + "text": "ut sunt consequuntur", + }, + ], "pageInfo": { "endCursor": "id_06", "hasNextPage": true, @@ -396,6 +552,33 @@ exports[`prisma-relay-cursor-connection custom edge fields returns the first 5 t }, }, ], + "nodes": [ + { + "id": "id_06", + "isCompleted": true, + "text": "ut sunt consequuntur", + }, + { + "id": "id_07", + "isCompleted": false, + "text": "accusamus aut labore", + }, + { + "id": "id_08", + "isCompleted": true, + "text": "et quo quia", + }, + { + "id": "id_09", + "isCompleted": true, + "text": "accusantium a excepturi", + }, + { + "id": "id_10", + "isCompleted": true, + "text": "deserunt rerum occaecati", + }, + ], "pageInfo": { "endCursor": "id_10", "hasNextPage": true, @@ -460,6 +643,33 @@ exports[`prisma-relay-cursor-connection custom edge fields returns the first 5 t }, }, ], + "nodes": [ + { + "id": "id_16", + "isCompleted": true, + "text": "ut molestias veniam", + }, + { + "id": "id_17", + "isCompleted": true, + "text": "a placeat aperiam", + }, + { + "id": "id_18", + "isCompleted": true, + "text": "quos rerum aut", + }, + { + "id": "id_19", + "isCompleted": false, + "text": "ullam a voluptatem", + }, + { + "id": "id_20", + "isCompleted": true, + "text": "dolorum deserunt quis", + }, + ], "pageInfo": { "endCursor": "id_20", "hasNextPage": false, @@ -514,6 +724,28 @@ exports[`prisma-relay-cursor-connection custom edge fields returns the first 5 t }, }, ], + "nodes": [ + { + "id": "id_17", + "isCompleted": true, + "text": "a placeat aperiam", + }, + { + "id": "id_18", + "isCompleted": true, + "text": "quos rerum aut", + }, + { + "id": "id_19", + "isCompleted": false, + "text": "ullam a voluptatem", + }, + { + "id": "id_20", + "isCompleted": true, + "text": "dolorum deserunt quis", + }, + ], "pageInfo": { "endCursor": "id_20", "hasNextPage": false, @@ -527,6 +759,7 @@ exports[`prisma-relay-cursor-connection custom edge fields returns the first 5 t exports[`prisma-relay-cursor-connection custom edge fields returns the first 5 todos after the 20th todo 1`] = ` { "edges": [], + "nodes": [], "pageInfo": { "endCursor": undefined, "hasNextPage": false, @@ -591,6 +824,33 @@ exports[`prisma-relay-cursor-connection custom edge fields returns the last 5 to }, }, ], + "nodes": [ + { + "id": "id_16", + "isCompleted": true, + "text": "ut molestias veniam", + }, + { + "id": "id_17", + "isCompleted": true, + "text": "a placeat aperiam", + }, + { + "id": "id_18", + "isCompleted": true, + "text": "quos rerum aut", + }, + { + "id": "id_19", + "isCompleted": false, + "text": "ullam a voluptatem", + }, + { + "id": "id_20", + "isCompleted": true, + "text": "dolorum deserunt quis", + }, + ], "pageInfo": { "endCursor": "id_20", "hasNextPage": false, @@ -604,6 +864,7 @@ exports[`prisma-relay-cursor-connection custom edge fields returns the last 5 to exports[`prisma-relay-cursor-connection custom edge fields returns the last 5 todos before the 1st todo 1`] = ` { "edges": [], + "nodes": [], "pageInfo": { "endCursor": undefined, "hasNextPage": true, @@ -658,6 +919,28 @@ exports[`prisma-relay-cursor-connection custom edge fields returns the last 5 to }, }, ], + "nodes": [ + { + "id": "id_01", + "isCompleted": false, + "text": "veritatis molestias qui", + }, + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + ], "pageInfo": { "endCursor": "id_04", "hasNextPage": true, @@ -722,6 +1005,33 @@ exports[`prisma-relay-cursor-connection custom edge fields returns the last 5 to }, }, ], + "nodes": [ + { + "id": "id_01", + "isCompleted": false, + "text": "veritatis molestias qui", + }, + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + { + "id": "id_05", + "isCompleted": true, + "text": "voluptatem sint ipsam", + }, + ], "pageInfo": { "endCursor": "id_05", "hasNextPage": true, @@ -786,6 +1096,33 @@ exports[`prisma-relay-cursor-connection custom edge fields returns the last 5 to }, }, ], + "nodes": [ + { + "id": "id_11", + "isCompleted": false, + "text": "unde et quasi", + }, + { + "id": "id_12", + "isCompleted": false, + "text": "et autem sapiente", + }, + { + "id": "id_13", + "isCompleted": false, + "text": "deleniti fuga et", + }, + { + "id": "id_14", + "isCompleted": true, + "text": "ea molestiae similique", + }, + { + "id": "id_15", + "isCompleted": false, + "text": "doloribus ea aut", + }, + ], "pageInfo": { "endCursor": "id_15", "hasNextPage": true, @@ -885,6 +1222,28 @@ exports[`prisma-relay-cursor-connection multi field id returns the first 5 profi }, }, ], + "nodes": [ + { + "firstname": "foo1", + "lastname": "bar1", + }, + { + "firstname": "foo10", + "lastname": "bar1", + }, + { + "firstname": "foo11", + "lastname": "bar1", + }, + { + "firstname": "foo12", + "lastname": "bar1", + }, + { + "firstname": "foo13", + "lastname": "bar1", + }, + ], "pageInfo": { "endCursor": "eyJmaXJzdG5hbWVfbGFzdG5hbWUiOnsiZmlyc3RuYW1lIjoiZm9vMTMiLCJsYXN0bmFtZSI6ImJhcjEifX0=", "hasNextPage": true, @@ -934,6 +1293,28 @@ exports[`prisma-relay-cursor-connection multi field id returns the first 5 profi }, }, ], + "nodes": [ + { + "firstname": "foo10", + "lastname": "bar1", + }, + { + "firstname": "foo11", + "lastname": "bar1", + }, + { + "firstname": "foo12", + "lastname": "bar1", + }, + { + "firstname": "foo13", + "lastname": "bar1", + }, + { + "firstname": "foo14", + "lastname": "bar1", + }, + ], "pageInfo": { "endCursor": "eyJmaXJzdG5hbWVfbGFzdG5hbWUiOnsiZmlyc3RuYW1lIjoiZm9vMTQiLCJsYXN0bmFtZSI6ImJhcjEifX0=", "hasNextPage": true, @@ -976,6 +1357,24 @@ exports[`prisma-relay-cursor-connection multi field id returns the first 5 profi }, }, ], + "nodes": [ + { + "firstname": "foo6", + "lastname": "bar1", + }, + { + "firstname": "foo7", + "lastname": "bar1", + }, + { + "firstname": "foo8", + "lastname": "bar1", + }, + { + "firstname": "foo9", + "lastname": "bar1", + }, + ], "pageInfo": { "endCursor": "eyJmaXJzdG5hbWVfbGFzdG5hbWUiOnsiZmlyc3RuYW1lIjoiZm9vOSIsImxhc3RuYW1lIjoiYmFyMSJ9fQ==", "hasNextPage": false, @@ -1025,6 +1424,28 @@ exports[`prisma-relay-cursor-connection multi field id returns the first 5 profi }, }, ], + "nodes": [ + { + "firstname": "foo16", + "lastname": "bar1", + }, + { + "firstname": "foo17", + "lastname": "bar1", + }, + { + "firstname": "foo18", + "lastname": "bar1", + }, + { + "firstname": "foo19", + "lastname": "bar1", + }, + { + "firstname": "foo2", + "lastname": "bar1", + }, + ], "pageInfo": { "endCursor": "eyJmaXJzdG5hbWVfbGFzdG5hbWUiOnsiZmlyc3RuYW1lIjoiZm9vMiIsImxhc3RuYW1lIjoiYmFyMSJ9fQ==", "hasNextPage": true, @@ -1074,6 +1495,28 @@ exports[`prisma-relay-cursor-connection multi field id returns the first 5 profi }, }, ], + "nodes": [ + { + "firstname": "foo17", + "lastname": "bar1", + }, + { + "firstname": "foo18", + "lastname": "bar1", + }, + { + "firstname": "foo19", + "lastname": "bar1", + }, + { + "firstname": "foo2", + "lastname": "bar1", + }, + { + "firstname": "foo20", + "lastname": "bar1", + }, + ], "pageInfo": { "endCursor": "eyJmaXJzdG5hbWVfbGFzdG5hbWUiOnsiZmlyc3RuYW1lIjoiZm9vMjAiLCJsYXN0bmFtZSI6ImJhcjEifX0=", "hasNextPage": true, @@ -1123,6 +1566,28 @@ exports[`prisma-relay-cursor-connection multi field id returns the first 5 profi }, }, ], + "nodes": [ + { + "firstname": "foo3", + "lastname": "bar1", + }, + { + "firstname": "foo4", + "lastname": "bar1", + }, + { + "firstname": "foo5", + "lastname": "bar1", + }, + { + "firstname": "foo6", + "lastname": "bar1", + }, + { + "firstname": "foo7", + "lastname": "bar1", + }, + ], "pageInfo": { "endCursor": "eyJmaXJzdG5hbWVfbGFzdG5hbWUiOnsiZmlyc3RuYW1lIjoiZm9vNyIsImxhc3RuYW1lIjoiYmFyMSJ9fQ==", "hasNextPage": true, @@ -1136,6 +1601,7 @@ exports[`prisma-relay-cursor-connection multi field id returns the first 5 profi exports[`prisma-relay-cursor-connection multi field id returns the last 5 profiles before the 1st profile 1`] = ` { "edges": [], + "nodes": [], "pageInfo": { "endCursor": undefined, "hasNextPage": true, @@ -1185,6 +1651,28 @@ exports[`prisma-relay-cursor-connection multi field id returns the last 5 profil }, }, ], + "nodes": [ + { + "firstname": "foo19", + "lastname": "bar1", + }, + { + "firstname": "foo2", + "lastname": "bar1", + }, + { + "firstname": "foo20", + "lastname": "bar1", + }, + { + "firstname": "foo3", + "lastname": "bar1", + }, + { + "firstname": "foo4", + "lastname": "bar1", + }, + ], "pageInfo": { "endCursor": "eyJmaXJzdG5hbWVfbGFzdG5hbWUiOnsiZmlyc3RuYW1lIjoiZm9vNCIsImxhc3RuYW1lIjoiYmFyMSJ9fQ==", "hasNextPage": true, @@ -1234,6 +1722,28 @@ exports[`prisma-relay-cursor-connection multi field id returns the last 5 profil }, }, ], + "nodes": [ + { + "firstname": "foo2", + "lastname": "bar1", + }, + { + "firstname": "foo20", + "lastname": "bar1", + }, + { + "firstname": "foo3", + "lastname": "bar1", + }, + { + "firstname": "foo4", + "lastname": "bar1", + }, + { + "firstname": "foo5", + "lastname": "bar1", + }, + ], "pageInfo": { "endCursor": "eyJmaXJzdG5hbWVfbGFzdG5hbWUiOnsiZmlyc3RuYW1lIjoiZm9vNSIsImxhc3RuYW1lIjoiYmFyMSJ9fQ==", "hasNextPage": true, @@ -1283,6 +1793,28 @@ exports[`prisma-relay-cursor-connection multi field id returns the last 5 profil }, }, ], + "nodes": [ + { + "firstname": "foo11", + "lastname": "bar1", + }, + { + "firstname": "foo12", + "lastname": "bar1", + }, + { + "firstname": "foo13", + "lastname": "bar1", + }, + { + "firstname": "foo14", + "lastname": "bar1", + }, + { + "firstname": "foo15", + "lastname": "bar1", + }, + ], "pageInfo": { "endCursor": "eyJmaXJzdG5hbWVfbGFzdG5hbWUiOnsiZmlyc3RuYW1lIjoiZm9vMTUiLCJsYXN0bmFtZSI6ImJhcjEifX0=", "hasNextPage": true, @@ -1458,6 +1990,88 @@ exports[`prisma-relay-cursor-connection number id returns all users 1`] = ` }, }, ], + "nodes": [ + { + "email": "user1@email.com", + "id": 1, + }, + { + "email": "user2@email.com", + "id": 2, + }, + { + "email": "user3@email.com", + "id": 3, + }, + { + "email": "user4@email.com", + "id": 4, + }, + { + "email": "user5@email.com", + "id": 5, + }, + { + "email": "user6@email.com", + "id": 6, + }, + { + "email": "user7@email.com", + "id": 7, + }, + { + "email": "user8@email.com", + "id": 8, + }, + { + "email": "user9@email.com", + "id": 9, + }, + { + "email": "user10@email.com", + "id": 10, + }, + { + "email": "user11@email.com", + "id": 11, + }, + { + "email": "user12@email.com", + "id": 12, + }, + { + "email": "user13@email.com", + "id": 13, + }, + { + "email": "user14@email.com", + "id": 14, + }, + { + "email": "user15@email.com", + "id": 15, + }, + { + "email": "user16@email.com", + "id": 16, + }, + { + "email": "user17@email.com", + "id": 17, + }, + { + "email": "user18@email.com", + "id": 18, + }, + { + "email": "user19@email.com", + "id": 19, + }, + { + "email": "user20@email.com", + "id": 20, + }, + ], "pageInfo": { "endCursor": "eyJpZCI6MjB9", "hasNextPage": false, @@ -1507,6 +2121,28 @@ exports[`prisma-relay-cursor-connection number id returns the first 5 users 1`] }, }, ], + "nodes": [ + { + "email": "user1@email.com", + "id": 1, + }, + { + "email": "user2@email.com", + "id": 2, + }, + { + "email": "user3@email.com", + "id": 3, + }, + { + "email": "user4@email.com", + "id": 4, + }, + { + "email": "user5@email.com", + "id": 5, + }, + ], "pageInfo": { "endCursor": "eyJpZCI6NX0=", "hasNextPage": true, @@ -1556,6 +2192,28 @@ exports[`prisma-relay-cursor-connection number id returns the first 5 users afte }, }, ], + "nodes": [ + { + "email": "user2@email.com", + "id": 2, + }, + { + "email": "user3@email.com", + "id": 3, + }, + { + "email": "user4@email.com", + "id": 4, + }, + { + "email": "user5@email.com", + "id": 5, + }, + { + "email": "user6@email.com", + "id": 6, + }, + ], "pageInfo": { "endCursor": "eyJpZCI6Nn0=", "hasNextPage": true, @@ -1605,6 +2263,28 @@ exports[`prisma-relay-cursor-connection number id returns the first 5 users afte }, }, ], + "nodes": [ + { + "email": "user6@email.com", + "id": 6, + }, + { + "email": "user7@email.com", + "id": 7, + }, + { + "email": "user8@email.com", + "id": 8, + }, + { + "email": "user9@email.com", + "id": 9, + }, + { + "email": "user10@email.com", + "id": 10, + }, + ], "pageInfo": { "endCursor": "eyJpZCI6MTB9", "hasNextPage": true, @@ -1654,6 +2334,28 @@ exports[`prisma-relay-cursor-connection number id returns the first 5 users afte }, }, ], + "nodes": [ + { + "email": "user16@email.com", + "id": 16, + }, + { + "email": "user17@email.com", + "id": 17, + }, + { + "email": "user18@email.com", + "id": 18, + }, + { + "email": "user19@email.com", + "id": 19, + }, + { + "email": "user20@email.com", + "id": 20, + }, + ], "pageInfo": { "endCursor": "eyJpZCI6MjB9", "hasNextPage": false, @@ -1696,6 +2398,24 @@ exports[`prisma-relay-cursor-connection number id returns the first 5 users afte }, }, ], + "nodes": [ + { + "email": "user17@email.com", + "id": 17, + }, + { + "email": "user18@email.com", + "id": 18, + }, + { + "email": "user19@email.com", + "id": 19, + }, + { + "email": "user20@email.com", + "id": 20, + }, + ], "pageInfo": { "endCursor": "eyJpZCI6MjB9", "hasNextPage": false, @@ -1709,6 +2429,7 @@ exports[`prisma-relay-cursor-connection number id returns the first 5 users afte exports[`prisma-relay-cursor-connection number id returns the first 5 users after the 20th user 1`] = ` { "edges": [], + "nodes": [], "pageInfo": { "endCursor": undefined, "hasNextPage": false, @@ -1758,6 +2479,28 @@ exports[`prisma-relay-cursor-connection number id returns the last 5 users 1`] = }, }, ], + "nodes": [ + { + "email": "user16@email.com", + "id": 16, + }, + { + "email": "user17@email.com", + "id": 17, + }, + { + "email": "user18@email.com", + "id": 18, + }, + { + "email": "user19@email.com", + "id": 19, + }, + { + "email": "user20@email.com", + "id": 20, + }, + ], "pageInfo": { "endCursor": "eyJpZCI6MjB9", "hasNextPage": false, @@ -1771,6 +2514,7 @@ exports[`prisma-relay-cursor-connection number id returns the last 5 users 1`] = exports[`prisma-relay-cursor-connection number id returns the last 5 users before the 1st user 1`] = ` { "edges": [], + "nodes": [], "pageInfo": { "endCursor": undefined, "hasNextPage": true, @@ -1813,6 +2557,24 @@ exports[`prisma-relay-cursor-connection number id returns the last 5 users befor }, }, ], + "nodes": [ + { + "email": "user1@email.com", + "id": 1, + }, + { + "email": "user2@email.com", + "id": 2, + }, + { + "email": "user3@email.com", + "id": 3, + }, + { + "email": "user4@email.com", + "id": 4, + }, + ], "pageInfo": { "endCursor": "eyJpZCI6NH0=", "hasNextPage": true, @@ -1862,6 +2624,28 @@ exports[`prisma-relay-cursor-connection number id returns the last 5 users befor }, }, ], + "nodes": [ + { + "email": "user1@email.com", + "id": 1, + }, + { + "email": "user2@email.com", + "id": 2, + }, + { + "email": "user3@email.com", + "id": 3, + }, + { + "email": "user4@email.com", + "id": 4, + }, + { + "email": "user5@email.com", + "id": 5, + }, + ], "pageInfo": { "endCursor": "eyJpZCI6NX0=", "hasNextPage": true, @@ -1911,6 +2695,28 @@ exports[`prisma-relay-cursor-connection number id returns the last 5 users befor }, }, ], + "nodes": [ + { + "email": "user11@email.com", + "id": 11, + }, + { + "email": "user12@email.com", + "id": 12, + }, + { + "email": "user13@email.com", + "id": 13, + }, + { + "email": "user14@email.com", + "id": 14, + }, + { + "email": "user15@email.com", + "id": 15, + }, + ], "pageInfo": { "endCursor": "eyJpZCI6MTV9", "hasNextPage": true, @@ -1949,6 +2755,7 @@ exports[`prisma-relay-cursor-connection number id returns the paginated users wi exports[`prisma-relay-cursor-connection requested fields via resolveInfo returns all todos (no fields) 1`] = ` { "edges": [], + "nodes": [], "pageInfo": { "endCursor": undefined, "hasNextPage": false, @@ -1962,6 +2769,7 @@ exports[`prisma-relay-cursor-connection requested fields via resolveInfo returns exports[`prisma-relay-cursor-connection requested fields via resolveInfo returns all todos (totalCount field) 1`] = ` { "edges": [], + "nodes": [], "pageInfo": { "endCursor": undefined, "hasNextPage": false, @@ -2016,6 +2824,33 @@ exports[`prisma-relay-cursor-connection requested fields via resolveInfo returns }, }, ], + "nodes": [ + { + "id": "id_01", + "isCompleted": false, + "text": "veritatis molestias qui", + }, + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + { + "id": "id_05", + "isCompleted": true, + "text": "voluptatem sint ipsam", + }, + ], "pageInfo": { "endCursor": "id_05", "hasNextPage": true, @@ -2070,6 +2905,33 @@ exports[`prisma-relay-cursor-connection requested fields via resolveInfo returns }, }, ], + "nodes": [ + { + "id": "id_01", + "isCompleted": false, + "text": "veritatis molestias qui", + }, + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + { + "id": "id_05", + "isCompleted": true, + "text": "voluptatem sint ipsam", + }, + ], "pageInfo": { "endCursor": "id_05", "hasNextPage": true, @@ -2124,6 +2986,33 @@ exports[`prisma-relay-cursor-connection requested fields via resolveInfo returns }, }, ], + "nodes": [ + { + "id": "id_16", + "isCompleted": true, + "text": "ut molestias veniam", + }, + { + "id": "id_17", + "isCompleted": true, + "text": "a placeat aperiam", + }, + { + "id": "id_18", + "isCompleted": true, + "text": "quos rerum aut", + }, + { + "id": "id_19", + "isCompleted": false, + "text": "ullam a voluptatem", + }, + { + "id": "id_20", + "isCompleted": true, + "text": "dolorum deserunt quis", + }, + ], "pageInfo": { "endCursor": "id_20", "hasNextPage": false, @@ -2178,6 +3067,33 @@ exports[`prisma-relay-cursor-connection requested fields via resolveInfo returns }, }, ], + "nodes": [ + { + "id": "id_16", + "isCompleted": true, + "text": "ut molestias veniam", + }, + { + "id": "id_17", + "isCompleted": true, + "text": "a placeat aperiam", + }, + { + "id": "id_18", + "isCompleted": true, + "text": "quos rerum aut", + }, + { + "id": "id_19", + "isCompleted": false, + "text": "ullam a voluptatem", + }, + { + "id": "id_20", + "isCompleted": true, + "text": "dolorum deserunt quis", + }, + ], "pageInfo": { "endCursor": "id_20", "hasNextPage": false, @@ -2382,6 +3298,108 @@ exports[`prisma-relay-cursor-connection string id returns all todos 1`] = ` }, }, ], + "nodes": [ + { + "id": "id_01", + "isCompleted": false, + "text": "veritatis molestias qui", + }, + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + { + "id": "id_05", + "isCompleted": true, + "text": "voluptatem sint ipsam", + }, + { + "id": "id_06", + "isCompleted": true, + "text": "ut sunt consequuntur", + }, + { + "id": "id_07", + "isCompleted": false, + "text": "accusamus aut labore", + }, + { + "id": "id_08", + "isCompleted": true, + "text": "et quo quia", + }, + { + "id": "id_09", + "isCompleted": true, + "text": "accusantium a excepturi", + }, + { + "id": "id_10", + "isCompleted": true, + "text": "deserunt rerum occaecati", + }, + { + "id": "id_11", + "isCompleted": false, + "text": "unde et quasi", + }, + { + "id": "id_12", + "isCompleted": false, + "text": "et autem sapiente", + }, + { + "id": "id_13", + "isCompleted": false, + "text": "deleniti fuga et", + }, + { + "id": "id_14", + "isCompleted": true, + "text": "ea molestiae similique", + }, + { + "id": "id_15", + "isCompleted": false, + "text": "doloribus ea aut", + }, + { + "id": "id_16", + "isCompleted": true, + "text": "ut molestias veniam", + }, + { + "id": "id_17", + "isCompleted": true, + "text": "a placeat aperiam", + }, + { + "id": "id_18", + "isCompleted": true, + "text": "quos rerum aut", + }, + { + "id": "id_19", + "isCompleted": false, + "text": "ullam a voluptatem", + }, + { + "id": "id_20", + "isCompleted": true, + "text": "dolorum deserunt quis", + }, + ], "pageInfo": { "endCursor": "id_20", "hasNextPage": false, @@ -2431,6 +3449,28 @@ exports[`prisma-relay-cursor-connection string id returns the first 5 completed }, }, ], + "nodes": [ + { + "id": "id_04", + "isCompleted": true, + }, + { + "id": "id_05", + "isCompleted": true, + }, + { + "id": "id_06", + "isCompleted": true, + }, + { + "id": "id_08", + "isCompleted": true, + }, + { + "id": "id_09", + "isCompleted": true, + }, + ], "pageInfo": { "endCursor": "id_09", "hasNextPage": true, @@ -2485,6 +3525,33 @@ exports[`prisma-relay-cursor-connection string id returns the first 5 todos 1`] }, }, ], + "nodes": [ + { + "id": "id_01", + "isCompleted": false, + "text": "veritatis molestias qui", + }, + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + { + "id": "id_05", + "isCompleted": true, + "text": "voluptatem sint ipsam", + }, + ], "pageInfo": { "endCursor": "id_05", "hasNextPage": true, @@ -2539,6 +3606,33 @@ exports[`prisma-relay-cursor-connection string id returns the first 5 todos afte }, }, ], + "nodes": [ + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + { + "id": "id_05", + "isCompleted": true, + "text": "voluptatem sint ipsam", + }, + { + "id": "id_06", + "isCompleted": true, + "text": "ut sunt consequuntur", + }, + ], "pageInfo": { "endCursor": "id_06", "hasNextPage": true, @@ -2593,6 +3687,33 @@ exports[`prisma-relay-cursor-connection string id returns the first 5 todos afte }, }, ], + "nodes": [ + { + "id": "id_06", + "isCompleted": true, + "text": "ut sunt consequuntur", + }, + { + "id": "id_07", + "isCompleted": false, + "text": "accusamus aut labore", + }, + { + "id": "id_08", + "isCompleted": true, + "text": "et quo quia", + }, + { + "id": "id_09", + "isCompleted": true, + "text": "accusantium a excepturi", + }, + { + "id": "id_10", + "isCompleted": true, + "text": "deserunt rerum occaecati", + }, + ], "pageInfo": { "endCursor": "id_10", "hasNextPage": true, @@ -2647,6 +3768,33 @@ exports[`prisma-relay-cursor-connection string id returns the first 5 todos afte }, }, ], + "nodes": [ + { + "id": "id_16", + "isCompleted": true, + "text": "ut molestias veniam", + }, + { + "id": "id_17", + "isCompleted": true, + "text": "a placeat aperiam", + }, + { + "id": "id_18", + "isCompleted": true, + "text": "quos rerum aut", + }, + { + "id": "id_19", + "isCompleted": false, + "text": "ullam a voluptatem", + }, + { + "id": "id_20", + "isCompleted": true, + "text": "dolorum deserunt quis", + }, + ], "pageInfo": { "endCursor": "id_20", "hasNextPage": false, @@ -2693,6 +3841,28 @@ exports[`prisma-relay-cursor-connection string id returns the first 5 todos afte }, }, ], + "nodes": [ + { + "id": "id_17", + "isCompleted": true, + "text": "a placeat aperiam", + }, + { + "id": "id_18", + "isCompleted": true, + "text": "quos rerum aut", + }, + { + "id": "id_19", + "isCompleted": false, + "text": "ullam a voluptatem", + }, + { + "id": "id_20", + "isCompleted": true, + "text": "dolorum deserunt quis", + }, + ], "pageInfo": { "endCursor": "id_20", "hasNextPage": false, @@ -2706,6 +3876,7 @@ exports[`prisma-relay-cursor-connection string id returns the first 5 todos afte exports[`prisma-relay-cursor-connection string id returns the first 5 todos after the 20th todo 1`] = ` { "edges": [], + "nodes": [], "pageInfo": { "endCursor": undefined, "hasNextPage": false, @@ -2760,6 +3931,33 @@ exports[`prisma-relay-cursor-connection string id returns the last 5 todos 1`] = }, }, ], + "nodes": [ + { + "id": "id_16", + "isCompleted": true, + "text": "ut molestias veniam", + }, + { + "id": "id_17", + "isCompleted": true, + "text": "a placeat aperiam", + }, + { + "id": "id_18", + "isCompleted": true, + "text": "quos rerum aut", + }, + { + "id": "id_19", + "isCompleted": false, + "text": "ullam a voluptatem", + }, + { + "id": "id_20", + "isCompleted": true, + "text": "dolorum deserunt quis", + }, + ], "pageInfo": { "endCursor": "id_20", "hasNextPage": false, @@ -2773,6 +3971,7 @@ exports[`prisma-relay-cursor-connection string id returns the last 5 todos 1`] = exports[`prisma-relay-cursor-connection string id returns the last 5 todos before the 1st todo 1`] = ` { "edges": [], + "nodes": [], "pageInfo": { "endCursor": undefined, "hasNextPage": true, @@ -2819,6 +4018,28 @@ exports[`prisma-relay-cursor-connection string id returns the last 5 todos befor }, }, ], + "nodes": [ + { + "id": "id_01", + "isCompleted": false, + "text": "veritatis molestias qui", + }, + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + ], "pageInfo": { "endCursor": "id_04", "hasNextPage": true, @@ -2873,6 +4094,33 @@ exports[`prisma-relay-cursor-connection string id returns the last 5 todos befor }, }, ], + "nodes": [ + { + "id": "id_01", + "isCompleted": false, + "text": "veritatis molestias qui", + }, + { + "id": "id_02", + "isCompleted": false, + "text": "occaecati a dolor", + }, + { + "id": "id_03", + "isCompleted": false, + "text": "ut enim quia", + }, + { + "id": "id_04", + "isCompleted": true, + "text": "ipsam ipsam corrupti", + }, + { + "id": "id_05", + "isCompleted": true, + "text": "voluptatem sint ipsam", + }, + ], "pageInfo": { "endCursor": "id_05", "hasNextPage": true, @@ -2927,6 +4175,33 @@ exports[`prisma-relay-cursor-connection string id returns the last 5 todos befor }, }, ], + "nodes": [ + { + "id": "id_11", + "isCompleted": false, + "text": "unde et quasi", + }, + { + "id": "id_12", + "isCompleted": false, + "text": "et autem sapiente", + }, + { + "id": "id_13", + "isCompleted": false, + "text": "deleniti fuga et", + }, + { + "id": "id_14", + "isCompleted": true, + "text": "ea molestiae similique", + }, + { + "id": "id_15", + "isCompleted": false, + "text": "doloribus ea aut", + }, + ], "pageInfo": { "endCursor": "id_15", "hasNextPage": true, @@ -3006,6 +4281,28 @@ exports[`prisma-relay-cursor-connection unique field returns the first 5 users a }, }, ], + "nodes": [ + { + "email": "user2@email.com", + "id": 2, + }, + { + "email": "user3@email.com", + "id": 3, + }, + { + "email": "user4@email.com", + "id": 4, + }, + { + "email": "user5@email.com", + "id": 5, + }, + { + "email": "user6@email.com", + "id": 6, + }, + ], "pageInfo": { "endCursor": "eyJlbWFpbCI6InVzZXI2QGVtYWlsLmNvbSJ9", "hasNextPage": true, @@ -3055,6 +4352,28 @@ exports[`prisma-relay-cursor-connection unique field returns the first 5 users a }, }, ], + "nodes": [ + { + "email": "user6@email.com", + "id": 6, + }, + { + "email": "user7@email.com", + "id": 7, + }, + { + "email": "user8@email.com", + "id": 8, + }, + { + "email": "user9@email.com", + "id": 9, + }, + { + "email": "user10@email.com", + "id": 10, + }, + ], "pageInfo": { "endCursor": "eyJlbWFpbCI6InVzZXIxMEBlbWFpbC5jb20ifQ==", "hasNextPage": true, @@ -3104,6 +4423,28 @@ exports[`prisma-relay-cursor-connection unique field returns the first 5 users a }, }, ], + "nodes": [ + { + "email": "user16@email.com", + "id": 16, + }, + { + "email": "user17@email.com", + "id": 17, + }, + { + "email": "user18@email.com", + "id": 18, + }, + { + "email": "user19@email.com", + "id": 19, + }, + { + "email": "user20@email.com", + "id": 20, + }, + ], "pageInfo": { "endCursor": "eyJlbWFpbCI6InVzZXIyMEBlbWFpbC5jb20ifQ==", "hasNextPage": false, @@ -3146,6 +4487,24 @@ exports[`prisma-relay-cursor-connection unique field returns the first 5 users a }, }, ], + "nodes": [ + { + "email": "user17@email.com", + "id": 17, + }, + { + "email": "user18@email.com", + "id": 18, + }, + { + "email": "user19@email.com", + "id": 19, + }, + { + "email": "user20@email.com", + "id": 20, + }, + ], "pageInfo": { "endCursor": "eyJlbWFpbCI6InVzZXIyMEBlbWFpbC5jb20ifQ==", "hasNextPage": false, @@ -3159,6 +4518,7 @@ exports[`prisma-relay-cursor-connection unique field returns the first 5 users a exports[`prisma-relay-cursor-connection unique field returns the first 5 users after the 20th user 1`] = ` { "edges": [], + "nodes": [], "pageInfo": { "endCursor": undefined, "hasNextPage": false, @@ -3172,6 +4532,7 @@ exports[`prisma-relay-cursor-connection unique field returns the first 5 users a exports[`prisma-relay-cursor-connection unique field returns the last 5 users before the 1st user 1`] = ` { "edges": [], + "nodes": [], "pageInfo": { "endCursor": undefined, "hasNextPage": true, @@ -3214,6 +4575,24 @@ exports[`prisma-relay-cursor-connection unique field returns the last 5 users be }, }, ], + "nodes": [ + { + "email": "user1@email.com", + "id": 1, + }, + { + "email": "user2@email.com", + "id": 2, + }, + { + "email": "user3@email.com", + "id": 3, + }, + { + "email": "user4@email.com", + "id": 4, + }, + ], "pageInfo": { "endCursor": "eyJlbWFpbCI6InVzZXI0QGVtYWlsLmNvbSJ9", "hasNextPage": true, @@ -3263,6 +4642,28 @@ exports[`prisma-relay-cursor-connection unique field returns the last 5 users be }, }, ], + "nodes": [ + { + "email": "user1@email.com", + "id": 1, + }, + { + "email": "user2@email.com", + "id": 2, + }, + { + "email": "user3@email.com", + "id": 3, + }, + { + "email": "user4@email.com", + "id": 4, + }, + { + "email": "user5@email.com", + "id": 5, + }, + ], "pageInfo": { "endCursor": "eyJlbWFpbCI6InVzZXI1QGVtYWlsLmNvbSJ9", "hasNextPage": true, @@ -3312,6 +4713,28 @@ exports[`prisma-relay-cursor-connection unique field returns the last 5 users be }, }, ], + "nodes": [ + { + "email": "user11@email.com", + "id": 11, + }, + { + "email": "user12@email.com", + "id": 12, + }, + { + "email": "user13@email.com", + "id": 13, + }, + { + "email": "user14@email.com", + "id": 14, + }, + { + "email": "user15@email.com", + "id": 15, + }, + ], "pageInfo": { "endCursor": "eyJlbWFpbCI6InVzZXIxNUBlbWFpbC5jb20ifQ==", "hasNextPage": true, diff --git a/tests/index.spec.ts b/tests/index.spec.ts index 2db4d789..d70f9944 100644 --- a/tests/index.spec.ts +++ b/tests/index.spec.ts @@ -96,6 +96,15 @@ describe('prisma-relay-cursor-connection', () => { // @ts-expect-error Not selected field result.edges[0].node.text + + // Test that the return types work via TS + result.nodes[0].isCompleted + + // @ts-expect-error Typo in selected field + result.nodes[0].isCompletedd + + // @ts-expect-error Not selected field + result.nodes[0].text }) }) @@ -434,6 +443,9 @@ describe('prisma-relay-cursor-connection', () => { // Test that the extraEdgeField return type work via TS result.edges[0]?.extraEdgeField + + // Test that the node.extraNodeField return types work via TS + result.nodes[0]?.extraNodeField }) })