1
- // TODO: This file is allllll copypasta (kind of)!
2
-
3
- import * as sourcegraph from 'sourcegraph'
1
+ import { queryGraphQL } from '../graphql'
4
2
import { createAggregateError } from './errors'
5
3
6
- async function queryGraphQL ( query : string , variables : any = { } ) {
7
- return sourcegraph . commands . executeCommand < any > ( 'queryGraphQL' , query , variables )
8
- }
9
-
10
4
const discussionCommentFieldsFragment = `
11
5
fragment DiscussionCommentFields on DiscussionComment {
12
6
id
@@ -21,7 +15,7 @@ const discussionCommentFieldsFragment = `
21
15
`
22
16
23
17
function discussionThreadFieldsFragment ( relativeRev ?: string ) : string {
24
- var relativeRevFields : string = ''
18
+ let relativeRevFields = ''
25
19
if ( relativeRev ) {
26
20
relativeRevFields = `
27
21
relativePath(rev: $relativeRev)
@@ -84,11 +78,11 @@ function discussionThreadFieldsFragment(relativeRev?: string): string {
84
78
*
85
79
* @return Promise that emits the new discussion thread.
86
80
*/
87
- async function createThread (
81
+ export async function createThread (
88
82
input : SourcegraphGQL . IDiscussionThreadCreateInput ,
89
- relativeRev : string = ''
83
+ relativeRev = ''
90
84
) : Promise < SourcegraphGQL . IDiscussionThread > {
91
- let { data, errors } = await queryGraphQL (
85
+ const { data, errors } = await queryGraphQL (
92
86
`
93
87
mutation CreateThread($input: DiscussionThreadCreateInput!, $relativeRev: String!) {
94
88
discussions {
@@ -125,7 +119,7 @@ export async function fetchDiscussionThreads(opts: {
125
119
relativeRev ?: string
126
120
} ) : Promise < SourcegraphGQL . IDiscussionThreadConnection > {
127
121
opts . relativeRev = opts . relativeRev || ''
128
- let { data, errors } = await queryGraphQL (
122
+ const { data, errors } = await queryGraphQL (
129
123
`
130
124
query DiscussionThreads(
131
125
$first: Int
@@ -175,9 +169,9 @@ export async function fetchDiscussionThreads(opts: {
175
169
*/
176
170
export async function fetchDiscussionThreadAndComments (
177
171
threadID : string ,
178
- relativeRev : string = ''
172
+ relativeRev = ''
179
173
) : Promise < SourcegraphGQL . IDiscussionThread > {
180
- let { data, errors } = await queryGraphQL (
174
+ const { data, errors } = await queryGraphQL (
181
175
`
182
176
query DiscussionThreadComments($threadID: ID!, $relativeRev: String!) {
183
177
discussionThreads(threadID: $threadID) {
@@ -217,9 +211,9 @@ export async function fetchDiscussionThreadAndComments(
217
211
export async function addCommentToThread (
218
212
threadID : string ,
219
213
contents : string ,
220
- relativeRev : string = ''
214
+ relativeRev = ''
221
215
) : Promise < SourcegraphGQL . IDiscussionThread > {
222
- let { data, errors } = await queryGraphQL (
216
+ const { data, errors } = await queryGraphQL (
223
217
`
224
218
mutation AddCommentToThread($threadID: ID!, $contents: String!, $relativeRev: String!) {
225
219
discussions {
@@ -251,7 +245,7 @@ export async function addCommentToThread(
251
245
* @return Promise that emits the HTML string, which is already sanitized and escaped and thus is always safe to render.
252
246
*/
253
247
export async function renderMarkdown ( markdown : string , options ?: SourcegraphGQL . IMarkdownOptions ) : Promise < string > {
254
- let { data, errors } = await queryGraphQL (
248
+ const { data, errors } = await queryGraphQL (
255
249
`
256
250
query RenderMarkdown($markdown: String!, $options: MarkdownOptions) {
257
251
renderMarkdown(markdown: $markdown, options: $options)
0 commit comments