[WIP] Switched from rest to GraphQL #162-2
This commit is contained in:
13
kdb-web/src/app/models/graphql/queries.model.ts
Normal file
13
kdb-web/src/app/models/graphql/queries.model.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export class Queries {
|
||||
static serverInfoQuery = `
|
||||
query {
|
||||
serverCount
|
||||
servers {
|
||||
id
|
||||
name
|
||||
iconURL
|
||||
userCount
|
||||
}
|
||||
}
|
||||
`;
|
||||
}
|
6
kdb-web/src/app/models/graphql/query.model.ts
Normal file
6
kdb-web/src/app/models/graphql/query.model.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Server } from "../data/server.model";
|
||||
|
||||
export interface Query {
|
||||
serverCount: number;
|
||||
servers: Server[];
|
||||
}
|
5
kdb-web/src/app/models/graphql/result.model.ts
Normal file
5
kdb-web/src/app/models/graphql/result.model.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Query } from "./query.model";
|
||||
|
||||
export interface QueryResult {
|
||||
data: any;
|
||||
}
|
@@ -3,13 +3,15 @@ import { FormBuilder, FormControl, FormGroup } from "@angular/forms";
|
||||
import { Router } from "@angular/router";
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
import { LazyLoadEvent } from "primeng/api";
|
||||
import { debounceTime } from "rxjs";
|
||||
import { debounceTime, throwError } from "rxjs";
|
||||
import { ConfirmationDialogService } from "src/app/services/confirmation-dialog/confirmation-dialog.service";
|
||||
import { DataService } from "src/app/services/data/data.service";
|
||||
import { ServerService } from "src/app/services/data/server.service";
|
||||
import { SpinnerService } from "src/app/services/spinner/spinner.service";
|
||||
import { ToastService } from "src/app/services/toast/toast.service";
|
||||
import { Server } from "../../../../../models/data/server.model";
|
||||
import { catchError } from "rxjs/operators";
|
||||
import { Queries } from "../../../../../models/graphql/queries.model";
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard',
|
||||
@@ -71,14 +73,14 @@ export class DashboardComponent implements OnInit {
|
||||
|
||||
async loadNextPage() {
|
||||
this.spinnerService.showSpinner();
|
||||
// this.data.getFilteredServers(this.searchCriterions).pipe(catchError(err => {
|
||||
// this.spinnerService.hideSpinner();
|
||||
// return throwError(() => err);
|
||||
// })).subscribe(list => {
|
||||
// this.totalRecords = list.totalCount;
|
||||
// this.servers = list.servers;
|
||||
// this.spinnerService.hideSpinner();
|
||||
// });
|
||||
this.data.query(Queries.serverInfoQuery).pipe(catchError(err => {
|
||||
this.spinnerService.hideSpinner();
|
||||
return throwError(() => err);
|
||||
})).subscribe(data => {
|
||||
this.totalRecords = data.data.serverCount;
|
||||
this.servers = data.data.servers;
|
||||
this.spinnerService.hideSpinner();
|
||||
});
|
||||
}
|
||||
|
||||
nextPage(event: LazyLoadEvent) {
|
||||
|
@@ -1,28 +1,30 @@
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
||||
import { Injectable } from "@angular/core";
|
||||
import { SettingsService } from "../settings/settings.service";
|
||||
import { Observable } from "rxjs";
|
||||
import { QueryResult } from "../../models/graphql/result.model";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: "root"
|
||||
})
|
||||
export class DataService {
|
||||
|
||||
// serverQuery = this.apollo.watchQuery({
|
||||
// query: gql`
|
||||
// {
|
||||
// serverCount
|
||||
// servers {
|
||||
// id
|
||||
// name
|
||||
// }
|
||||
// }
|
||||
// `
|
||||
// });
|
||||
|
||||
|
||||
constructor(
|
||||
private appsettings: SettingsService,
|
||||
private http: HttpClient
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
query(query: string, variables: object = {}): Observable<QueryResult> {
|
||||
return this.http.post<QueryResult>(`${this.appsettings.getApiURL()}/api/graphql`,
|
||||
JSON.stringify({
|
||||
query, variables
|
||||
}), {
|
||||
headers: new HttpHeaders({
|
||||
"Content-Type": "application/json"
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user