[CORL 133] API Review (#2197)

* refactor: removed unused subscription code

* refactor: removed management api's

* refactor: cleanup of connections

* refactor: refactored comments edge

* refactor: simplified connection resolving

* feat: added story connection edge

* fix: added story index

* feat: added user pagination and user edge

* fix: added filter to comment query

* fix: removed unused resolvers

* fix: creating a comment reply should require auth

* refactor: cleanup of graph files

* feat: removed display name, made username non-unique

* fix: fixed tests

* fix: fixed tests

* fix: added more api docs

* fix: fixed bug with installer

* refactor: fixes and updates

* fix: added linting for graphql, fixed schema

* feat: added docker build tests

* fix: upped output timeout

* fix: fixed stacktraces in production builds

* fix: removed `git add`

- `git add` was causing issues with
    partial staged changs on files

* feat: improved error messaging for auth

* refactor: cleaned up queue names

* fix: merge error
This commit is contained in:
Wyatt Johnson
2019-03-12 15:12:21 +01:00
committed by Kiwi
parent 37959f9398
commit d37333be89
125 changed files with 1269 additions and 1536 deletions
+16 -53
View File
@@ -15,10 +15,11 @@ import {
import {
Connection,
createConnection,
getPageInfo,
doesNotContainNull,
nodesToEdges,
NodeToCursorTransformer,
OrderedConnectionInput,
resolveConnection,
} from "talk-server/models/helpers/connection";
import Query, {
createConnectionOrderVariants,
@@ -123,6 +124,11 @@ export interface Comment extends TenantResource {
*/
replyCount: number;
/**
* metadata stores the deep Comment properties.
*/
metadata?: Record<string, any>;
/**
* createdAt is the date that this Comment was created.
*/
@@ -133,11 +139,6 @@ export interface Comment extends TenantResource {
* undefined, this Comment is not deleted.
*/
deletedAt?: Date;
/**
* metadata stores the deep Comment properties.
*/
metadata?: Record<string, any>;
}
export async function createCommentIndexes(mongo: Db) {
@@ -550,6 +551,7 @@ export async function retrieveCommentParentsConnection(
return {
edges: [{ node: parent, cursor: 1 }],
nodes: [parent],
pageInfo: {
hasNextPage: false,
hasPreviousPage: comment.grandparentIDs.length > 0,
@@ -566,29 +568,26 @@ export async function retrieveCommentParentsConnection(
const parentIDSubset = parentIDs.slice(skip, skip + limit);
// Retrieve the parents via the subset list.
const parents = await retrieveManyComments(mongo, tenantID, parentIDSubset);
const nodes = await retrieveManyComments(mongo, tenantID, parentIDSubset);
// Loop over the list to ensure that none of the entries is null (indicating
// that there was a misplaced parent). We can assert the type here because we
// will throw an error and abort if one of the comments are null.
parents.forEach(parentComment => {
if (!parentComment) {
// TODO: (wyattjoh) replace with a better error.
throw new Error("parent id specified does not exist");
}
return true;
});
if (!doesNotContainNull(nodes)) {
// TODO: (wyattjoh) replace with a better error.
throw new Error("parent id specified does not exist");
}
const edges = nodesToEdges(
// We can't have a null parent after the forEach filter above.
parents as Array<Readonly<Comment>>,
nodes,
(_, index) => index + skip + 1
).reverse();
// Return the resolved connection.
return {
edges,
nodes,
pageInfo: {
hasNextPage: false,
hasPreviousPage: parentIDs.length > limit + skip,
@@ -721,44 +720,8 @@ async function retrieveConnection(
// Apply some sorting options.
applyInputToQuery(input, query);
// We load one more than the limit so we can determine if there is
// another page of entries. This gets trimmed off below after we've checked to
// see if this constitutes another page of edges.
query.first(input.first + 1);
// Get the cursor.
const cursor = await query.exec();
// Get the comments from the cursor.
const nodes = await cursor.toArray();
// Return a connection.
return convertNodesToConnection(input, nodes);
}
export function convertNodesToConnection(
input: CommentConnectionInput,
nodes: Array<Readonly<Comment>>
) {
// Convert the nodes to edges (which will include the extra edge we don't need
// if there is more results).
const edges = nodesToEdges(nodes, cursorGetterFactory(input));
// Get the pageInfo for the connection. We will use this to also determine if
// we need to trim off the extra edge that we requested by comparing its
// hasNextPage parameter.
const pageInfo = getPageInfo(input, edges);
if (pageInfo.hasNextPage) {
// Because this means that we got one more than expected, we should trim off
// the extra edge that was retrieved.
edges.splice(input.first, 1);
}
// Return the connection.
return {
edges,
pageInfo,
};
return resolveConnection(query, input, cursorGetterFactory(input));
}
function applyInputToQuery(