@gapi/federation 1.8.120

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ import { RemoteGraphQLDataSource } from '@apollo/gateway';
2
+ export declare class AuthenticatedDataSource extends RemoteGraphQLDataSource {
3
+ willSendRequest({ request, context }: {
4
+ request: any;
5
+ context: any;
6
+ }): void;
7
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthenticatedDataSource = void 0;
4
+ const gateway_1 = require("@apollo/gateway");
5
+ class AuthenticatedDataSource extends gateway_1.RemoteGraphQLDataSource {
6
+ willSendRequest({ request, context }) {
7
+ Object.entries(context.headers || {}).forEach(([key, value]) => request.http.headers.set(key, value));
8
+ }
9
+ }
10
+ exports.AuthenticatedDataSource = AuthenticatedDataSource;
11
+ //# sourceMappingURL=auth-data-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-data-source.js","sourceRoot":"","sources":["../src/auth-data-source.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAE1D,MAAa,uBAAwB,SAAQ,iCAAuB;IAClE,eAAe,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE;QAClC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAC7D,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CACrC,CAAC;IACJ,CAAC;CACF;AAND,0DAMC"}
@@ -0,0 +1,6 @@
1
+ import { ModuleWithProviders } from '@rxdi/core';
2
+ import { FederationModuleOptions } from './tokens';
3
+ export declare class FederationModule {
4
+ static forRoot({ port, serviceList, willSendRequest, context, apolloServerConfig, }: FederationModuleOptions): ModuleWithProviders;
5
+ }
6
+ export * from './tokens';
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14
+ };
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
17
+ };
18
+ var FederationModule_1;
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.FederationModule = void 0;
21
+ const gateway_1 = require("@apollo/gateway");
22
+ const core_1 = require("@rxdi/core");
23
+ const apollo_server_1 = require("apollo-server");
24
+ const auth_data_source_1 = require("./auth-data-source");
25
+ const tokens_1 = require("./tokens");
26
+ let FederationModule = FederationModule_1 = class FederationModule {
27
+ static forRoot({ port, serviceList, willSendRequest, context, apolloServerConfig, }) {
28
+ return {
29
+ module: FederationModule_1,
30
+ providers: [
31
+ {
32
+ provide: tokens_1.ApolloGatewayInternal,
33
+ useFactory: () => new gateway_1.ApolloGateway({
34
+ serviceList,
35
+ buildService: ({ url }) => {
36
+ const auth = new auth_data_source_1.AuthenticatedDataSource({ url });
37
+ if (willSendRequest) {
38
+ auth.willSendRequest = willSendRequest.bind(auth);
39
+ }
40
+ return auth;
41
+ },
42
+ __exposeQueryPlanExperimental: true,
43
+ }),
44
+ },
45
+ {
46
+ provide: tokens_1.ApolloServerInternal,
47
+ deps: [tokens_1.ApolloGatewayInternal],
48
+ useFactory: (gateway) => new apollo_server_1.ApolloServer(Object.assign({ gateway, engine: false, context: context
49
+ ? context
50
+ : ({ req: { headers } }) => ({ headers }), subscriptions: false }, apolloServerConfig)),
51
+ },
52
+ {
53
+ provide: 'Listen',
54
+ deps: [tokens_1.ApolloServerInternal],
55
+ lazy: true,
56
+ useFactory: (server) => server.listen({ port }).then(({ url }) => {
57
+ console.log(`🚀 Gateway started at ${url}`);
58
+ }),
59
+ },
60
+ ],
61
+ };
62
+ }
63
+ };
64
+ FederationModule = FederationModule_1 = __decorate([
65
+ core_1.Module()
66
+ ], FederationModule);
67
+ exports.FederationModule = FederationModule;
68
+ __exportStar(require("./tokens"), exports);
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,6CAAgD;AAChD,qCAAyD;AACzD,iDAA6C;AAE7C,yDAA6D;AAC7D,qCAIkB;AAGlB,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IACpB,MAAM,CAAC,OAAO,CAAC,EACpB,IAAI,EACJ,WAAW,EACX,eAAe,EACf,OAAO,EACP,kBAAkB,GACM;QACxB,OAAO;YACL,MAAM,EAAE,kBAAgB;YACxB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,8BAAqB;oBAC9B,UAAU,EAAE,GAAG,EAAE,CACf,IAAI,uBAAa,CAAC;wBAChB,WAAW;wBACX,YAAY,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;4BACxB,MAAM,IAAI,GAAG,IAAI,0CAAuB,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;4BAClD,IAAI,eAAe,EAAE;gCACnB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;6BACnD;4BACD,OAAO,IAAI,CAAC;wBACd,CAAC;wBACD,6BAA6B,EAAE,IAAI;qBACpC,CAAC;iBACL;gBACD;oBACE,OAAO,EAAE,6BAAoB;oBAC7B,IAAI,EAAE,CAAC,8BAAqB,CAAC;oBAC7B,UAAU,EAAE,CAAC,OAA8B,EAAE,EAAE,CAC7C,IAAI,4BAAY,iBACd,OAAO,EACP,MAAM,EAAE,KAAK,EACb,OAAO,EAAE,OAAO;4BACd,CAAC,CAAC,OAAO;4BACT,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAC3C,aAAa,EAAE,KAAK,IACjB,kBAAkB,EACrB;iBACL;gBACD;oBACE,OAAO,EAAE,QAAQ;oBACjB,IAAI,EAAE,CAAC,6BAAoB,CAAC;oBAC5B,IAAI,EAAE,IAAI;oBACV,UAAU,EAAE,CAAC,MAA4B,EAAE,EAAE,CAC3C,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;wBACvC,OAAO,CAAC,GAAG,CAAC,yBAAyB,GAAG,EAAE,CAAC,CAAC;oBAC9C,CAAC,CAAC;iBACL;aACF;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AApDY,gBAAgB;IAD5B,aAAM,EAAE;GACI,gBAAgB,CAoD5B;AApDY,4CAAgB;AAsD7B,2CAAyB"}
@@ -0,0 +1,23 @@
1
+ import { ApolloGateway } from '@apollo/gateway';
2
+ import { InjectionToken } from '@rxdi/core';
3
+ import { ApolloServer } from 'apollo-server';
4
+ import { ContextFunction } from 'apollo-server-core';
5
+ import { ApolloServerExpressConfig } from 'apollo-server-express';
6
+ export declare const ApolloServerInternal: InjectionToken<ApolloServer>;
7
+ export declare type ApolloServerInternal = ApolloServer;
8
+ export declare const ApolloGatewayInternal: InjectionToken<ApolloGateway>;
9
+ export declare type ApolloGatewayInternal = ApolloGateway;
10
+ export declare type WillSendRequest = (ctx: {
11
+ request: any;
12
+ context: any;
13
+ }) => void;
14
+ export declare type FederationModuleOptions = {
15
+ port: number | string;
16
+ willSendRequest?: WillSendRequest;
17
+ context?: ContextFunction;
18
+ serviceList: {
19
+ name: string;
20
+ url: string;
21
+ }[];
22
+ apolloServerConfig?: ApolloServerExpressConfig;
23
+ };
package/dist/tokens.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApolloGatewayInternal = exports.ApolloServerInternal = void 0;
4
+ const core_1 = require("@rxdi/core");
5
+ exports.ApolloServerInternal = new core_1.InjectionToken();
6
+ exports.ApolloGatewayInternal = new core_1.InjectionToken();
7
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":";;;AACA,qCAA4C;AAK/B,QAAA,oBAAoB,GAAG,IAAI,qBAAc,EAAgB,CAAC;AAG1D,QAAA,qBAAqB,GAAG,IAAI,qBAAc,EAAiB,CAAC"}
package/jest.config.js ADDED
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ testEnvironment: 'node',
3
+ testPathIgnorePatterns: ['/node_modules/'],
4
+ coverageReporters: ['lcov', 'html'],
5
+ rootDir: './',
6
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'node'],
7
+ globals: {
8
+ __DEV__: true,
9
+ },
10
+ transform: {
11
+ '\\.(ts|tsx)$': 'ts-jest',
12
+ },
13
+ testRegex: '/test/.*\\.spec.(ts|tsx|js)$',
14
+ verbose: true,
15
+ collectCoverage: true,
16
+ };
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@gapi/federation",
3
+ "version": "1.8.120",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/Stradivario/gapi.git"
7
+ },
8
+ "scripts": {
9
+ "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
10
+ "delete-dist": "rm -rf dist",
11
+ "clean": "git clean -dxf",
12
+ "lint": "npx eslint . --ext .ts",
13
+ "test": "echo Tests",
14
+ "lint-fix": "npx eslint . --fix --ext .ts",
15
+ "build": "rm -rf dist && tsc || true",
16
+ "build-single-executable": "gapi build --single-executable",
17
+ "build-stand-alone": "npm run build-single-executable && rm -rf bin && mkdir bin && cp ./dist/index.js ./bin/federation-linux.js && cp ./dist/federation-linux ./bin"
18
+ },
19
+ "author": {
20
+ "name": "Kristian Tachev(Stradivario)",
21
+ "email": "kristiqn.tachev@gmail.com"
22
+ },
23
+ "keywords": [
24
+ "graphql",
25
+ "gapi",
26
+ "node",
27
+ "apollo",
28
+ "federation",
29
+ "federated-graph"
30
+ ],
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/Stradivario/gapi/issues"
34
+ },
35
+ "dependencies": {
36
+ "@apollo/gateway": "^0.14.1",
37
+ "@rxdi/core": "^0.7.114",
38
+ "apollo-server": "^2.12.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^13.11.1",
42
+ "@types/jest": "^25.2.1",
43
+ "@typescript-eslint/eslint-plugin": "^2.10.0",
44
+ "@typescript-eslint/parser": "^2.10.0",
45
+ "eslint": "^6.7.2",
46
+ "prettier": "^2.0.4",
47
+ "typescript": "^3.8.3",
48
+ "eslint-config-prettier": "^6.7.0",
49
+ "eslint-plugin-prettier": "^3.1.1",
50
+ "eslint-plugin-simple-import-sort": "^5.0.0",
51
+ "jest": "^25.5.4",
52
+ "ts-jest": "^25.4.0"
53
+ },
54
+ "bin": {
55
+ "federation": "./bin/federation-linux.js"
56
+ },
57
+ "main": "./dist/index.js",
58
+ "types": "./dist/index.d.ts",
59
+ "module": "./dist/index.js",
60
+ "typings": "./dist/index.d.ts"
61
+ }
@@ -0,0 +1,9 @@
1
+ import { RemoteGraphQLDataSource } from '@apollo/gateway';
2
+
3
+ export class AuthenticatedDataSource extends RemoteGraphQLDataSource {
4
+ willSendRequest({ request, context }) {
5
+ Object.entries(context.headers || {}).forEach(([key, value]) =>
6
+ request.http.headers.set(key, value),
7
+ );
8
+ }
9
+ }
package/src/index.ts ADDED
@@ -0,0 +1,67 @@
1
+ import { ApolloGateway } from '@apollo/gateway';
2
+ import { Module, ModuleWithProviders } from '@rxdi/core';
3
+ import { ApolloServer } from 'apollo-server';
4
+
5
+ import { AuthenticatedDataSource } from './auth-data-source';
6
+ import {
7
+ ApolloGatewayInternal,
8
+ ApolloServerInternal,
9
+ FederationModuleOptions,
10
+ } from './tokens';
11
+
12
+ @Module()
13
+ export class FederationModule {
14
+ public static forRoot({
15
+ port,
16
+ serviceList,
17
+ willSendRequest,
18
+ context,
19
+ apolloServerConfig,
20
+ }: FederationModuleOptions): ModuleWithProviders {
21
+ return {
22
+ module: FederationModule,
23
+ providers: [
24
+ {
25
+ provide: ApolloGatewayInternal,
26
+ useFactory: () =>
27
+ new ApolloGateway({
28
+ serviceList,
29
+ buildService: ({ url }) => {
30
+ const auth = new AuthenticatedDataSource({ url });
31
+ if (willSendRequest) {
32
+ auth.willSendRequest = willSendRequest.bind(auth);
33
+ }
34
+ return auth;
35
+ },
36
+ __exposeQueryPlanExperimental: true,
37
+ }),
38
+ },
39
+ {
40
+ provide: ApolloServerInternal,
41
+ deps: [ApolloGatewayInternal],
42
+ useFactory: (gateway: ApolloGatewayInternal) =>
43
+ new ApolloServer({
44
+ gateway,
45
+ engine: false,
46
+ context: context
47
+ ? context
48
+ : ({ req: { headers } }) => ({ headers }),
49
+ subscriptions: false,
50
+ ...apolloServerConfig,
51
+ }),
52
+ },
53
+ {
54
+ provide: 'Listen',
55
+ deps: [ApolloServerInternal],
56
+ lazy: true,
57
+ useFactory: (server: ApolloServerInternal) =>
58
+ server.listen({ port }).then(({ url }) => {
59
+ console.log(`🚀 Gateway started at ${url}`);
60
+ }),
61
+ },
62
+ ],
63
+ };
64
+ }
65
+ }
66
+
67
+ export * from './tokens';
package/src/main.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { Bootstrap, Container } from '@rxdi/core';
2
+ import { ContextFunction } from 'apollo-server-core';
3
+ import { existsSync, readFileSync } from 'fs';
4
+ import { printSchema } from 'graphql';
5
+
6
+ import {
7
+ ApolloGatewayInternal,
8
+ FederationModule,
9
+ FederationModuleOptions,
10
+ WillSendRequest,
11
+ } from '../src/index';
12
+
13
+ let context: ContextFunction;
14
+ let willSendRequest: WillSendRequest;
15
+ const [, , file] = process.argv;
16
+ const configFile =
17
+ file ||
18
+ (process.env.GATEWAY_CONFIG
19
+ ? process.env.GATEWAY_CONFIG
20
+ : './gateway.config.json');
21
+
22
+ try {
23
+ context = require('./gateway.context.js');
24
+ } catch (e) {}
25
+
26
+ try {
27
+ willSendRequest = require('./gateway.request.js');
28
+ } catch (e) {}
29
+
30
+ const config: FederationModuleOptions = existsSync(configFile)
31
+ ? JSON.parse(readFileSync(configFile, { encoding: 'utf-8' }))
32
+ : ({
33
+ port: process.env.GATEWAY_PORT,
34
+ serviceList: process.env.GATEWAY_SERVICE_LIST
35
+ ? JSON.parse(process.env.GATEWAY_SERVICE_LIST)
36
+ : [{ name: 'no-name', url: 'http://localhost:9000/graphql' }],
37
+ } as FederationModuleOptions);
38
+
39
+ Bootstrap(
40
+ FederationModule.forRoot({ ...config, context, willSendRequest }),
41
+ ).subscribe(
42
+ () =>
43
+ Container.get(ApolloGatewayInternal).onSchemaChange((schema) =>
44
+ console.log(`
45
+ ${process.env.GATEWAY_PRINT_SCHEMA ? `Schema: ${printSchema(schema)}` : ''}
46
+ Loaded remote graphs:
47
+ ${config.serviceList.map((s) => `\n1. ${s.name} - ${s.url}`)}
48
+ `),
49
+ ),
50
+ console.error,
51
+ );
package/src/tokens.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { ApolloGateway } from '@apollo/gateway';
2
+ import { InjectionToken } from '@rxdi/core';
3
+ import { ApolloServer } from 'apollo-server';
4
+ import { ContextFunction } from 'apollo-server-core';
5
+ import { ApolloServerExpressConfig } from 'apollo-server-express';
6
+
7
+ export const ApolloServerInternal = new InjectionToken<ApolloServer>();
8
+ export type ApolloServerInternal = ApolloServer;
9
+
10
+ export const ApolloGatewayInternal = new InjectionToken<ApolloGateway>();
11
+ export type ApolloGatewayInternal = ApolloGateway;
12
+ export type WillSendRequest = (ctx: { request; context }) => void;
13
+ export type FederationModuleOptions = {
14
+ port: number | string;
15
+ willSendRequest?: WillSendRequest;
16
+ context?: ContextFunction;
17
+ serviceList: { name: string; url: string }[];
18
+ apolloServerConfig?: ApolloServerExpressConfig;
19
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "module": "commonjs",
5
+ "target": "es6",
6
+ "baseUrl": ".",
7
+ "stripInternal": true,
8
+ "emitDecoratorMetadata": true,
9
+ "experimentalDecorators": true,
10
+ "moduleResolution": "node",
11
+ "outDir": "dist",
12
+ "removeComments": true,
13
+ "allowSyntheticDefaultImports": true,
14
+ "preserveConstEnums": true,
15
+ "sourceMap": true,
16
+ "strictNullChecks": false,
17
+ "forceConsistentCasingInFileNames": true,
18
+ "noFallthroughCasesInSwitch": true,
19
+ "noImplicitAny": false,
20
+ "noImplicitReturns": true,
21
+ "noImplicitThis": false,
22
+ "noUnusedLocals": true,
23
+ "noUnusedParameters": false,
24
+ "rootDir": "src",
25
+ "lib": ["es2017", "es2016", "es2015", "es6", "dom", "esnext.asynciterable"],
26
+ "skipLibCheck": true,
27
+ "typeRoots": ["node_modules/@types"]
28
+ },
29
+ "files": ["src/index.ts"]
30
+ }