Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(graphql): add operation names and extract variables #611

Merged
merged 4 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/app/Archives/AllTargetsArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,21 @@ export const AllTargetsArchivedRecordingsTable: React.FunctionComponent<AllTarge
addSubscription(
context.api
.graphql<any>(
`
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)
Expand All @@ -141,8 +140,8 @@ export const AllTargetsArchivedRecordingsTable: React.FunctionComponent<AllTarge
context.api
.graphql<any>(
`
query {
targetNodes(filter: { name: "${target.connectUrl}" }) {
query GetArchiveCountForTarget($connectUrl: String) {
targetNodes(filter: { name: $connectUrl }) {
recordings {
archived {
aggregate {
Expand All @@ -151,7 +150,8 @@ export const AllTargetsArchivedRecordingsTable: React.FunctionComponent<AllTarge
}
}
}
}`
}`,
{ connectUrl: target.connectUrl }
)
.subscribe((v) =>
setCounts((old) => {
Expand Down
18 changes: 10 additions & 8 deletions src/app/RecordingMetadata/BulkEditLabels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ export const BulkEditLabels: React.FunctionComponent<BulkEditLabelsProps> = (pro
observable = props.isUploadsTable
? context.api
.graphql<any>(
`
query {
archivedRecordings(filter: { sourceTarget: "${UPLOADS_SUBDIRECTORY}" }) {
`query GetUploadedRecordings($filter: ArchivedRecordingFilterInput) {
archivedRecordings(filter: $filter) {
data {
name
downloadUrl
Expand All @@ -181,7 +180,8 @@ export const BulkEditLabels: React.FunctionComponent<BulkEditLabelsProps> = (pro
}
}
}
}`
}`,
{ filter: { sourceTarget: UPLOADS_SUBDIRECTORY } }
)
.pipe(
map((v) => v.data.archivedRecordings.data as ArchivedRecording[]),
Expand All @@ -190,9 +190,9 @@ export const BulkEditLabels: React.FunctionComponent<BulkEditLabelsProps> = (pro
: context.target.target().pipe(
filter((target) => target !== NO_TARGET),
concatMap((target) =>
context.api.graphql<any>(`
query {
targetNodes(filter: { name: "${target.connectUrl}" }) {
context.api.graphql<any>(
`query GetActiveRecordingsForTarget($connectUrl: String) {
tthvo marked this conversation as resolved.
Show resolved Hide resolved
targetNodes(filter: { name: $connectUrl }) {
recordings {
archived {
data {
Expand All @@ -206,7 +206,9 @@ export const BulkEditLabels: React.FunctionComponent<BulkEditLabelsProps> = (pro
}
}
}
}`)
}`,
{ connectUrl: target.connectUrl }
)
),
map((v) => v.data.targetNodes[0].recordings.archived.data as ArchivedRecording[]),
first()
Expand Down
21 changes: 13 additions & 8 deletions src/app/Recordings/ArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ export const ArchivedRecordingsTable: React.FunctionComponent<ArchivedRecordings

const queryTargetRecordings = React.useCallback(
(connectUrl: string) => {
return context.api.graphql<any>(`
query {
archivedRecordings(filter: { sourceTarget: "${connectUrl}" }) {
return context.api.graphql<any>(
`
query ArchivedRecordingsForTarget($connectUrl: String) {
archivedRecordings(filter: { sourceTarget: $connectUrl }) {
data {
name
downloadUrl
Expand All @@ -169,15 +170,17 @@ export const ArchivedRecordingsTable: React.FunctionComponent<ArchivedRecordings
size
}
}
}`);
}`,
{ connectUrl }
);
},
[context.api, context.api.graphql]
);

const queryUploadedRecordings = React.useCallback(() => {
return context.api.graphql<any>(`
query {
archivedRecordings(filter: { sourceTarget: "${UPLOADS_SUBDIRECTORY}" }) {
return context.api.graphql<any>(
`query UploadedRecordings($input: ArchivedRecordingFilterInput){
tthvo marked this conversation as resolved.
Show resolved Hide resolved
archivedRecordings(filter: $input) {
data {
name
downloadUrl
Expand All @@ -188,7 +191,9 @@ export const ArchivedRecordingsTable: React.FunctionComponent<ArchivedRecordings
size
}
}
}`);
}`,
{ input: { sourceTarget: UPLOADS_SUBDIRECTORY } }
);
}, [context.api, context.api.graphql]);

const refreshRecordingList = React.useCallback(() => {
Expand Down
52 changes: 33 additions & 19 deletions src/app/Shared/Services/Api.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,17 @@ export class ApiService {
);
}

graphql<T>(query: string): Observable<T> {
graphql<T>(query: string, variables?: Object): Observable<T> {
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()
Expand Down Expand Up @@ -749,13 +756,14 @@ export class ApiService {
filter((target) => target !== NO_TARGET),
first(),
concatMap((target) =>
this.graphql<any>(`
query {
targetNodes(filter: { name: "${target.connectUrl}" }) {
this.graphql<any>(
`
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
}
Expand All @@ -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[])
);
Expand All @@ -773,17 +783,18 @@ export class ApiService {
postUploadedRecordingMetadata(recordingName: string, labels: RecordingLabel[]): Observable<ArchivedRecording[]> {
return this.graphql<any>(
`
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[]));
}

Expand All @@ -792,13 +803,14 @@ export class ApiService {
filter((target) => target !== NO_TARGET),
first(),
concatMap((target) =>
this.graphql<any>(`
query {
targetNodes(filter: { name: "${target.connectUrl}" }) {
this.graphql<any>(
`
query PostActiveRecordingMetadataA($connectUrl: String, $recordingName: String, $labels: String) {
tthvo marked this conversation as resolved.
Show resolved Hide resolved
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
}
Expand All @@ -807,7 +819,9 @@ export class ApiService {
}
}
}
}`)
}`,
{ connectUrl: target.connectUrl, recordingName, labels: this.stringifyRecordingLabels(labels) }
maxcao13 marked this conversation as resolved.
Show resolved Hide resolved
)
),
map((v) => v.data.targetNodes[0].recordings.active as ActiveRecording[])
);
Expand Down