Merge pull request #8304 from backstage/freben/less-cross

remove more cross-fetch usage in backends
This commit is contained in:
Fredrik Adelöw
2021-12-01 18:26:28 +01:00
committed by GitHub
9 changed files with 82 additions and 19 deletions
+1 -1
View File
@@ -36,10 +36,10 @@
"@backstage/types": "^0.1.1",
"@graphql-modules/core": "^0.7.17",
"apollo-server": "^2.16.1",
"cross-fetch": "^3.0.6",
"graphql": "^15.3.0",
"graphql-tag": "^2.11.0",
"graphql-type-json": "^0.3.2",
"node-fetch": "^2.6.1",
"winston": "^3.2.1"
},
"devDependencies": {
@@ -15,7 +15,7 @@
*/
import { Entity, EntityMeta } from '@backstage/catalog-model';
import fetch from 'cross-fetch';
import fetch from 'node-fetch';
import { JsonObject } from '@backstage/types';
export interface ReaderEntityMeta extends EntityMeta {
@@ -26,11 +26,14 @@ export interface ReaderEntityMeta extends EntityMeta {
annotations: Record<string, string>;
labels: Record<string, string>;
}
export interface ReaderEntity extends Entity {
metadata: JsonObject & ReaderEntityMeta;
}
export class CatalogClient {
constructor(private baseUrl: string) {}
async list(): Promise<ReaderEntity[]> {
const res = await fetch(`${this.baseUrl}/catalog/entities`);
if (!res.ok) {
@@ -39,7 +42,7 @@ export class CatalogClient {
throw new Error(await res.text());
}
const entities: ReaderEntity[] = await res.json();
const entities = (await res.json()) as ReaderEntity[];
return entities;
}
}