From f5e0c6163d18926b40a9e928306296b59be41b7b Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 6 Sep 2018 00:14:47 +0200 Subject: [PATCH] Return null cursor when creating comment --- src/core/client/stream/test/postComment.spec.tsx | 2 +- src/core/client/stream/test/postReply.spec.tsx | 2 +- src/core/server/graph/tenant/resolvers/mutation.ts | 7 +++++-- src/core/server/graph/tenant/schema/schema.graphql | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/client/stream/test/postComment.spec.tsx b/src/core/client/stream/test/postComment.spec.tsx index 2e2f4c405..3a93bc5ff 100644 --- a/src/core/client/stream/test/postComment.spec.tsx +++ b/src/core/client/stream/test/postComment.spec.tsx @@ -39,7 +39,7 @@ beforeEach(() => { .returns({ // TODO: add a type assertion here to ensure that if the type changes, that the test will fail edge: { - cursor: "2018-07-06T18:24:00.000Z", + cursor: null, node: { id: "comment-x", author: users[0], diff --git a/src/core/client/stream/test/postReply.spec.tsx b/src/core/client/stream/test/postReply.spec.tsx index a3b108804..c22a041dd 100644 --- a/src/core/client/stream/test/postReply.spec.tsx +++ b/src/core/client/stream/test/postReply.spec.tsx @@ -39,7 +39,7 @@ beforeEach(() => { }) .returns({ edge: { - cursor: "2018-07-06T18:24:00.000Z", + cursor: null, node: { id: "comment-x", author: users[0], diff --git a/src/core/server/graph/tenant/resolvers/mutation.ts b/src/core/server/graph/tenant/resolvers/mutation.ts index 8f96079ff..5b7c65dc4 100644 --- a/src/core/server/graph/tenant/resolvers/mutation.ts +++ b/src/core/server/graph/tenant/resolvers/mutation.ts @@ -9,8 +9,11 @@ const Mutation: GQLMutationTypeResolver = { const comment = await ctx.mutators.Comment.create(input); return { edge: { - // FIXME: (wyattjoh) when we're using a replies/respect sort, it is index based instead of date based, needs some work! - cursor: comment.created_at, + // (cvle) + // Depending on the sort we can't determine the accurate cursor + // in a performant way, so we return null instead. + // It seems that Relay does not directly use this value... + cursor: null, node: comment, }, clientMutationId: input.clientMutationId, diff --git a/src/core/server/graph/tenant/schema/schema.graphql b/src/core/server/graph/tenant/schema/schema.graphql index 79d9a73a8..dc689f403 100644 --- a/src/core/server/graph/tenant/schema/schema.graphql +++ b/src/core/server/graph/tenant/schema/schema.graphql @@ -679,7 +679,7 @@ type CommentEdge { """ """ - cursor: Cursor! + cursor: Cursor } """