Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup graphql plugin #176

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ backend:
database:
client: better-sqlite3
connection: ':memory:'
reading:
allow:
- host: https://demo.backstage.io
paths:
- /api/graphql/schema

integrations:
github:
Expand Down Expand Up @@ -83,6 +88,10 @@ catalog:
- type: url
target: https://github.com/backstage/backstage/blob/master/catalog-info.yaml

# The demo site
- type: url
target: https://github.com/backstage/demo/blob/master/catalog-info.yaml

costInsights:
engineerCost: 200000
products:
Expand Down
18 changes: 17 additions & 1 deletion catalog-info.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: demo
name: backstage-demo
description: An example deployment of a Backstage application.
annotations:
github.com/project-slug: backstage/demo
spec:
type: website
owner: backstage/maintainers
lifecycle: experimental
consumesApis:
- demo-graphql
---
apiVersion: backstage.io/v1alpha1
kind: API
metadata:
name: demo-graphql
description: GraphQL Backend Plugin
spec:
type: graphql
lifecycle: production
owner: backstage/maintainers
apiConsumedBy:
- backstage-demo
definition:
$text: https://demo.backstage.io/api/graphql/schema
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
"@types/hast": "^2.3.4",
"@types/recharts": "^1.8.23",
"@types/react": "^17.0.59",
"@types/unist": "^2.0.6"
"@types/unist": "^2.0.6",
"graphql": "^16.2.0"
awanlin marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@backstage/cli": "^0.23.0",
"@backstage/e2e-test-utils": "^0.1.0",
"@playwright/test": "^1.32.3",
"@spotify/prettier-config": "^7.0.0",
"@types/node": "^18.0.0",
"concurrently": "^6.0.0",
"eslint-plugin-jest": "*",
"node-fetch": "^2.6.7",
Expand Down
9 changes: 7 additions & 2 deletions packages/app/src/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ export const apis: AnyApiFactory[] = [
}),
createApiFactory({
api: graphQlBrowseApiRef,
deps: { errorApi: errorApiRef, githubAuthApi: githubAuthApiRef },
factory: ({ errorApi, githubAuthApi }) =>
deps: { errorApi: errorApiRef, githubAuthApi: githubAuthApiRef, discoveryApi: discoveryApiRef },
factory: ({ errorApi, githubAuthApi, discoveryApi }) =>
GraphQLEndpoints.from([
GraphQLEndpoints.create({
id: 'backstage',
title: 'GraphQL Backend',
url: discoveryApi.getBaseUrl('graphql')
}),
GraphQLEndpoints.github({
id: 'github',
title: 'GitHub',
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"@backstage/plugin-search-backend-node": "^1.2.10",
"@backstage/plugin-techdocs-backend": "^1.8.0",
"@backstage/plugin-todo-backend": "^0.3.4",
"@frontside/backstage-plugin-graphql-backend": "^0.1.2",
"@frontside/backstage-plugin-graphql-backend-module-catalog": "^0.1.2",
"app": "^0.0.0",
"better-sqlite3": "^7.5.0",
"dockerode": "^3.2.1",
Expand Down
8 changes: 8 additions & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import search from './plugins/search';
import techdocs from './plugins/techdocs';
import todo from './plugins/todo';
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
import { CatalogClient } from '@backstage/catalog-client';
import graphql from './plugins/graphql';

function makeCreateEnv(config: Config) {
const root = getRootLogger();
Expand All @@ -45,6 +47,9 @@ function makeCreateEnv(config: Config) {
discovery,
tokenManager,
});
const catalogClient = new CatalogClient({
discoveryApi: discovery,
});
const cacheManager = CacheManager.fromConfig(config);
const taskScheduler = TaskScheduler.fromConfig(config, { databaseManager });
const identity = DefaultIdentityClient.create({
Expand All @@ -68,6 +73,7 @@ function makeCreateEnv(config: Config) {
permissions,
scheduler,
identity,
catalogClient,
};
};
}
Expand All @@ -88,6 +94,7 @@ async function main() {
const appEnv = createEnv('app');
const badgesEnv = createEnv('badges');
const exploreEnv = createEnv('explore');
const graphqlEnv = createEnv('graphql');

const apiRouter = Router();
apiRouter.use('/catalog', await catalog(catalogEnv));
Expand All @@ -98,6 +105,7 @@ async function main() {
apiRouter.use('/proxy', await proxy(proxyEnv));
apiRouter.use('/badges', await badges(badgesEnv));
apiRouter.use('/explore', await explore(exploreEnv));
apiRouter.use('/graphql', await graphql(graphqlEnv));
apiRouter.use(notFoundHandler());

const service = createServiceBuilder(module)
Expand Down
18 changes: 18 additions & 0 deletions packages/backend/src/plugins/graphql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createRouter } from '@frontside/backstage-plugin-graphql-backend';
import {
createCatalogLoader,
Catalog,
} from '@frontside/backstage-plugin-graphql-backend-module-catalog';
import { Router } from 'express';
import { PluginEnvironment } from '../types';

export default async function createPlugin({
logger,
catalogClient,
}: PluginEnvironment): Promise<Router> {
return await createRouter({
modules: [Catalog()],
logger,
loaders: { ...createCatalogLoader(catalogClient) },
});
}
2 changes: 2 additions & 0 deletions packages/backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { IdentityApi } from '@backstage/plugin-auth-node';
import { Logger } from 'winston';
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
import { PluginTaskScheduler } from '@backstage/backend-tasks';
import { CatalogClient } from '@backstage/catalog-client';

export type PluginEnvironment = {
logger: Logger;
Expand All @@ -23,4 +24,5 @@ export type PluginEnvironment = {
scheduler: PluginTaskScheduler;
permissions: PermissionEvaluator;
identity: IdentityApi;
catalogClient: CatalogClient;
};
Loading