From 00cf54df4c11721edbd8c96ced380ccf2870e97f Mon Sep 17 00:00:00 2001 From: zcason Date: Mon, 18 Sep 2023 11:25:00 -0500 Subject: [PATCH] migrate graphql-backend plugin to the new backend system Signed-off-by: zcason --- packages/backend-next/package.json | 1 + packages/backend-next/src/index.ts | 1 + plugins/graphql-backend/api-report.md | 5 ++++ plugins/graphql-backend/src/index.ts | 1 + plugins/graphql-backend/src/plugin.ts | 42 +++++++++++++++++++++++++++ yarn.lock | 2 ++ 6 files changed, 52 insertions(+) create mode 100644 plugins/graphql-backend/src/plugin.ts diff --git a/packages/backend-next/package.json b/packages/backend-next/package.json index edda247a5a..6952fdcc7a 100644 --- a/packages/backend-next/package.json +++ b/packages/backend-next/package.json @@ -38,6 +38,7 @@ "@backstage/plugin-catalog-backend-module-unprocessed": "workspace:^", "@backstage/plugin-devtools-backend": "workspace:^", "@backstage/plugin-entity-feedback-backend": "workspace:^", + "@backstage/plugin-graphql-backend": "workspace:^", "@backstage/plugin-kubernetes-backend": "workspace:^", "@backstage/plugin-lighthouse-backend": "workspace:^", "@backstage/plugin-linguist-backend": "workspace:^", diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index 4e99732a11..b6ffa11a21 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -29,6 +29,7 @@ backend.add( backend.add(import('@backstage/plugin-catalog-backend/alpha')); backend.add(import('@backstage/plugin-devtools-backend')); backend.add(import('@backstage/plugin-entity-feedback-backend')); +backend.add(import('@backstage/plugin-graphql-backend')); backend.add(import('@backstage/plugin-kubernetes-backend/alpha')); backend.add(import('@backstage/plugin-lighthouse-backend')); backend.add(import('@backstage/plugin-linguist-backend')); diff --git a/plugins/graphql-backend/api-report.md b/plugins/graphql-backend/api-report.md index a787c4f209..31cdf4c617 100644 --- a/plugins/graphql-backend/api-report.md +++ b/plugins/graphql-backend/api-report.md @@ -3,6 +3,7 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts +import { BackendFeature } from '@backstage/backend-plugin-api'; import { Config } from '@backstage/config'; import express from 'express'; import { Logger } from 'winston'; @@ -10,6 +11,10 @@ import { Logger } from 'winston'; // @public (undocumented) export function createRouter(options: RouterOptions): Promise; +// @public +const graphqlPlugin: () => BackendFeature; +export default graphqlPlugin; + // @public (undocumented) export interface RouterOptions { // (undocumented) diff --git a/plugins/graphql-backend/src/index.ts b/plugins/graphql-backend/src/index.ts index a9f7f92ad9..5c21db501f 100644 --- a/plugins/graphql-backend/src/index.ts +++ b/plugins/graphql-backend/src/index.ts @@ -21,3 +21,4 @@ */ export * from './service/router'; +export { graphqlPlugin as default } from './plugin'; diff --git a/plugins/graphql-backend/src/plugin.ts b/plugins/graphql-backend/src/plugin.ts new file mode 100644 index 0000000000..6401f87803 --- /dev/null +++ b/plugins/graphql-backend/src/plugin.ts @@ -0,0 +1,42 @@ +/* + * Copyright 2023 The Backstage Authors + * + * 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. + */ +import { + coreServices, + createBackendPlugin, +} from '@backstage/backend-plugin-api'; +import { createRouter } from './service/router'; +import { loggerToWinstonLogger } from '@backstage/backend-common'; + +export const graphqlPlugin = createBackendPlugin({ + pluginId: 'graphql', + register(env) { + env.registerInit({ + deps: { + config: coreServices.rootConfig, + http: coreServices.httpRouter, + logger: coreServices.logger, + }, + async init({ config, http, logger }) { + http.use( + await createRouter({ + config, + logger: loggerToWinstonLogger(logger), + }), + ); + }, + }); + }, +}); diff --git a/yarn.lock b/yarn.lock index 84ad190c8a..53f1c4052a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7280,6 +7280,7 @@ __metadata: dependencies: "@apollo/server": ^4.0.0 "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/config": "workspace:^" "@backstage/plugin-catalog-graphql": "workspace:^" @@ -25960,6 +25961,7 @@ __metadata: "@backstage/plugin-catalog-backend-module-unprocessed": "workspace:^" "@backstage/plugin-devtools-backend": "workspace:^" "@backstage/plugin-entity-feedback-backend": "workspace:^" + "@backstage/plugin-graphql-backend": "workspace:^" "@backstage/plugin-kubernetes-backend": "workspace:^" "@backstage/plugin-lighthouse-backend": "workspace:^" "@backstage/plugin-linguist-backend": "workspace:^"