@envelop/apollo-federation 2.4.0-alpha-234d044.0 → 2.4.0-alpha-e9434aa.0

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.
@@ -1,40 +1,11 @@
1
- import { printSchema, Source, print, getOperationAST } from 'graphql';
2
- import { InMemoryLRUCache } from 'apollo-server-caching';
3
- import { CacheScope } from 'apollo-server-types';
4
-
5
- // Taken from https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-core/src/cachePolicy.ts
6
- function newCachePolicy() {
7
- return {
8
- maxAge: undefined,
9
- scope: undefined,
10
- restrict(hint) {
11
- if (hint.maxAge !== undefined && (this.maxAge === undefined || hint.maxAge < this.maxAge)) {
12
- this.maxAge = hint.maxAge;
13
- }
14
- if (hint.scope !== undefined && this.scope !== CacheScope.Private) {
15
- this.scope = hint.scope;
16
- }
17
- },
18
- replace(hint) {
19
- if (hint.maxAge !== undefined) {
20
- this.maxAge = hint.maxAge;
21
- }
22
- if (hint.scope !== undefined) {
23
- this.scope = hint.scope;
24
- }
25
- },
26
- policyIfCacheable() {
27
- var _a;
28
- if (this.maxAge === undefined || this.maxAge === 0) {
29
- return null;
30
- }
31
- return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a : CacheScope.Public };
32
- },
33
- };
34
- }
35
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useApolloFederation = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const apollo_server_caching_1 = require("apollo-server-caching");
6
+ const newCachePolicy_js_1 = require("./newCachePolicy.js");
36
7
  const useApolloFederation = (options) => {
37
- const { gateway, cache = new InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = newCachePolicy(), } = options;
8
+ const { gateway, cache = new apollo_server_caching_1.InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = (0, newCachePolicy_js_1.newCachePolicy)(), } = options;
38
9
  let schemaHash;
39
10
  const documentSourceMap = new WeakMap();
40
11
  return {
@@ -46,13 +17,13 @@ const useApolloFederation = (options) => {
46
17
  logger.warn(`ApolloGateway doesn't have the schema loaded. Please make sure ApolloGateway is loaded with .load() method. Otherwise this plugin might not work consistently, especially if you are using ApolloServer.`);
47
18
  gateway.load();
48
19
  }
49
- gateway.onSchemaLoadOrUpdate(({ apiSchema, coreSupergraphSdl = printSchema(apiSchema) }) => {
20
+ gateway.onSchemaLoadOrUpdate(({ apiSchema, coreSupergraphSdl = (0, graphql_1.printSchema)(apiSchema) }) => {
50
21
  setSchema(apiSchema);
51
- schemaHash = (coreSupergraphSdl || printSchema(apiSchema));
22
+ schemaHash = (coreSupergraphSdl || (0, graphql_1.printSchema)(apiSchema));
52
23
  });
53
24
  },
54
25
  onParse({ params: { source } }) {
55
- const key = source instanceof Source ? source.body : source;
26
+ const key = source instanceof graphql_1.Source ? source.body : source;
56
27
  return ({ result }) => {
57
28
  if (!result || result instanceof Error)
58
29
  return;
@@ -63,10 +34,10 @@ const useApolloFederation = (options) => {
63
34
  var _a;
64
35
  let documentStr = documentSourceMap.get(args.document);
65
36
  if (documentStr == null) {
66
- documentStr = print(args.document);
37
+ documentStr = (0, graphql_1.print)(args.document);
67
38
  documentSourceMap.set(args.document, documentStr);
68
39
  }
69
- const operation = getOperationAST(args.document, (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined);
40
+ const operation = (0, graphql_1.getOperationAST)(args.document, (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined);
70
41
  if (!operation) {
71
42
  throw new Error(`Operation ${args.operationName || ''} cannot be found in ${documentStr}`);
72
43
  }
@@ -95,5 +66,4 @@ const useApolloFederation = (options) => {
95
66
  },
96
67
  };
97
68
  };
98
-
99
- export { useApolloFederation };
69
+ exports.useApolloFederation = useApolloFederation;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newCachePolicy = void 0;
4
+ // Taken from https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-core/src/cachePolicy.ts
5
+ const apollo_server_types_1 = require("apollo-server-types");
6
+ function newCachePolicy() {
7
+ return {
8
+ maxAge: undefined,
9
+ scope: undefined,
10
+ restrict(hint) {
11
+ if (hint.maxAge !== undefined && (this.maxAge === undefined || hint.maxAge < this.maxAge)) {
12
+ this.maxAge = hint.maxAge;
13
+ }
14
+ if (hint.scope !== undefined && this.scope !== apollo_server_types_1.CacheScope.Private) {
15
+ this.scope = hint.scope;
16
+ }
17
+ },
18
+ replace(hint) {
19
+ if (hint.maxAge !== undefined) {
20
+ this.maxAge = hint.maxAge;
21
+ }
22
+ if (hint.scope !== undefined) {
23
+ this.scope = hint.scope;
24
+ }
25
+ },
26
+ policyIfCacheable() {
27
+ var _a;
28
+ if (this.maxAge === undefined || this.maxAge === 0) {
29
+ return null;
30
+ }
31
+ return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a : apollo_server_types_1.CacheScope.Public };
32
+ },
33
+ };
34
+ }
35
+ exports.newCachePolicy = newCachePolicy;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,44 +1,11 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const graphql = require('graphql');
6
- const apolloServerCaching = require('apollo-server-caching');
7
- const apolloServerTypes = require('apollo-server-types');
8
-
9
- // Taken from https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-core/src/cachePolicy.ts
10
- function newCachePolicy() {
11
- return {
12
- maxAge: undefined,
13
- scope: undefined,
14
- restrict(hint) {
15
- if (hint.maxAge !== undefined && (this.maxAge === undefined || hint.maxAge < this.maxAge)) {
16
- this.maxAge = hint.maxAge;
17
- }
18
- if (hint.scope !== undefined && this.scope !== apolloServerTypes.CacheScope.Private) {
19
- this.scope = hint.scope;
20
- }
21
- },
22
- replace(hint) {
23
- if (hint.maxAge !== undefined) {
24
- this.maxAge = hint.maxAge;
25
- }
26
- if (hint.scope !== undefined) {
27
- this.scope = hint.scope;
28
- }
29
- },
30
- policyIfCacheable() {
31
- var _a;
32
- if (this.maxAge === undefined || this.maxAge === 0) {
33
- return null;
34
- }
35
- return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a : apolloServerTypes.CacheScope.Public };
36
- },
37
- };
38
- }
39
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useApolloFederation = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const apollo_server_caching_1 = require("apollo-server-caching");
6
+ const newCachePolicy_js_1 = require("./newCachePolicy.js");
40
7
  const useApolloFederation = (options) => {
41
- const { gateway, cache = new apolloServerCaching.InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = newCachePolicy(), } = options;
8
+ const { gateway, cache = new apollo_server_caching_1.InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = (0, newCachePolicy_js_1.newCachePolicy)(), } = options;
42
9
  let schemaHash;
43
10
  const documentSourceMap = new WeakMap();
44
11
  return {
@@ -50,13 +17,13 @@ const useApolloFederation = (options) => {
50
17
  logger.warn(`ApolloGateway doesn't have the schema loaded. Please make sure ApolloGateway is loaded with .load() method. Otherwise this plugin might not work consistently, especially if you are using ApolloServer.`);
51
18
  gateway.load();
52
19
  }
53
- gateway.onSchemaLoadOrUpdate(({ apiSchema, coreSupergraphSdl = graphql.printSchema(apiSchema) }) => {
20
+ gateway.onSchemaLoadOrUpdate(({ apiSchema, coreSupergraphSdl = (0, graphql_1.printSchema)(apiSchema) }) => {
54
21
  setSchema(apiSchema);
55
- schemaHash = (coreSupergraphSdl || graphql.printSchema(apiSchema));
22
+ schemaHash = (coreSupergraphSdl || (0, graphql_1.printSchema)(apiSchema));
56
23
  });
57
24
  },
58
25
  onParse({ params: { source } }) {
59
- const key = source instanceof graphql.Source ? source.body : source;
26
+ const key = source instanceof graphql_1.Source ? source.body : source;
60
27
  return ({ result }) => {
61
28
  if (!result || result instanceof Error)
62
29
  return;
@@ -67,10 +34,10 @@ const useApolloFederation = (options) => {
67
34
  var _a;
68
35
  let documentStr = documentSourceMap.get(args.document);
69
36
  if (documentStr == null) {
70
- documentStr = graphql.print(args.document);
37
+ documentStr = (0, graphql_1.print)(args.document);
71
38
  documentSourceMap.set(args.document, documentStr);
72
39
  }
73
- const operation = graphql.getOperationAST(args.document, (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined);
40
+ const operation = (0, graphql_1.getOperationAST)(args.document, (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined);
74
41
  if (!operation) {
75
42
  throw new Error(`Operation ${args.operationName || ''} cannot be found in ${documentStr}`);
76
43
  }
@@ -99,5 +66,4 @@ const useApolloFederation = (options) => {
99
66
  },
100
67
  };
101
68
  };
102
-
103
69
  exports.useApolloFederation = useApolloFederation;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newCachePolicy = void 0;
4
+ // Taken from https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-core/src/cachePolicy.ts
5
+ const apollo_server_types_1 = require("apollo-server-types");
6
+ function newCachePolicy() {
7
+ return {
8
+ maxAge: undefined,
9
+ scope: undefined,
10
+ restrict(hint) {
11
+ if (hint.maxAge !== undefined && (this.maxAge === undefined || hint.maxAge < this.maxAge)) {
12
+ this.maxAge = hint.maxAge;
13
+ }
14
+ if (hint.scope !== undefined && this.scope !== apollo_server_types_1.CacheScope.Private) {
15
+ this.scope = hint.scope;
16
+ }
17
+ },
18
+ replace(hint) {
19
+ if (hint.maxAge !== undefined) {
20
+ this.maxAge = hint.maxAge;
21
+ }
22
+ if (hint.scope !== undefined) {
23
+ this.scope = hint.scope;
24
+ }
25
+ },
26
+ policyIfCacheable() {
27
+ var _a;
28
+ if (this.maxAge === undefined || this.maxAge === 0) {
29
+ return null;
30
+ }
31
+ return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a : apollo_server_types_1.CacheScope.Public };
32
+ },
33
+ };
34
+ }
35
+ exports.newCachePolicy = newCachePolicy;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@envelop/apollo-federation",
3
- "version": "2.4.0-alpha-234d044.0",
3
+ "version": "2.4.0-alpha-e9434aa.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@apollo/gateway": "^0.41.0 || ^0.42.0 || ^0.43.0 || ^2.0.0",
7
- "@envelop/core": "^2.3.1",
6
+ "@envelop/core": "2.4.0-alpha-e9434aa.0",
7
+ "@apollo/gateway": "^0.41.0 || ^0.42.0 || ^0.43.0",
8
8
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
9
9
  },
10
10
  "dependencies": {
@@ -13,26 +13,47 @@
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "https://github.com/dotansimha/envelop.git",
16
+ "url": "https://github.com/n1ru4l/envelop.git",
17
17
  "directory": "packages/plugins/apollo-federation"
18
18
  },
19
19
  "author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
20
20
  "license": "MIT",
21
- "main": "index.js",
22
- "module": "index.mjs",
23
- "typings": "index.d.ts",
21
+ "main": "cjs/index.js",
22
+ "module": "esm/index.js",
23
+ "typings": "typings/index.d.ts",
24
24
  "typescript": {
25
- "definition": "index.d.ts"
25
+ "definition": "typings/index.d.ts"
26
26
  },
27
+ "type": "module",
27
28
  "exports": {
28
29
  ".": {
29
- "require": "./index.js",
30
- "import": "./index.mjs"
30
+ "require": {
31
+ "types": "./typings/index.d.ts",
32
+ "default": "./cjs/index.js"
33
+ },
34
+ "import": {
35
+ "types": "./typings/index.d.ts",
36
+ "default": "./esm/index.js"
37
+ },
38
+ "default": {
39
+ "types": "./typings/index.d.ts",
40
+ "default": "./esm/index.js"
41
+ }
31
42
  },
32
43
  "./*": {
33
- "require": "./*.js",
34
- "import": "./*.mjs"
44
+ "require": {
45
+ "types": "./typings/*.d.ts",
46
+ "default": "./cjs/*.js"
47
+ },
48
+ "import": {
49
+ "types": "./typings/*.d.ts",
50
+ "default": "./esm/*.js"
51
+ },
52
+ "default": {
53
+ "types": "./typings/*.d.ts",
54
+ "default": "./esm/*.js"
55
+ }
35
56
  },
36
57
  "./package.json": "./package.json"
37
58
  }
38
- }
59
+ }
File without changes
package/README.md DELETED
@@ -1,37 +0,0 @@
1
- ## `@envelop/apollo-federation`
2
-
3
- This plugin integrates Apollo Federation Gateway into Envelop.
4
-
5
- ## Getting Started
6
-
7
- ```
8
- yarn add @envelop/apollo-federation
9
- ```
10
-
11
- ## Usage Example
12
-
13
- ```ts
14
- import { envelop } from '@envelop/core';
15
- import { ApolloGateway } from '@apollo/gateway';
16
- import { useApolloFederation } from '@envelop/apollo-federation';
17
-
18
- // Initialize the gateway
19
- const gateway = new ApolloGateway({
20
- serviceList: [
21
- { name: 'accounts', url: 'http://localhost:4001' },
22
- { name: 'products', url: 'http://localhost:4002' },
23
- // ...additional subgraphs...
24
- ],
25
- });
26
-
27
- // Make sure all services are loaded
28
- await gateway.load();
29
-
30
- // Then pass it to the plugin configuration
31
- const getEnveloped = envelop({
32
- plugins: [
33
- // ... other plugins ...
34
- useApolloFederation({ gateway }),
35
- ],
36
- });
37
- ```