From ce2ed89e57c8e978a62fbb77f423ad1bcde79ace Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 12 Aug 2020 01:47:09 +0200 Subject: [PATCH] feat(gql/catalog): to remove the duplication in the schema thanks to the limitations on implements, let's create the schema using javascript Trust me, i've tried getting this to work with a typescript file, but it just would not work with the import export keywords which are needed to satisfy typescript config. couldn't get it to transpile anything properly. so thought screw it for now --- packages/backend-common/src/gql.ts | 17 ++++++ packages/backend-common/src/index.ts | 1 + plugins/catalog-graphql/src/schema.js | 87 +++++++++++++++++++++++++++ yarn.lock | 65 +++++++++++++++++++- 4 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 packages/backend-common/src/gql.ts create mode 100644 plugins/catalog-graphql/src/schema.js diff --git a/packages/backend-common/src/gql.ts b/packages/backend-common/src/gql.ts new file mode 100644 index 0000000000..ca6b9c7f55 --- /dev/null +++ b/packages/backend-common/src/gql.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const gql = (s: TemplateStringsArray, ...args: any[]) => + s.map((ss, i) => `${ss}${args[i] || ''}`).join(''); diff --git a/packages/backend-common/src/index.ts b/packages/backend-common/src/index.ts index a3f57ed9df..4b9518c6bc 100644 --- a/packages/backend-common/src/index.ts +++ b/packages/backend-common/src/index.ts @@ -20,3 +20,4 @@ export * from './logging'; export * from './middleware'; export * from './service'; export * from './hot'; +export * from './gql'; diff --git a/plugins/catalog-graphql/src/schema.js b/plugins/catalog-graphql/src/schema.js new file mode 100644 index 0000000000..473aad97f5 --- /dev/null +++ b/plugins/catalog-graphql/src/schema.js @@ -0,0 +1,87 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const EntityMetadataFields = /* GraphQL */ ` + name: String! + annotations: JSONObject! + annotation(name: String!): JSON + labels: JSONObject! + label(name: String!): JSON + uid: String! + etag: String! + generation: Int! +`; + +const EntityMetadata = /* GraphQL */ ` + scalar JSON + scalar JSONObject + + interface EntityMetadata { + ${EntityMetadataFields} + } + + type DefaultEntityMetadata implements EntityMetadata { + ${EntityMetadataFields} + } + + type ComponentMetadata implements EntityMetadata { + ${EntityMetadataFields} + # mock field to prove extensions working + relationships: String + } + + type TemplateMetadata implements EntityMetadata { + ${EntityMetadataFields} + # mock field to prove extensions working + updatedBy: String + } + + type TemplateEntitySpec { + type: String! + path: String + schema: JSONObject! + templater: String! + } + + type ComponentEntitySpec { + type: String! + lifecycle: String! + owner: String! + } + + type DefaultEntitySpec { + raw: JSONObject + } + + union EntitySpec = DefaultEntitySpec | TemplateEntitySpec | ComponentEntitySpec + + type CatalogEntity { + apiVersion: String! + kind: String! + metadata: EntityMetadata + spec: EntitySpec! + } + + type CatalogQuery { + list: [CatalogEntity!]! + } + + type Query { + catalog: CatalogQuery! + } +`; + +module.exports = EntityMetadata; diff --git a/yarn.lock b/yarn.lock index 7dfa9e500f..b4c5a4fe49 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4460,7 +4460,7 @@ "@types/qs" "*" "@types/range-parser" "*" -"@types/express@*", "@types/express@^4.17.6", "@types/express@^4.17.7": +"@types/express@*", "@types/express@4.17.7", "@types/express@^4.17.6", "@types/express@^4.17.7": version "4.17.7" resolved "https://registry.npmjs.org/@types/express/-/express-4.17.7.tgz#42045be6475636d9801369cd4418ef65cdb0dd59" integrity sha512-dCOT5lcmV/uC2J9k0rPafATeeyz+99xTt54ReX11/LObZgfzJqZNcW27zGhYyX+9iSEGXGt5qLPwRSvBZcLvtQ== @@ -5843,6 +5843,34 @@ apollo-server-core@^2.16.0: subscriptions-transport-ws "^0.9.11" ws "^6.0.0" +apollo-server-core@^2.16.1: + version "2.16.1" + resolved "https://registry.npmjs.org/apollo-server-core/-/apollo-server-core-2.16.1.tgz#5b5b8245ab9c0cb6c2367ec19ab855dea6ccea3a" + integrity sha512-nuwn5ZBbmzPwDetb3FgiFFJlNK7ZBFg8kis/raymrjd3eBGdNcOyMTJDl6J9673X9Xqp+dXQmFYDW/G3G8S1YA== + dependencies: + "@apollographql/apollo-tools" "^0.4.3" + "@apollographql/graphql-playground-html" "1.6.26" + "@types/graphql-upload" "^8.0.0" + "@types/ws" "^7.0.0" + apollo-cache-control "^0.11.1" + apollo-datasource "^0.7.2" + apollo-engine-reporting "^2.3.0" + apollo-server-caching "^0.5.2" + apollo-server-env "^2.4.5" + apollo-server-errors "^2.4.2" + apollo-server-plugin-base "^0.9.1" + apollo-server-types "^0.5.1" + apollo-tracing "^0.11.1" + fast-json-stable-stringify "^2.0.0" + graphql-extensions "^0.12.4" + graphql-tag "^2.9.2" + graphql-tools "^4.0.0" + graphql-upload "^8.0.2" + loglevel "^1.6.7" + sha.js "^2.4.11" + subscriptions-transport-ws "^0.9.11" + ws "^6.0.0" + apollo-server-env@^2.4.5: version "2.4.5" resolved "https://registry.npmjs.org/apollo-server-env/-/apollo-server-env-2.4.5.tgz#73730b4f0439094a2272a9d0caa4079d4b661d5f" @@ -5878,6 +5906,28 @@ apollo-server-express@^2.16.0: subscriptions-transport-ws "^0.9.16" type-is "^1.6.16" +apollo-server-express@^2.16.1: + version "2.16.1" + resolved "https://registry.npmjs.org/apollo-server-express/-/apollo-server-express-2.16.1.tgz#7438bca590ef8577d24d20ba0b6d582c120c0146" + integrity sha512-Oq5YNcaMYnRk6jDmA9LWf8oSd2KHDVe7jQ4wtooAvG9FVUD+FaFBgSkytXHMvtifQh2wdF07Ri8uDLMz6IQjTw== + dependencies: + "@apollographql/graphql-playground-html" "1.6.26" + "@types/accepts" "^1.3.5" + "@types/body-parser" "1.19.0" + "@types/cors" "^2.8.4" + "@types/express" "4.17.7" + accepts "^1.3.5" + apollo-server-core "^2.16.1" + apollo-server-types "^0.5.1" + body-parser "^1.18.3" + cors "^2.8.4" + express "^4.17.1" + graphql-subscriptions "^1.0.0" + graphql-tools "^4.0.0" + parseurl "^1.3.2" + subscriptions-transport-ws "^0.9.16" + type-is "^1.6.16" + apollo-server-plugin-base@^0.9.1: version "0.9.1" resolved "https://registry.npmjs.org/apollo-server-plugin-base/-/apollo-server-plugin-base-0.9.1.tgz#a62ae9ab4e89790fd4cc5d123bb616da34e8e5fb" @@ -5905,6 +5955,17 @@ apollo-server@^2.16.0: graphql-subscriptions "^1.0.0" graphql-tools "^4.0.0" +apollo-server@^2.16.1: + version "2.16.1" + resolved "https://registry.npmjs.org/apollo-server/-/apollo-server-2.16.1.tgz#edc319606eb29f73132239bdc005dd88ac40a142" + integrity sha512-oy9NVRzGwlpQ+W1DwLKRH+KASmodSYpvYIRY5DMAZtGqNmT2zOCpbIZVjBt23SuPB5NhIhhE4ROzoObRv3zy5w== + dependencies: + apollo-server-core "^2.16.1" + apollo-server-express "^2.16.1" + express "^4.0.0" + graphql-subscriptions "^1.0.0" + graphql-tools "^4.0.0" + apollo-tracing@^0.11.1: version "0.11.1" resolved "https://registry.npmjs.org/apollo-tracing/-/apollo-tracing-0.11.1.tgz#3e3a4ce4b21e57dcc57b10bbd539db243b752606" @@ -11340,7 +11401,7 @@ graphql-subscriptions@^1.0.0: dependencies: iterall "^1.2.1" -graphql-tag@2.11.0: +graphql-tag@2.11.0, graphql-tag@^2.11.0: version "2.11.0" resolved "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.11.0.tgz#1deb53a01c46a7eb401d6cb59dec86fa1cccbffd" integrity sha512-VmsD5pJqWJnQZMUeRwrDhfgoyqcfwEkvtpANqcoUG8/tOLkwNgU9mzub/Mc78OJMhHjx7gfAMTxzdG43VGg3bA==