From 7ab70b8484abc332585b06f8e5f39cc46f10d7f8 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 30 Aug 2018 15:41:08 +0200 Subject: [PATCH] Update relay-runtime types --- package-lock.json | 8 ++--- package.json | 2 +- src/core/client/framework/helpers/getMe.ts | 4 --- .../lib/relay/commitMutationPromise.ts | 18 +++++------ src/core/client/stream/components/App.tsx | 2 +- .../PermalinkButton/PermalinkButton.tsx | 1 + .../containers/PostCommentFormContainer.tsx | 3 +- .../stream/containers/ReplyListContainer.tsx | 2 +- .../containers/StreamContainer.spec.tsx | 2 ++ .../stream/mutations/CreateCommentMutation.ts | 30 +++++++------------ .../server/graph/tenant/schema/schema.graphql | 2 +- 11 files changed, 32 insertions(+), 42 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7130b63f3..11b85ab82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1342,9 +1342,9 @@ } }, "@coralproject/rte": { - "version": "0.10.6", - "resolved": "https://registry.npmjs.org/@coralproject/rte/-/rte-0.10.6.tgz", - "integrity": "sha512-oUK/KSw28AkmpX5D8v1IkQT0iIxKxPmSG0euTFgqEthSgnAUQgoOmQengaR/nsS9zE31KPbbWMIAzH0aN/YwNA==", + "version": "0.10.9", + "resolved": "https://registry.npmjs.org/@coralproject/rte/-/rte-0.10.9.tgz", + "integrity": "sha512-0K+bc3JaOhjgJJ91uupev4EmSoldd/IizfjRgAQ8LbZjRc3pWprzIBhoTMChApBzz7eI9DUfw2ULg5muziV8BA==", "dev": true, "requires": { "bowser": "^1.0.0", @@ -2107,7 +2107,7 @@ "dev": true }, "@types/relay-runtime": { - "version": "github:coralproject/patched#ba8d413696e97b4f67450de3525cc319b9980cba", + "version": "github:coralproject/patched#c9a2387f6d32f092b9c75ddfca92d1856d2b41f6", "from": "github:coralproject/patched#types/relay-runtime", "dev": true }, diff --git a/package.json b/package.json index f4921415f..6b41d9457 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@babel/polyfill": "7.0.0-beta.49", "@babel/preset-env": "7.0.0-beta.49", "@babel/preset-react": "7.0.0-beta.49", - "@coralproject/rte": "^0.10.6", + "@coralproject/rte": "^0.10.9", "@types/bcryptjs": "^2.4.1", "@types/bunyan": "^1.8.4", "@types/case-sensitive-paths-webpack-plugin": "^2.1.2", diff --git a/src/core/client/framework/helpers/getMe.ts b/src/core/client/framework/helpers/getMe.ts index a8ecbdc7a..07eeb5952 100644 --- a/src/core/client/framework/helpers/getMe.ts +++ b/src/core/client/framework/helpers/getMe.ts @@ -1,7 +1,3 @@ -declare module "relay-runtime" { - export const ROOT_ID: string; -} - import { Environment, ROOT_ID } from "relay-runtime"; export default function getMe(environment: Environment) { diff --git a/src/core/client/framework/lib/relay/commitMutationPromise.ts b/src/core/client/framework/lib/relay/commitMutationPromise.ts index 97fb23088..b94fd7dde 100644 --- a/src/core/client/framework/lib/relay/commitMutationPromise.ts +++ b/src/core/client/framework/lib/relay/commitMutationPromise.ts @@ -1,5 +1,5 @@ import { commitMutation } from "react-relay"; -import { Environment, MutationConfig } from "relay-runtime"; +import { Environment, MutationConfig, OperationBase } from "relay-runtime"; import { Omit } from "talk-framework/types"; @@ -7,8 +7,8 @@ import { Omit } from "talk-framework/types"; * Like `MutationConfig` but omits `onCompleted` and `onError` * because we are going to use a Promise API. */ -export type MutationPromiseConfig = Omit< - MutationConfig, +export type MutationPromiseConfig = Omit< + MutationConfig, "onCompleted" | "onError" >; @@ -27,10 +27,10 @@ function getPayload(response: { [key: string]: any }): any { * and errors are wrapped inside of application specific * error instances. */ -export async function commitMutationPromiseNormalized( +export async function commitMutationPromiseNormalized( environment: Environment, - config: MutationPromiseConfig -): Promise { + config: MutationPromiseConfig +): Promise { try { const response = await commitMutationPromise(environment, config); return getPayload(response); @@ -42,10 +42,10 @@ export async function commitMutationPromiseNormalized( /** * Like `commitMutation` of the Relay API but returns a Promise. */ -export function commitMutationPromise( +export function commitMutationPromise( environment: Environment, - config: MutationPromiseConfig -): Promise { + config: MutationPromiseConfig +): Promise { return new Promise((resolve, reject) => { commitMutation(environment, { ...config, diff --git a/src/core/client/stream/components/App.tsx b/src/core/client/stream/components/App.tsx index a09c49149..b7d2d09d9 100644 --- a/src/core/client/stream/components/App.tsx +++ b/src/core/client/stream/components/App.tsx @@ -2,9 +2,9 @@ import * as React from "react"; import { StatelessComponent } from "react"; import { Flex } from "talk-ui/components"; + import PermalinkViewQuery from "../queries/PermalinkViewQuery"; import StreamQuery from "../queries/StreamQuery"; - import * as styles from "./App.css"; export interface AppProps { diff --git a/src/core/client/stream/components/PermalinkButton/PermalinkButton.tsx b/src/core/client/stream/components/PermalinkButton/PermalinkButton.tsx index 12540c1d3..cf0fad56c 100644 --- a/src/core/client/stream/components/PermalinkButton/PermalinkButton.tsx +++ b/src/core/client/stream/components/PermalinkButton/PermalinkButton.tsx @@ -1,5 +1,6 @@ import { Localized } from "fluent-react/compat"; import React from "react"; + import { oncePerFrame } from "talk-common/utils"; import { Button, diff --git a/src/core/client/stream/containers/PostCommentFormContainer.tsx b/src/core/client/stream/containers/PostCommentFormContainer.tsx index bf4ab8cf9..6398025eb 100644 --- a/src/core/client/stream/containers/PostCommentFormContainer.tsx +++ b/src/core/client/stream/containers/PostCommentFormContainer.tsx @@ -1,4 +1,4 @@ -import React, { Component } from "react"; +import React, { Component, ReactNode } from "react"; import { BadUserInputError } from "talk-framework/lib/errors"; import { PropTypesOf } from "talk-framework/types"; @@ -11,6 +11,7 @@ import { CreateCommentMutation, withCreateCommentMutation } from "../mutations"; interface InnerProps { createComment: CreateCommentMutation; assetID: string; + children?: ReactNode; } class PostCommentFormContainer extends Component { diff --git a/src/core/client/stream/containers/ReplyListContainer.tsx b/src/core/client/stream/containers/ReplyListContainer.tsx index 447090289..4ee7165e6 100644 --- a/src/core/client/stream/containers/ReplyListContainer.tsx +++ b/src/core/client/stream/containers/ReplyListContainer.tsx @@ -23,7 +23,7 @@ export class ReplyListContainer extends React.Component { public render() { if ( - !this.props.comment.replies == null || + this.props.comment.replies == null || this.props.comment.replies.edges.length === 0 ) { return null; diff --git a/src/core/client/stream/containers/StreamContainer.spec.tsx b/src/core/client/stream/containers/StreamContainer.spec.tsx index 411bf518a..531c74970 100644 --- a/src/core/client/stream/containers/StreamContainer.spec.tsx +++ b/src/core/client/stream/containers/StreamContainer.spec.tsx @@ -20,6 +20,7 @@ it("renders correctly", () => { edges: [{ node: { id: "comment-1" } }, { node: { id: "comment-2" } }], }, }, + user: null, relay: { hasMore: noop, isLoading: noop, @@ -39,6 +40,7 @@ describe("when has more comments", () => { edges: [{ node: { id: "comment-1" } }, { node: { id: "comment-2" } }], }, }, + user: null, relay: { hasMore: () => true, isLoading: () => false, diff --git a/src/core/client/stream/mutations/CreateCommentMutation.ts b/src/core/client/stream/mutations/CreateCommentMutation.ts index 0c25e2ce0..0482fd238 100644 --- a/src/core/client/stream/mutations/CreateCommentMutation.ts +++ b/src/core/client/stream/mutations/CreateCommentMutation.ts @@ -9,13 +9,10 @@ import { } from "talk-framework/lib/relay"; import { Omit } from "talk-framework/types"; -import { - CreateCommentMutationResponse, - CreateCommentMutationVariables, -} from "talk-stream/__generated__/CreateCommentMutation.graphql"; +import { CreateCommentMutation } from "talk-stream/__generated__/CreateCommentMutation.graphql"; export type CreateCommentInput = Omit< - CreateCommentMutationVariables["input"], + CreateCommentMutation["variables"]["input"], "clientMutationId" >; @@ -26,8 +23,12 @@ const mutation = graphql` cursor node { id - ...CommentContainer - ...ReplyListContainer_comment + author { + id + username + } + body + createdAt } } clientMutationId @@ -40,10 +41,7 @@ let clientMutationId = 0; function commit(environment: Environment, input: CreateCommentInput) { const me = getMe(environment)!; const currentDate = new Date().toISOString(); - return commitMutationPromiseNormalized< - CreateCommentMutationResponse["createComment"], - CreateCommentMutationVariables - >(environment, { + return commitMutationPromiseNormalized(environment, { mutation, variables: { input: { @@ -63,14 +61,6 @@ function commit(environment: Environment, input: CreateCommentInput) { username: me.username, }, body: input.body, - replies: { - edges: [], - pageInfo: { - endCursor: null, - hasNextPage: false, - }, - }, - __typename: "Comment", }, }, clientMutationId: (clientMutationId++).toString(), @@ -100,4 +90,4 @@ export const withCreateCommentMutation = createMutationContainer( export type CreateCommentMutation = ( input: CreateCommentInput -) => Promise; +) => Promise; diff --git a/src/core/server/graph/tenant/schema/schema.graphql b/src/core/server/graph/tenant/schema/schema.graphql index e0684ae65..d32d6259f 100644 --- a/src/core/server/graph/tenant/schema/schema.graphql +++ b/src/core/server/graph/tenant/schema/schema.graphql @@ -577,7 +577,7 @@ type Comment { """ createdAt is the date in which the comment was created. """ - createdAt: Time + createdAt: Time! """ author is the User that authored the Comment.