Skip to content

Commit

Permalink
chore(graphql): add operation names and extract variables (#611)
Browse files Browse the repository at this point in the history
* chore(graphql): add operation names and extract variables

* rename GraphQL variable

* remove extra char

* remove Get prefix
  • Loading branch information
andrewazores authored Nov 7, 2022
1 parent 108a6df commit 05553bd
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 54 deletions.
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 ArchiveCountForTarget($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 ActiveRecordingsForTarget($connectUrl: String) {
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($filter: ArchivedRecordingFilterInput){
archivedRecordings(filter: $filter) {
data {
name
downloadUrl
Expand All @@ -188,7 +191,9 @@ export const ArchivedRecordingsTable: React.FunctionComponent<ArchivedRecordings
size
}
}
}`);
}`,
{ filter: { 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 PostActiveRecordingMetadata($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
}
Expand All @@ -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[])
);
Expand Down

0 comments on commit 05553bd

Please sign in to comment.