@envelop/apollo-federation 2.4.0-alpha-db79afa.0 → 2.4.0-alpha-aca44e1.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.
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Plugin } from '@envelop/core';
2
- import { ApolloGateway } from '@apollo/gateway';
3
- import { KeyValueCache } from 'apollo-server-caching';
4
- import { CachePolicy, GraphQLRequestMetrics, Logger } from 'apollo-server-types';
1
+ import type { Plugin } from '@envelop/core';
2
+ import type { ApolloGateway } from '@apollo/gateway';
3
+ import type { KeyValueCache } from 'apollo-server-caching';
4
+ import type { CachePolicy, GraphQLRequestMetrics, Logger } from 'apollo-server-types';
5
5
  export interface ApolloFederationPluginConfig {
6
6
  gateway: ApolloGateway;
7
7
  metrics?: GraphQLRequestMetrics;
package/index.js CHANGED
@@ -3,10 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const graphql = require('graphql');
6
- const apolloServerCaching = require('apollo-server-caching');
7
- const apolloServerTypes = require('apollo-server-types');
6
+ const core = require('@envelop/core');
8
7
 
9
- // Taken from https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-core/src/cachePolicy.ts
10
8
  function newCachePolicy() {
11
9
  return {
12
10
  maxAge: undefined,
@@ -15,7 +13,7 @@ function newCachePolicy() {
15
13
  if (hint.maxAge !== undefined && (this.maxAge === undefined || hint.maxAge < this.maxAge)) {
16
14
  this.maxAge = hint.maxAge;
17
15
  }
18
- if (hint.scope !== undefined && this.scope !== apolloServerTypes.CacheScope.Private) {
16
+ if (hint.scope !== undefined && this.scope !== 'PRIVATE') {
19
17
  this.scope = hint.scope;
20
18
  }
21
19
  },
@@ -32,13 +30,21 @@ function newCachePolicy() {
32
30
  if (this.maxAge === undefined || this.maxAge === 0) {
33
31
  return null;
34
32
  }
35
- return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a : apolloServerTypes.CacheScope.Public };
33
+ return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a : 'PUBLIC' };
36
34
  },
37
35
  };
38
36
  }
39
37
 
38
+ function getDefaultCache() {
39
+ const lruCache = core.getInMemoryLRUCache();
40
+ return {
41
+ get: async (key) => lruCache.get(key),
42
+ set: async (key, value) => lruCache.set(key, value),
43
+ delete: async (key) => lruCache.delete(key),
44
+ };
45
+ }
40
46
  const useApolloFederation = (options) => {
41
- const { gateway, cache = new apolloServerCaching.InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = newCachePolicy(), } = options;
47
+ const { gateway, cache = getDefaultCache(), logger = console, metrics = Object.create(null), overallCachePolicy = newCachePolicy(), } = options;
42
48
  let schemaHash;
43
49
  const documentSourceMap = new WeakMap();
44
50
  return {
package/index.mjs CHANGED
@@ -1,8 +1,6 @@
1
1
  import { printSchema, Source, print, getOperationAST } from 'graphql';
2
- import { InMemoryLRUCache } from 'apollo-server-caching';
3
- import { CacheScope } from 'apollo-server-types';
2
+ import { getInMemoryLRUCache } from '@envelop/core';
4
3
 
5
- // Taken from https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-core/src/cachePolicy.ts
6
4
  function newCachePolicy() {
7
5
  return {
8
6
  maxAge: undefined,
@@ -11,7 +9,7 @@ function newCachePolicy() {
11
9
  if (hint.maxAge !== undefined && (this.maxAge === undefined || hint.maxAge < this.maxAge)) {
12
10
  this.maxAge = hint.maxAge;
13
11
  }
14
- if (hint.scope !== undefined && this.scope !== CacheScope.Private) {
12
+ if (hint.scope !== undefined && this.scope !== 'PRIVATE') {
15
13
  this.scope = hint.scope;
16
14
  }
17
15
  },
@@ -28,13 +26,21 @@ function newCachePolicy() {
28
26
  if (this.maxAge === undefined || this.maxAge === 0) {
29
27
  return null;
30
28
  }
31
- return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a : CacheScope.Public };
29
+ return { maxAge: this.maxAge, scope: (_a = this.scope) !== null && _a !== void 0 ? _a : 'PUBLIC' };
32
30
  },
33
31
  };
34
32
  }
35
33
 
34
+ function getDefaultCache() {
35
+ const lruCache = getInMemoryLRUCache();
36
+ return {
37
+ get: async (key) => lruCache.get(key),
38
+ set: async (key, value) => lruCache.set(key, value),
39
+ delete: async (key) => lruCache.delete(key),
40
+ };
41
+ }
36
42
  const useApolloFederation = (options) => {
37
- const { gateway, cache = new InMemoryLRUCache(), logger = console, metrics = Object.create(null), overallCachePolicy = newCachePolicy(), } = options;
43
+ const { gateway, cache = getDefaultCache(), logger = console, metrics = Object.create(null), overallCachePolicy = newCachePolicy(), } = options;
38
44
  let schemaHash;
39
45
  const documentSourceMap = new WeakMap();
40
46
  return {
@@ -1,2 +1,2 @@
1
- import { CachePolicy } from 'apollo-server-types';
1
+ import type { CachePolicy } from 'apollo-server-types';
2
2
  export declare function newCachePolicy(): CachePolicy;
package/package.json CHANGED
@@ -1,16 +1,12 @@
1
1
  {
2
2
  "name": "@envelop/apollo-federation",
3
- "version": "2.4.0-alpha-db79afa.0",
3
+ "version": "2.4.0-alpha-aca44e1.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@apollo/gateway": "^0.41.0 || ^0.42.0 || ^0.43.0",
7
- "@envelop/core": "2.4.0-alpha-db79afa.0",
7
+ "@envelop/core": "2.4.0-alpha-aca44e1.0",
8
8
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
9
9
  },
10
- "dependencies": {
11
- "apollo-server-caching": "^3.1.0",
12
- "apollo-server-types": "^3.2.0"
13
- },
14
10
  "repository": {
15
11
  "type": "git",
16
12
  "url": "https://github.com/dotansimha/envelop.git",