Skip to content

Commit

Permalink
Add totalCount field to relay connection (#17)
Browse files Browse the repository at this point in the history
* add totalCount field to relay connection

* add totalCount to relay integration tests
  • Loading branch information
kdembler authored Sep 25, 2020
1 parent fb24f42 commit a9d9ac9
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions __tests__/gql/queries/relay-connection.gql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ query TestRelayConnection(
id
}
}
totalCount
pageInfo {
hasPreviousPage
hasNextPage
Expand Down
1 change: 1 addition & 0 deletions __tests__/gql/queries/relay-non-null-edges-connection.gql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ query TestNonNullEdgesRelayConnection(
id
}
}
totalCount
pageInfo {
hasPreviousPage
hasNextPage
Expand Down
1 change: 1 addition & 0 deletions __tests__/gql/queries/relay-non-null-nodes-connection.gql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ query TestNonNullNodesRelayConnection(
id
}
}
totalCount
pageInfo {
hasPreviousPage
hasNextPage
Expand Down
3 changes: 3 additions & 0 deletions __tests__/gql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,19 @@ type TestOption {

type TestRelayConnection {
edges: [TestRelayEdge]
totalCount: Int!
pageInfo: PageInfo!
}

type TestNonNullEdgesRelayConnection {
edges: [TestRelayEdge!]!
totalCount: Int!
pageInfo: PageInfo!
}

type TestNonNullNodesRelayConnection {
edges: [TestNonNullNodesRelayEdge]
totalCount: Int!
pageInfo: PageInfo!
}

Expand Down
4 changes: 4 additions & 0 deletions __tests__/integration/queries/relay-connection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe("Integration | queries | Relay connection", function () {
node: { id: "3" },
},
],
totalCount: 3,
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
Expand All @@ -55,6 +56,7 @@ describe("Integration | queries | Relay connection", function () {
node: { id: "1" },
},
],
totalCount: 1,
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
Expand All @@ -76,6 +78,7 @@ describe("Integration | queries | Relay connection", function () {
node: { id: "2" },
},
],
totalCount: 3,
pageInfo: {
hasPreviousPage: true,
hasNextPage: true,
Expand All @@ -97,6 +100,7 @@ describe("Integration | queries | Relay connection", function () {
node: { id: "2" },
},
],
totalCount: 3,
pageInfo: {
hasPreviousPage: true,
hasNextPage: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("Integration | queries | Relay connection (non-null edges)", function (
node: { id: "3" },
},
],
totalCount: 3,
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
Expand All @@ -60,6 +61,7 @@ describe("Integration | queries | Relay connection (non-null edges)", function (
node: { id: "1" },
},
],
totalCount: 1,
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
Expand All @@ -84,6 +86,7 @@ describe("Integration | queries | Relay connection (non-null edges)", function (
node: { id: "2" },
},
],
totalCount: 3,
pageInfo: {
hasPreviousPage: true,
hasNextPage: true,
Expand All @@ -108,6 +111,7 @@ describe("Integration | queries | Relay connection (non-null edges)", function (
node: { id: "2" },
},
],
totalCount: 3,
pageInfo: {
hasPreviousPage: true,
hasNextPage: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("Integration | queries | Relay connection (non-null edges and nodes)",
node: { id: "3" },
},
],
totalCount: 3,
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
Expand All @@ -60,6 +61,7 @@ describe("Integration | queries | Relay connection (non-null edges and nodes)",
node: { id: "1" },
},
],
totalCount: 1,
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
Expand All @@ -84,6 +86,7 @@ describe("Integration | queries | Relay connection (non-null edges and nodes)",
node: { id: "2" },
},
],
totalCount: 3,
pageInfo: {
hasPreviousPage: true,
hasNextPage: true,
Expand All @@ -108,6 +111,7 @@ describe("Integration | queries | Relay connection (non-null edges and nodes)",
node: { id: "2" },
},
],
totalCount: 3,
pageInfo: {
hasPreviousPage: true,
hasNextPage: true,
Expand Down
1 change: 1 addition & 0 deletions lib/resolvers/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export function resolveRelayConnection(obj, args, context, info, type) {
return {
edges,
pageInfo: getPageInfo(records, edges),
totalCount: records.length,
};
}

0 comments on commit a9d9ac9

Please sign in to comment.