feat(gql/catlaog): Tidying up the resolver for the annotations
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
"@graphql-codegen/typescript-resolvers": "^1.17.7",
|
||||
"@graphql-modules/core": "^0.7.17",
|
||||
"graphql": "^15.3.0",
|
||||
"graphql-type-json": "^0.3.2",
|
||||
"node-fetch": "^2.6.0",
|
||||
"ts-node": "^8.10.2",
|
||||
"winston": "^3.2.1",
|
||||
@@ -36,9 +37,9 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "^0.1.1-alpha.18",
|
||||
"@types/express": "^4.17.7",
|
||||
"@types/supertest": "^2.0.8",
|
||||
"eslint-plugin-graphql": "^4.0.0",
|
||||
"@types/express": "^4.17.7",
|
||||
"msw": "^0.19.5",
|
||||
"supertest": "^4.0.2"
|
||||
},
|
||||
|
||||
@@ -18,26 +18,16 @@ import { Logger } from 'winston';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { GraphQLModule } from '@graphql-modules/core';
|
||||
import { Resolvers, CatalogEntity, CatalogQuery } from './types';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { Resolvers, CatalogQuery } from './types';
|
||||
import { Config } from '@backstage/config';
|
||||
import { CatalogClient } from '../service/client';
|
||||
import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';
|
||||
|
||||
export interface ModuleOptions {
|
||||
logger: Logger;
|
||||
config: Config;
|
||||
}
|
||||
|
||||
const parseToCatalogEntities = (e: Entity): CatalogEntity => ({
|
||||
...e,
|
||||
metadata: {
|
||||
...e.metadata,
|
||||
annotations: Object.entries(
|
||||
e.metadata.annotations ?? {},
|
||||
).map(([key, value]) => ({ key, value })),
|
||||
},
|
||||
});
|
||||
|
||||
export async function createModule(
|
||||
options: ModuleOptions,
|
||||
): Promise<GraphQLModule> {
|
||||
@@ -51,18 +41,19 @@ export async function createModule(
|
||||
);
|
||||
|
||||
const resolvers: Resolvers = {
|
||||
JSON: GraphQLJSON,
|
||||
JSONObject: GraphQLJSONObject,
|
||||
Query: {
|
||||
catalog: () => ({} as CatalogQuery),
|
||||
},
|
||||
CatalogQuery: {
|
||||
list: async () => {
|
||||
const list = await catalogClient.list();
|
||||
return list.map(parseToCatalogEntities);
|
||||
return await catalogClient.list();
|
||||
},
|
||||
},
|
||||
EntityMetadata: {
|
||||
annotation: (e, { name }) =>
|
||||
e.annotations?.find(a => a.key === name) ?? null,
|
||||
annotations: e => e.annotations,
|
||||
annotation: (e, { name }) => e.annotations[name] ?? null,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
scalar JSON
|
||||
scalar JSONObject
|
||||
|
||||
type EntityMetadataAnnotation {
|
||||
key: String!
|
||||
value: String!
|
||||
@@ -6,8 +9,7 @@ type EntityMetadataAnnotation {
|
||||
type EntityMetadata {
|
||||
name: String!
|
||||
namespace: String
|
||||
annotation(name: String): EntityMetadataAnnotation
|
||||
annotations: [EntityMetadataAnnotation!]
|
||||
annotations: JSONObject
|
||||
}
|
||||
|
||||
type CatalogEntity {
|
||||
|
||||
@@ -10379,7 +10379,6 @@ file-loader@^4.2.0:
|
||||
|
||||
"file-saver@github:eligrey/FileSaver.js#1.3.8":
|
||||
version "1.3.8"
|
||||
uid e865e37af9f9947ddcced76b549e27dc45c1cb2e
|
||||
resolved "https://codeload.github.com/eligrey/FileSaver.js/tar.gz/e865e37af9f9947ddcced76b549e27dc45c1cb2e"
|
||||
|
||||
file-system-cache@^1.0.5:
|
||||
@@ -11376,6 +11375,11 @@ graphql-tools@^4.0.0:
|
||||
iterall "^1.1.3"
|
||||
uuid "^3.1.0"
|
||||
|
||||
graphql-type-json@^0.3.2:
|
||||
version "0.3.2"
|
||||
resolved "https://registry.npmjs.org/graphql-type-json/-/graphql-type-json-0.3.2.tgz#f53a851dbfe07bd1c8157d24150064baab41e115"
|
||||
integrity sha512-J+vjof74oMlCWXSvt0DOf2APEdZOCdubEvGDUAlqH//VBYcOYsGgRW7Xzorr44LvkjiuvecWc8fChxuZZbChtg==
|
||||
|
||||
graphql-upload@^8.0.2:
|
||||
version "8.1.0"
|
||||
resolved "https://registry.npmjs.org/graphql-upload/-/graphql-upload-8.1.0.tgz#6d0ab662db5677a68bfb1f2c870ab2544c14939a"
|
||||
@@ -13586,7 +13590,6 @@ jsonpointer@^4.0.1:
|
||||
resolved "https://registry.npmjs.org/jsonpointer/-/jsonpointer-4.0.1.tgz#4fd92cb34e0e9db3c89c8622ecf51f9b978c6cb9"
|
||||
integrity sha1-T9kss04OnbPInIYi7PUfm5eMbLk=
|
||||
|
||||
<<<<<<< HEAD
|
||||
jsonwebtoken@^8.1.0:
|
||||
version "8.5.1"
|
||||
resolved "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d"
|
||||
@@ -13602,7 +13605,7 @@ jsonwebtoken@^8.1.0:
|
||||
lodash.once "^4.0.0"
|
||||
ms "^2.1.1"
|
||||
semver "^5.6.0"
|
||||
=======
|
||||
|
||||
jspdf-autotable@3.5.3:
|
||||
version "3.5.3"
|
||||
resolved "https://registry.npmjs.org/jspdf-autotable/-/jspdf-autotable-3.5.3.tgz#2f73adb07f340e7dbf22950e3e6c8bf853991479"
|
||||
@@ -13614,12 +13617,11 @@ jspdf@1.5.3:
|
||||
integrity sha512-J9X76xnncMw+wIqb15HeWfPMqPwYxSpPY8yWPJ7rAZN/ZDzFkjCSZObryCyUe8zbrVRNiuCnIeQteCzMn7GnWw==
|
||||
dependencies:
|
||||
canvg "1.5.3"
|
||||
file-saver "github:eligrey/FileSaver.js#1.3.8"
|
||||
file-saver eligrey/FileSaver.js#1.3.8
|
||||
html2canvas "1.0.0-alpha.12"
|
||||
omggif "1.0.7"
|
||||
promise-polyfill "8.1.0"
|
||||
stackblur-canvas "2.2.0"
|
||||
>>>>>>> f225b094e4651d478fa5925ef498fdbdab6ca353
|
||||
|
||||
jsprim@^1.2.2:
|
||||
version "1.4.1"
|
||||
@@ -16072,9 +16074,6 @@ parse-entities@^1.1.0, parse-entities@^1.1.2:
|
||||
is-decimal "^1.0.0"
|
||||
is-hexadecimal "^1.0.0"
|
||||
|
||||
<<<<<<< HEAD
|
||||
parse-filepath@1.0.2, parse-filepath@^1.0.1:
|
||||
=======
|
||||
parse-entities@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.npmjs.org/parse-entities/-/parse-entities-2.0.0.tgz#53c6eb5b9314a1f4ec99fa0fdf7ce01ecda0cbe8"
|
||||
@@ -16087,8 +16086,7 @@ parse-entities@^2.0.0:
|
||||
is-decimal "^1.0.0"
|
||||
is-hexadecimal "^1.0.0"
|
||||
|
||||
parse-filepath@^1.0.1:
|
||||
>>>>>>> f225b094e4651d478fa5925ef498fdbdab6ca353
|
||||
parse-filepath@1.0.2, parse-filepath@^1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.npmjs.org/parse-filepath/-/parse-filepath-1.0.2.tgz#a632127f53aaf3d15876f5872f3ffac763d6c891"
|
||||
integrity sha1-pjISf1Oq89FYdvWHLz/6x2PWyJE=
|
||||
@@ -17149,7 +17147,6 @@ pretty-hrtime@^1.0.3:
|
||||
resolved "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1"
|
||||
integrity sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=
|
||||
|
||||
<<<<<<< HEAD
|
||||
prisma-json-schema@0.1.3:
|
||||
version "0.1.3"
|
||||
resolved "https://registry.npmjs.org/prisma-json-schema/-/prisma-json-schema-0.1.3.tgz#6c302db8f464f8b92e8694d3f7dd3f41ac9afcbe"
|
||||
@@ -17179,16 +17176,10 @@ prisma-yml@1.34.10:
|
||||
scuid "^1.0.2"
|
||||
yaml-ast-parser "^0.0.40"
|
||||
|
||||
prismjs@^1.8.4:
|
||||
version "1.19.0"
|
||||
resolved "https://registry.npmjs.org/prismjs/-/prismjs-1.19.0.tgz#713afbd45c3baca4b321569f2df39e17e729d4dc"
|
||||
integrity sha512-IVFtbW9mCWm9eOIaEkNyo2Vl4NnEifis2GQ7/MLRG5TQe6t+4Sj9J5QWI9i3v+SS43uZBlCAOn+zYTVYQcPXJw==
|
||||
=======
|
||||
prismjs@^1.20.0, prismjs@^1.8.4, prismjs@~1.20.0:
|
||||
version "1.20.0"
|
||||
resolved "https://registry.npmjs.org/prismjs/-/prismjs-1.20.0.tgz#9b685fc480a3514ee7198eac6a3bf5024319ff03"
|
||||
integrity sha512-AEDjSrVNkynnw6A+B1DsFkd6AVdTnp+/WoUixFRULlCLZVRZlVQMVWio/16jv7G1FscUxQxOQhWwApgbnxr6kQ==
|
||||
>>>>>>> f225b094e4651d478fa5925ef498fdbdab6ca353
|
||||
optionalDependencies:
|
||||
clipboard "^2.0.0"
|
||||
|
||||
@@ -18481,11 +18472,7 @@ request-promise-native@^1.0.5, request-promise-native@^1.0.8:
|
||||
stealthy-require "^1.1.1"
|
||||
tough-cookie "^2.3.3"
|
||||
|
||||
<<<<<<< HEAD
|
||||
request@2.88.2, request@^2.85.0, request@^2.87.0, request@^2.88.0, request@^2.88.2:
|
||||
=======
|
||||
request@^2.55.0, request@^2.85.0, request@^2.87.0, request@^2.88.0, request@^2.88.2:
|
||||
>>>>>>> f225b094e4651d478fa5925ef498fdbdab6ca353
|
||||
request@2.88.2, request@^2.55.0, request@^2.85.0, request@^2.87.0, request@^2.88.0, request@^2.88.2:
|
||||
version "2.88.2"
|
||||
resolved "https://registry.npmjs.org/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3"
|
||||
integrity sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==
|
||||
|
||||
Reference in New Issue
Block a user