[WIP] Switched from rest to GraphQL #162-2

This commit is contained in:
2023-02-09 16:09:34 +01:00
parent 4266db7e35
commit 6aca981fd1
7 changed files with 59 additions and 25 deletions

View File

@@ -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"
})
}
);
}
}