graphql: Add -backend suffix to the plugin directory
plugins/graphql is a backend plugin published at @backstage/plugin-graphql-backend When exploring the repository, I got confused to find only plugins/graphql since backend plugins are supposed to have the -backend suffix Signed-off-by: Himanshu Mishra <himanshu@orkohunter.net>
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
extends: [require.resolve('@backstage/cli/config/eslint.backend')],
|
||||
};
|
||||
@@ -0,0 +1,94 @@
|
||||
# @backstage/plugin-graphql-backend
|
||||
|
||||
## 0.1.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @backstage/backend-common@0.9.0
|
||||
- @backstage/config@0.1.8
|
||||
- @backstage/plugin-catalog-graphql@0.2.12
|
||||
|
||||
## 0.1.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [3be844496]
|
||||
- Updated dependencies [22fd8ce2a]
|
||||
- Updated dependencies [f9fb4a205]
|
||||
- @backstage/plugin-catalog-graphql@0.2.9
|
||||
- @backstage/backend-common@0.8.0
|
||||
|
||||
## 0.1.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [e0bfd3d44]
|
||||
- Updated dependencies [38ca05168]
|
||||
- Updated dependencies [d8b81fd28]
|
||||
- @backstage/backend-common@0.7.0
|
||||
- @backstage/config@0.1.5
|
||||
- @backstage/plugin-catalog-graphql@0.2.8
|
||||
|
||||
## 0.1.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [8686eb38c]
|
||||
- Updated dependencies [0434853a5]
|
||||
- Updated dependencies [8686eb38c]
|
||||
- @backstage/backend-common@0.6.0
|
||||
- @backstage/config@0.1.4
|
||||
- @backstage/plugin-catalog-graphql@0.2.7
|
||||
|
||||
## 0.1.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [0b135e7e0]
|
||||
- Updated dependencies [294a70cab]
|
||||
- Updated dependencies [0ea032763]
|
||||
- Updated dependencies [5345a1f98]
|
||||
- Updated dependencies [09a370426]
|
||||
- @backstage/backend-common@0.5.0
|
||||
- @backstage/plugin-catalog-graphql@0.2.6
|
||||
|
||||
## 0.1.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [38e24db00]
|
||||
- Updated dependencies [e3bd9fc2f]
|
||||
- Updated dependencies [12bbd748c]
|
||||
- Updated dependencies [e3bd9fc2f]
|
||||
- @backstage/backend-common@0.4.0
|
||||
- @backstage/config@0.1.2
|
||||
- @backstage/plugin-catalog-graphql@0.2.4
|
||||
|
||||
## 0.1.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [1722cb53c]
|
||||
- Updated dependencies [1722cb53c]
|
||||
- Updated dependencies [7b37e6834]
|
||||
- Updated dependencies [8e2effb53]
|
||||
- @backstage/backend-common@0.3.0
|
||||
- @backstage/plugin-catalog-graphql@0.2.1
|
||||
|
||||
## 0.1.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [28edd7d29]
|
||||
- Updated dependencies [5249594c5]
|
||||
- Updated dependencies [56e4eb589]
|
||||
- Updated dependencies [e37c0a005]
|
||||
- Updated dependencies [f00ca3cb8]
|
||||
- Updated dependencies [6579769df]
|
||||
- Updated dependencies [8c2b76e45]
|
||||
- Updated dependencies [440a17b39]
|
||||
- Updated dependencies [8afce088a]
|
||||
- Updated dependencies [7bbeb049f]
|
||||
- @backstage/plugin-catalog-graphql@0.2.0
|
||||
- @backstage/backend-common@0.2.0
|
||||
@@ -0,0 +1,28 @@
|
||||
# GraphQL Backend
|
||||
|
||||
## Getting Started
|
||||
|
||||
This is the GraphQL Backend plugin.
|
||||
|
||||
It is responsible for merging different `graphql-plugins` together to provide the end schema.
|
||||
|
||||
To run it within the backend do:
|
||||
|
||||
1. Register the router in `packages/backend/src/index.ts`:
|
||||
|
||||
```ts
|
||||
const graphqlEnv = useHotMemoize(module, () => createEnv('graphql'));
|
||||
|
||||
const service = createServiceBuilder(module)
|
||||
.loadConfig(configReader)
|
||||
/** several different routers */
|
||||
.addRouter('/graphql', await graphql(graphqlEnv));
|
||||
```
|
||||
|
||||
2. Start the backend
|
||||
|
||||
```bash
|
||||
yarn workspace example-backend start
|
||||
```
|
||||
|
||||
This will launch the full example backend.
|
||||
@@ -0,0 +1,24 @@
|
||||
## API Report File for "@backstage/plugin-graphql-backend"
|
||||
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
import { Config } from '@backstage/config';
|
||||
import express from 'express';
|
||||
import { Logger as Logger_2 } from 'winston';
|
||||
|
||||
// Warning: (ae-missing-release-tag) "createRouter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
export function createRouter(options: RouterOptions): Promise<express.Router>;
|
||||
|
||||
// Warning: (ae-missing-release-tag) "RouterOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
export interface RouterOptions {
|
||||
// (undocumented)
|
||||
config: Config;
|
||||
// (undocumented)
|
||||
logger: Logger_2;
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"name": "@backstage/plugin-graphql-backend",
|
||||
"description": "An experimental Backstage backend plugin for GraphQL",
|
||||
"version": "0.1.9",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"license": "Apache-2.0",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"main": "dist/index.cjs.js",
|
||||
"types": "dist/index.d.ts"
|
||||
},
|
||||
"homepage": "https://backstage.io",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/backstage/backstage",
|
||||
"directory": "plugins/graphql-backend"
|
||||
},
|
||||
"keywords": [
|
||||
"backstage",
|
||||
"graphql"
|
||||
],
|
||||
"scripts": {
|
||||
"start": "backstage-cli backend:dev",
|
||||
"build": "backstage-cli backend:build",
|
||||
"lint": "backstage-cli lint",
|
||||
"test": "backstage-cli test",
|
||||
"prepack": "backstage-cli prepack",
|
||||
"postpack": "backstage-cli postpack",
|
||||
"clean": "backstage-cli clean"
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-common": "^0.9.0",
|
||||
"@backstage/config": "^0.1.8",
|
||||
"@backstage/plugin-catalog-graphql": "^0.2.12",
|
||||
"@graphql-modules/core": "^0.7.17",
|
||||
"@types/express": "^4.17.6",
|
||||
"apollo-server": "^2.16.1",
|
||||
"apollo-server-express": "^2.16.1",
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"graphql": "^15.3.0",
|
||||
"helmet": "^4.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"winston": "^3.2.1",
|
||||
"yn": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "^0.7.0",
|
||||
"@types/supertest": "^2.0.8",
|
||||
"eslint-plugin-graphql": "^4.0.0",
|
||||
"msw": "^0.29.0",
|
||||
"supertest": "^6.1.3"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"schema.gql"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2020 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* An experimental Backstage backend plugin for GraphQL
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
export * from './service/router';
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2020 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 { createRouter } from './router';
|
||||
import supertest from 'supertest';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { createLogger } from 'winston';
|
||||
import express from 'express';
|
||||
|
||||
describe('Router', () => {
|
||||
describe('/health', () => {
|
||||
it('should return ok', async () => {
|
||||
const config = new ConfigReader({ backend: { baseUrl: 'lol' } });
|
||||
|
||||
const router = await createRouter({ config, logger: createLogger() });
|
||||
const app = express().use(router);
|
||||
|
||||
const { body } = await supertest(app).get('/health');
|
||||
|
||||
expect(body).toEqual({ status: 'ok' });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2020 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 { errorHandler, resolvePackagePath } from '@backstage/backend-common';
|
||||
import express from 'express';
|
||||
import Router from 'express-promise-router';
|
||||
import { Logger } from 'winston';
|
||||
import fs from 'fs';
|
||||
import { GraphQLModule } from '@graphql-modules/core';
|
||||
import { ApolloServer } from 'apollo-server-express';
|
||||
import { createModule as createCatalogModule } from '@backstage/plugin-catalog-graphql';
|
||||
import { Config } from '@backstage/config';
|
||||
import helmet from 'helmet';
|
||||
|
||||
const schemaPath = resolvePackagePath(
|
||||
'@backstage/plugin-graphql-backend',
|
||||
'schema.gql',
|
||||
);
|
||||
|
||||
export interface RouterOptions {
|
||||
logger: Logger;
|
||||
config: Config;
|
||||
}
|
||||
|
||||
export async function createRouter(
|
||||
options: RouterOptions,
|
||||
): Promise<express.Router> {
|
||||
const typeDefs = await fs.promises.readFile(schemaPath, 'utf-8');
|
||||
|
||||
const catalogModule = await createCatalogModule(options);
|
||||
|
||||
const { schema } = new GraphQLModule({
|
||||
imports: [catalogModule],
|
||||
typeDefs,
|
||||
});
|
||||
|
||||
const server = new ApolloServer({
|
||||
schema,
|
||||
logger: options.logger,
|
||||
introspection: true,
|
||||
playground: process.env.NODE_ENV === 'development',
|
||||
});
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get('/health', (_, response) => {
|
||||
response.send({ status: 'ok' });
|
||||
});
|
||||
|
||||
const apolloMiddleware = server.getMiddleware({ path: '/' });
|
||||
|
||||
if (process.env.NODE_ENV === 'development')
|
||||
router.use(
|
||||
helmet.contentSecurityPolicy({
|
||||
directives: {
|
||||
defaultSrc: ["'self'", "'unsafe-inline'", 'http://*'],
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
router.use(apolloMiddleware);
|
||||
|
||||
router.use(errorHandler());
|
||||
|
||||
return router;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2020 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.
|
||||
*/
|
||||
|
||||
export {};
|
||||
Reference in New Issue
Block a user