mirror of
https://github.com/wassname/talk.git
synced 2026-08-14 12:50:17 +08:00
changed cursor to Cursor scalar type, changed SORT_ORDER
This commit is contained in:
@@ -312,7 +312,7 @@ const getCommentsByQuery = async ({user}, {ids, statuses, asset_id, parent_id, a
|
||||
}
|
||||
|
||||
if (cursor) {
|
||||
if (sort === 'REVERSE_CHRONOLOGICAL') {
|
||||
if (sort === 'DESC') {
|
||||
comments = comments.where({
|
||||
created_at: {
|
||||
$lt: cursor
|
||||
@@ -328,7 +328,7 @@ const getCommentsByQuery = async ({user}, {ids, statuses, asset_id, parent_id, a
|
||||
}
|
||||
|
||||
let query = comments
|
||||
.sort({created_at: sort === 'REVERSE_CHRONOLOGICAL' ? -1 : 1});
|
||||
.sort({created_at: sort === 'DESC' ? -1 : 1});
|
||||
if (limit) {
|
||||
query = query.limit(limit + 1);
|
||||
}
|
||||
@@ -363,7 +363,7 @@ const genRecentReplies = (context, ids) => {
|
||||
}
|
||||
}},
|
||||
|
||||
// sort these by their created at timestamp, CHRONOLOGICAL'y as these are
|
||||
// sort these by their created at timestamp, ASC'y as these are
|
||||
// replies
|
||||
{$sort: {
|
||||
created_at: 1
|
||||
@@ -413,7 +413,7 @@ const genRecentComments = (_, ids) => {
|
||||
}
|
||||
}},
|
||||
|
||||
// sort these by their created at timestamp, CHRONOLOGICAL'y as these are
|
||||
// sort these by their created at timestamp, ASC'y as these are
|
||||
// replies
|
||||
{$sort: {
|
||||
created_at: 1
|
||||
|
||||
@@ -36,7 +36,7 @@ const getUsersByQuery = ({user}, {ids, limit, cursor, statuses = null, sort}) =>
|
||||
}
|
||||
|
||||
if (cursor) {
|
||||
if (sort === 'REVERSE_CHRONOLOGICAL') {
|
||||
if (sort === 'DESC') {
|
||||
users = users.where({
|
||||
created_at: {
|
||||
$lt: cursor
|
||||
@@ -52,7 +52,7 @@ const getUsersByQuery = ({user}, {ids, limit, cursor, statuses = null, sort}) =>
|
||||
}
|
||||
|
||||
return users
|
||||
.sort({created_at: sort === 'REVERSE_CHRONOLOGICAL' ? -1 : 1})
|
||||
.sort({created_at: sort === 'DESC' ? -1 : 1})
|
||||
.limit(limit);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
const GraphQLScalarType = require('graphql').GraphQLScalarType;
|
||||
const Kind = require('graphql/language').Kind;
|
||||
|
||||
module.exports = new GraphQLScalarType({
|
||||
name: 'Cursor',
|
||||
description: 'Cursor represents a paginating cursor.',
|
||||
serialize(value) {
|
||||
if (value instanceof Date) {
|
||||
return value.toISOString();
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
parseValue(value) {
|
||||
if (typeof value === 'string') {
|
||||
return new Date(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
parseLiteral(ast) {
|
||||
switch (ast.kind) {
|
||||
case Kind.STRING:
|
||||
|
||||
// This handles an empty string.
|
||||
if (ast.value && ast.value.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Date(ast.value);
|
||||
default:
|
||||
return ast.value;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -5,8 +5,9 @@ const ActionSummary = require('./action_summary');
|
||||
const Action = require('./action');
|
||||
const AssetActionSummary = require('./asset_action_summary');
|
||||
const Asset = require('./asset');
|
||||
const Comment = require('./comment');
|
||||
const CommentStatusHistory = require('./comment_status_history');
|
||||
const Comment = require('./comment');
|
||||
const Cursor = require('./cursor');
|
||||
const Date = require('./date');
|
||||
const FlagActionSummary = require('./flag_action_summary');
|
||||
const FlagAction = require('./flag_action');
|
||||
@@ -31,8 +32,9 @@ let resolvers = {
|
||||
Action,
|
||||
AssetActionSummary,
|
||||
Asset,
|
||||
Comment,
|
||||
CommentStatusHistory,
|
||||
Comment,
|
||||
Cursor,
|
||||
Date,
|
||||
FlagActionSummary,
|
||||
FlagAction,
|
||||
|
||||
+13
-10
@@ -5,6 +5,9 @@
|
||||
# Date represented as an ISO8601 string.
|
||||
scalar Date
|
||||
|
||||
# Cursor represents a paginating cursor.
|
||||
scalar Cursor
|
||||
|
||||
################################################################################
|
||||
## Reliability
|
||||
################################################################################
|
||||
@@ -126,10 +129,10 @@ input UsersQuery {
|
||||
limit: Int = 10
|
||||
|
||||
# Skip results from the last created_at timestamp.
|
||||
cursor: Date
|
||||
cursor: Cursor
|
||||
|
||||
# Sort the results by created_at.
|
||||
sort: SORT_ORDER = REVERSE_CHRONOLOGICAL
|
||||
sort: SORT_ORDER = DESC
|
||||
}
|
||||
|
||||
# AssetsQuery allows teh ability to query assets by specific fields
|
||||
@@ -241,10 +244,10 @@ input CommentsQuery {
|
||||
limit: Int = 10
|
||||
|
||||
# Skip results from the last created_at timestamp.
|
||||
cursor: Date
|
||||
cursor: Cursor
|
||||
|
||||
# Sort the results by created_at.
|
||||
sort: SORT_ORDER = REVERSE_CHRONOLOGICAL
|
||||
sort: SORT_ORDER = DESC
|
||||
|
||||
# Filter by a specific tag name.
|
||||
tags: [String!]
|
||||
@@ -314,7 +317,7 @@ type Comment {
|
||||
recentReplies: [Comment!]
|
||||
|
||||
# the replies that were made to the comment.
|
||||
replies(sort: SORT_ORDER = CHRONOLOGICAL, limit: Int = 3, excludeIgnored: Boolean): CommentConnection!
|
||||
replies(sort: SORT_ORDER = ASC, limit: Int = 3, excludeIgnored: Boolean): CommentConnection!
|
||||
|
||||
# The count of replies on a comment.
|
||||
replyCount(excludeIgnored: Boolean): Int
|
||||
@@ -348,10 +351,10 @@ type CommentConnection {
|
||||
hasNextPage: Boolean!
|
||||
|
||||
# Cursor of first comment in subset.
|
||||
startCursor: Date
|
||||
startCursor: Cursor
|
||||
|
||||
# Cursor of last comment in subset.
|
||||
endCursor: Date
|
||||
endCursor: Cursor
|
||||
|
||||
# Subset of comments.
|
||||
nodes: [Comment!]!
|
||||
@@ -573,7 +576,7 @@ type Asset {
|
||||
# If `deep` is true, it will return comments of all depths,
|
||||
# otherwise only top-level comments are returned.
|
||||
comments(
|
||||
sort: SORT_ORDER = REVERSE_CHRONOLOGICAL,
|
||||
sort: SORT_ORDER = DESC,
|
||||
limit: Int = 10,
|
||||
excludeIgnored: Boolean,
|
||||
tags: [String!]
|
||||
@@ -652,10 +655,10 @@ type ValidationUserError implements UserError {
|
||||
enum SORT_ORDER {
|
||||
|
||||
# newest to oldest order.
|
||||
REVERSE_CHRONOLOGICAL
|
||||
DESC
|
||||
|
||||
# oldest to newer order.
|
||||
CHRONOLOGICAL
|
||||
ASC
|
||||
}
|
||||
|
||||
# All queries that can be executed.
|
||||
|
||||
Reference in New Issue
Block a user