From 99908d30591d47ae0f11ca5f0e6f2cb7f28b51f6 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Sun, 6 Nov 2022 20:48:55 -0500 Subject: [PATCH 1/4] chore(graphql): add operation names and extract variables --- .../AllTargetsArchivedRecordingsTable.tsx | 38 +++++++------- src/app/RecordingMetadata/BulkEditLabels.tsx | 18 ++++--- .../Recordings/ArchivedRecordingsTable.tsx | 21 +++++--- src/app/Shared/Services/Api.service.tsx | 52 ++++++++++++------- 4 files changed, 75 insertions(+), 54 deletions(-) diff --git a/src/app/Archives/AllTargetsArchivedRecordingsTable.tsx b/src/app/Archives/AllTargetsArchivedRecordingsTable.tsx index 09d23f9bc..9b9cfce44 100644 --- a/src/app/Archives/AllTargetsArchivedRecordingsTable.tsx +++ b/src/app/Archives/AllTargetsArchivedRecordingsTable.tsx @@ -113,22 +113,21 @@ export const AllTargetsArchivedRecordingsTable: React.FunctionComponent( - ` - query { - targetNodes { - target { - serviceUri - alias - } - recordings { - archived { - aggregate { - count - } - } - } - } - }` + `query AllTargetsArchives { + targetNodes { + target { + serviceUri + alias + } + recordings { + archived { + aggregate { + count + } + } + } + } + }` ) .pipe(map((v) => v.data.targetNodes)) .subscribe(handleTargetsAndCounts) @@ -141,8 +140,8 @@ export const AllTargetsArchivedRecordingsTable: React.FunctionComponent( ` - query { - targetNodes(filter: { name: "${target.connectUrl}" }) { + query GetArchiveCountForTarget($connectUrl: String) { + targetNodes(filter: { name: $connectUrl }) { recordings { archived { aggregate { @@ -151,7 +150,8 @@ export const AllTargetsArchivedRecordingsTable: React.FunctionComponent setCounts((old) => { diff --git a/src/app/RecordingMetadata/BulkEditLabels.tsx b/src/app/RecordingMetadata/BulkEditLabels.tsx index 03e32f53b..1d76c1f74 100644 --- a/src/app/RecordingMetadata/BulkEditLabels.tsx +++ b/src/app/RecordingMetadata/BulkEditLabels.tsx @@ -169,9 +169,8 @@ export const BulkEditLabels: React.FunctionComponent = (pro observable = props.isUploadsTable ? context.api .graphql( - ` - query { - archivedRecordings(filter: { sourceTarget: "${UPLOADS_SUBDIRECTORY}" }) { + `query GetUploadedRecordings($filter: ArchivedRecordingFilterInput) { + archivedRecordings(filter: $filter) { data { name downloadUrl @@ -181,7 +180,8 @@ export const BulkEditLabels: React.FunctionComponent = (pro } } } - }` + }`, + { filter: { sourceTarget: UPLOADS_SUBDIRECTORY } } ) .pipe( map((v) => v.data.archivedRecordings.data as ArchivedRecording[]), @@ -190,9 +190,9 @@ export const BulkEditLabels: React.FunctionComponent = (pro : context.target.target().pipe( filter((target) => target !== NO_TARGET), concatMap((target) => - context.api.graphql(` - query { - targetNodes(filter: { name: "${target.connectUrl}" }) { + context.api.graphql( + `query GetActiveRecordingsForTarget($connectUrl: String) { + targetNodes(filter: { name: $connectUrl }) { recordings { archived { data { @@ -206,7 +206,9 @@ export const BulkEditLabels: React.FunctionComponent = (pro } } } - }`) + }`, + { connectUrl: target.connectUrl } + ) ), map((v) => v.data.targetNodes[0].recordings.archived.data as ArchivedRecording[]), first() diff --git a/src/app/Recordings/ArchivedRecordingsTable.tsx b/src/app/Recordings/ArchivedRecordingsTable.tsx index d93d062de..bda571c4b 100644 --- a/src/app/Recordings/ArchivedRecordingsTable.tsx +++ b/src/app/Recordings/ArchivedRecordingsTable.tsx @@ -156,9 +156,10 @@ export const ArchivedRecordingsTable: React.FunctionComponent { - return context.api.graphql(` - query { - archivedRecordings(filter: { sourceTarget: "${connectUrl}" }) { + return context.api.graphql( + ` + query ArchivedRecordingsForTarget($connectUrl: String) { + archivedRecordings(filter: { sourceTarget: $connectUrl }) { data { name downloadUrl @@ -169,15 +170,17 @@ export const ArchivedRecordingsTable: React.FunctionComponent { - return context.api.graphql(` - query { - archivedRecordings(filter: { sourceTarget: "${UPLOADS_SUBDIRECTORY}" }) { + return context.api.graphql( + `query UploadedRecordings($input: ArchivedRecordingFilterInput){ + archivedRecordings(filter: $input) { data { name downloadUrl @@ -188,7 +191,9 @@ export const ArchivedRecordingsTable: React.FunctionComponent { diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index 86874b046..056974955 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -593,10 +593,17 @@ export class ApiService { ); } - graphql(query: string): Observable { + graphql(query: string, variables?: Object): Observable { const headers = new Headers(); - headers.set('Content-Type', 'application/graphql'); - return this.sendRequest('v2.2', 'graphql', { method: 'POST', body: query, headers }).pipe( + headers.set('Content-Type', 'application/json'); + return this.sendRequest('v2.2', 'graphql', { + method: 'POST', + body: JSON.stringify({ + query: query.replace(/[\s]+/g, ' '), + variables, + }), + headers, + }).pipe( map((resp) => resp.json()), concatMap(from), first() @@ -749,13 +756,14 @@ export class ApiService { filter((target) => target !== NO_TARGET), first(), concatMap((target) => - this.graphql(` - query { - targetNodes(filter: { name: "${target.connectUrl}" }) { + this.graphql( + ` + query PostRecordingMetadata($connectUrl: String, $recordingName: String, $labels: String) { + targetNodes(filter: { name: $connectUrl }) { recordings { - archived(filter: { name: "${recordingName}" }) { + archived(filter: { name: $recordingName }) { data { - doPutMetadata(metadata: { labels: ${this.stringifyRecordingLabels(labels)}}) { + doPutMetadata(metadata: { labels: $labels }) { metadata { labels } @@ -764,7 +772,9 @@ export class ApiService { } } } - }`) + }`, + { connectUrl: target.connectUrl, recordingName, labels: this.stringifyRecordingLabels(labels) } + ) ), map((v) => v.data.targetNodes[0].recordings.archived as ArchivedRecording[]) ); @@ -773,17 +783,18 @@ export class ApiService { postUploadedRecordingMetadata(recordingName: string, labels: RecordingLabel[]): Observable { return this.graphql( ` - query { - archivedRecordings(filter: {sourceTarget: "${UPLOADS_SUBDIRECTORY}", name: "${recordingName}" }) { + query PostUploadedRecordingMetadata($connectUrl: String, $recordingName: String, $labels: String){ + archivedRecordings(filter: {sourceTarget: $connectUrl, name: $recordingName }) { data { - doPutMetadata(metadata: { labels: ${this.stringifyRecordingLabels(labels)}}) { + doPutMetadata(metadata: { labels: $labels }) { metadata { labels } } } } - }` + }`, + { connectUrl: UPLOADS_SUBDIRECTORY, recordingName, labels: this.stringifyRecordingLabels(labels) } ).pipe(map((v) => v.data.archivedRecordings.data as ArchivedRecording[])); } @@ -792,13 +803,14 @@ export class ApiService { filter((target) => target !== NO_TARGET), first(), concatMap((target) => - this.graphql(` - query { - targetNodes(filter: { name: "${target.connectUrl}" }) { + this.graphql( + ` + query PostActiveRecordingMetadataA($connectUrl: String, $recordingName: String, $labels: String) { + targetNodes(filter: { name: $connectUrl }) { recordings { - active(filter: { name: "${recordingName}" }) { + active(filter: { name: $recordingName }) { data { - doPutMetadata(metadata: { labels: ${this.stringifyRecordingLabels(labels)}}) { + doPutMetadata(metadata: { labels: $labels }) { metadata { labels } @@ -807,7 +819,9 @@ export class ApiService { } } } - }`) + }`, + { connectUrl: target.connectUrl, recordingName, labels: this.stringifyRecordingLabels(labels) } + ) ), map((v) => v.data.targetNodes[0].recordings.active as ActiveRecording[]) ); From 56f83c5250142fd03d90d8c31d84ef01bcc14c92 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Mon, 7 Nov 2022 14:51:25 -0500 Subject: [PATCH 2/4] rename GraphQL variable --- src/app/Recordings/ArchivedRecordingsTable.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/Recordings/ArchivedRecordingsTable.tsx b/src/app/Recordings/ArchivedRecordingsTable.tsx index bda571c4b..6c0dab506 100644 --- a/src/app/Recordings/ArchivedRecordingsTable.tsx +++ b/src/app/Recordings/ArchivedRecordingsTable.tsx @@ -179,8 +179,8 @@ export const ArchivedRecordingsTable: React.FunctionComponent { return context.api.graphql( - `query UploadedRecordings($input: ArchivedRecordingFilterInput){ - archivedRecordings(filter: $input) { + `query UploadedRecordings($filter: ArchivedRecordingFilterInput){ + archivedRecordings(filter: $filter) { data { name downloadUrl @@ -192,7 +192,7 @@ export const ArchivedRecordingsTable: React.FunctionComponent Date: Mon, 7 Nov 2022 14:59:06 -0500 Subject: [PATCH 3/4] remove extra char --- src/app/Shared/Services/Api.service.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index 056974955..772870e51 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -805,7 +805,7 @@ export class ApiService { concatMap((target) => this.graphql( ` - query PostActiveRecordingMetadataA($connectUrl: String, $recordingName: String, $labels: String) { + query PostActiveRecordingMetadata($connectUrl: String, $recordingName: String, $labels: String) { targetNodes(filter: { name: $connectUrl }) { recordings { active(filter: { name: $recordingName }) { From 05d5aadf3bf9822d97e97f03d7dffe4ee42aa498 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Mon, 7 Nov 2022 15:30:38 -0500 Subject: [PATCH 4/4] remove Get prefix --- src/app/Archives/AllTargetsArchivedRecordingsTable.tsx | 2 +- src/app/RecordingMetadata/BulkEditLabels.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/Archives/AllTargetsArchivedRecordingsTable.tsx b/src/app/Archives/AllTargetsArchivedRecordingsTable.tsx index 9b9cfce44..549243e50 100644 --- a/src/app/Archives/AllTargetsArchivedRecordingsTable.tsx +++ b/src/app/Archives/AllTargetsArchivedRecordingsTable.tsx @@ -140,7 +140,7 @@ export const AllTargetsArchivedRecordingsTable: React.FunctionComponent( ` - query GetArchiveCountForTarget($connectUrl: String) { + query ArchiveCountForTarget($connectUrl: String) { targetNodes(filter: { name: $connectUrl }) { recordings { archived { diff --git a/src/app/RecordingMetadata/BulkEditLabels.tsx b/src/app/RecordingMetadata/BulkEditLabels.tsx index 1d76c1f74..473f85aa2 100644 --- a/src/app/RecordingMetadata/BulkEditLabels.tsx +++ b/src/app/RecordingMetadata/BulkEditLabels.tsx @@ -191,7 +191,7 @@ export const BulkEditLabels: React.FunctionComponent = (pro filter((target) => target !== NO_TARGET), concatMap((target) => context.api.graphql( - `query GetActiveRecordingsForTarget($connectUrl: String) { + `query ActiveRecordingsForTarget($connectUrl: String) { targetNodes(filter: { name: $connectUrl }) { recordings { archived {