@graphql-hive/apollo 0.46.0-alpha-20251228154027-642b870bbba981b4b79341b2fbb051e340db927f → 0.46.0-alpha-20260105114825-21a288f5ce8422d00716d16112b4066f405342dc

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/cjs/index.js CHANGED
@@ -70,12 +70,58 @@ function addRequestWithHeaders(context, http) {
70
70
  }
71
71
  return context;
72
72
  }
73
- function createHive(clientOrOptions) {
74
- return (0, core_1.createHive)(Object.assign(Object.assign({}, clientOrOptions), { agent: Object.assign({ name: 'hive-client-yoga', version: version_js_1.version }, clientOrOptions.agent) }));
73
+ function getLoggerFromContext(ctx) {
74
+ if (ctx === null || ctx === void 0 ? void 0 : ctx.logger) {
75
+ return new logger_1.Logger({
76
+ level: 'debug',
77
+ writers: [
78
+ {
79
+ write(level, attrs, msg) {
80
+ const payload = attrs ? Object.assign({ msg }, attrs) : msg;
81
+ switch (level) {
82
+ case 'trace':
83
+ case 'debug':
84
+ ctx.logger.debug(payload);
85
+ break;
86
+ case 'info':
87
+ ctx.logger.info(payload);
88
+ break;
89
+ case 'warn':
90
+ ctx.logger.warn(payload);
91
+ break;
92
+ case 'error':
93
+ ctx.logger.error(payload);
94
+ break;
95
+ }
96
+ },
97
+ },
98
+ ],
99
+ });
100
+ }
101
+ return undefined;
102
+ }
103
+ function getPersistedDocumentsCacheFromContext(ctx) {
104
+ if (ctx === null || ctx === void 0 ? void 0 : ctx.cache) {
105
+ return {
106
+ async get(key) {
107
+ const value = await ctx.cache.get(key);
108
+ return value != null ? value : null;
109
+ },
110
+ set(key, value, options) {
111
+ return ctx.cache.set(key, value, options);
112
+ },
113
+ };
114
+ }
115
+ return undefined;
116
+ }
117
+ function createHive(clientOrOptions, ctx) {
118
+ const persistedDocumentsCache = getPersistedDocumentsCacheFromContext(ctx);
119
+ return (0, core_1.createHive)(Object.assign(Object.assign({ logger: getLoggerFromContext(ctx) }, clientOrOptions), { agent: Object.assign({ name: 'hive-client-apollo', version: version_js_1.version }, clientOrOptions.agent), experimental__persistedDocuments: clientOrOptions.experimental__persistedDocuments
120
+ ? Object.assign(Object.assign({}, clientOrOptions.experimental__persistedDocuments), { layer2Cache: persistedDocumentsCache || clientOrOptions.experimental__persistedDocuments.layer2Cache
121
+ ? Object.assign({ cache: persistedDocumentsCache }, (clientOrOptions.experimental__persistedDocuments.layer2Cache || {})) : undefined }) : undefined }));
75
122
  }
76
123
  function useHive(clientOrOptions) {
77
- const hive = (0, core_1.isHiveClient)(clientOrOptions) ? clientOrOptions : createHive(clientOrOptions);
78
- void hive.info();
124
+ let hive;
79
125
  return {
80
126
  requestDidStart(context) {
81
127
  var _a;
@@ -283,6 +329,8 @@ function useHive(clientOrOptions) {
283
329
  })();
284
330
  },
285
331
  serverWillStart(ctx) {
332
+ hive = (0, core_1.isHiveClient)(clientOrOptions) ? clientOrOptions : createHive(clientOrOptions, ctx);
333
+ void hive.info();
286
334
  // `engine` does not exist in v3
287
335
  const isLegacyV0 = 'engine' in ctx;
288
336
  hive.reportSchema({ schema: ctx.schema });
package/cjs/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- exports.version = '0.46.0-alpha-20251228154027-642b870bbba981b4b79341b2fbb051e340db927f';
4
+ exports.version = '0.46.0-alpha-20260105114825-21a288f5ce8422d00716d16112b4066f405342dc';
package/esm/index.js CHANGED
@@ -60,12 +60,58 @@ function addRequestWithHeaders(context, http) {
60
60
  }
61
61
  return context;
62
62
  }
63
- export function createHive(clientOrOptions) {
64
- return createHiveClient(Object.assign(Object.assign({}, clientOrOptions), { agent: Object.assign({ name: 'hive-client-yoga', version }, clientOrOptions.agent) }));
63
+ function getLoggerFromContext(ctx) {
64
+ if (ctx === null || ctx === void 0 ? void 0 : ctx.logger) {
65
+ return new Logger({
66
+ level: 'debug',
67
+ writers: [
68
+ {
69
+ write(level, attrs, msg) {
70
+ const payload = attrs ? Object.assign({ msg }, attrs) : msg;
71
+ switch (level) {
72
+ case 'trace':
73
+ case 'debug':
74
+ ctx.logger.debug(payload);
75
+ break;
76
+ case 'info':
77
+ ctx.logger.info(payload);
78
+ break;
79
+ case 'warn':
80
+ ctx.logger.warn(payload);
81
+ break;
82
+ case 'error':
83
+ ctx.logger.error(payload);
84
+ break;
85
+ }
86
+ },
87
+ },
88
+ ],
89
+ });
90
+ }
91
+ return undefined;
92
+ }
93
+ function getPersistedDocumentsCacheFromContext(ctx) {
94
+ if (ctx === null || ctx === void 0 ? void 0 : ctx.cache) {
95
+ return {
96
+ async get(key) {
97
+ const value = await ctx.cache.get(key);
98
+ return value != null ? value : null;
99
+ },
100
+ set(key, value, options) {
101
+ return ctx.cache.set(key, value, options);
102
+ },
103
+ };
104
+ }
105
+ return undefined;
106
+ }
107
+ export function createHive(clientOrOptions, ctx) {
108
+ const persistedDocumentsCache = getPersistedDocumentsCacheFromContext(ctx);
109
+ return createHiveClient(Object.assign(Object.assign({ logger: getLoggerFromContext(ctx) }, clientOrOptions), { agent: Object.assign({ name: 'hive-client-apollo', version }, clientOrOptions.agent), experimental__persistedDocuments: clientOrOptions.experimental__persistedDocuments
110
+ ? Object.assign(Object.assign({}, clientOrOptions.experimental__persistedDocuments), { layer2Cache: persistedDocumentsCache || clientOrOptions.experimental__persistedDocuments.layer2Cache
111
+ ? Object.assign({ cache: persistedDocumentsCache }, (clientOrOptions.experimental__persistedDocuments.layer2Cache || {})) : undefined }) : undefined }));
65
112
  }
66
113
  export function useHive(clientOrOptions) {
67
- const hive = isHiveClient(clientOrOptions) ? clientOrOptions : createHive(clientOrOptions);
68
- void hive.info();
114
+ let hive;
69
115
  return {
70
116
  requestDidStart(context) {
71
117
  var _a;
@@ -273,6 +319,8 @@ export function useHive(clientOrOptions) {
273
319
  })();
274
320
  },
275
321
  serverWillStart(ctx) {
322
+ hive = isHiveClient(clientOrOptions) ? clientOrOptions : createHive(clientOrOptions, ctx);
323
+ void hive.info();
276
324
  // `engine` does not exist in v3
277
325
  const isLegacyV0 = 'engine' in ctx;
278
326
  hive.reportSchema({ schema: ctx.schema });
package/esm/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '0.46.0-alpha-20251228154027-642b870bbba981b4b79341b2fbb051e340db927f';
1
+ export const version = '0.46.0-alpha-20260105114825-21a288f5ce8422d00716d16112b4066f405342dc';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-hive/apollo",
3
- "version": "0.46.0-alpha-20251228154027-642b870bbba981b4b79341b2fbb051e340db927f",
3
+ "version": "0.46.0-alpha-20260105114825-21a288f5ce8422d00716d16112b4066f405342dc",
4
4
  "description": "GraphQL Hive + Apollo Server",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "@graphql-hive/logger": "^1.0.9",
12
- "@graphql-hive/core": "0.19.0-alpha-20251228154027-642b870bbba981b4b79341b2fbb051e340db927f"
12
+ "@graphql-hive/core": "0.19.0-alpha-20260105114825-21a288f5ce8422d00716d16112b4066f405342dc"
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
@@ -1,4 +1,4 @@
1
- import type { ApolloServerPlugin } from '@apollo/server';
1
+ import type { ApolloServerPlugin, GraphQLServerContext } from '@apollo/server';
2
2
  import { HiveClient, HivePluginOptions, type CircuitBreakerConfiguration } from '@graphql-hive/core';
3
3
  import { Logger } from '@graphql-hive/logger';
4
4
  export { atLeastOnceSampler, createSchemaFetcher, createServicesFetcher, createSupergraphSDLFetcher, } from '@graphql-hive/core';
@@ -45,6 +45,6 @@ export declare function createSupergraphManager(args: CreateSupergraphManagerArg
45
45
  cleanup?: () => Promise<void>;
46
46
  }>;
47
47
  };
48
- export declare function createHive(clientOrOptions: HivePluginOptions): HiveClient;
48
+ export declare function createHive(clientOrOptions: HivePluginOptions, ctx?: GraphQLServerContext): HiveClient;
49
49
  export declare function useHive(clientOrOptions: HiveClient | HivePluginOptions): ApolloServerPlugin;
50
50
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { ApolloServerPlugin } from '@apollo/server';
1
+ import type { ApolloServerPlugin, GraphQLServerContext } from '@apollo/server';
2
2
  import { HiveClient, HivePluginOptions, type CircuitBreakerConfiguration } from '@graphql-hive/core';
3
3
  import { Logger } from '@graphql-hive/logger';
4
4
  export { atLeastOnceSampler, createSchemaFetcher, createServicesFetcher, createSupergraphSDLFetcher, } from '@graphql-hive/core';
@@ -45,6 +45,6 @@ export declare function createSupergraphManager(args: CreateSupergraphManagerArg
45
45
  cleanup?: () => Promise<void>;
46
46
  }>;
47
47
  };
48
- export declare function createHive(clientOrOptions: HivePluginOptions): HiveClient;
48
+ export declare function createHive(clientOrOptions: HivePluginOptions, ctx?: GraphQLServerContext): HiveClient;
49
49
  export declare function useHive(clientOrOptions: HiveClient | HivePluginOptions): ApolloServerPlugin;
50
50
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare const version = "0.46.0-alpha-20251228154027-642b870bbba981b4b79341b2fbb051e340db927f";
1
+ export declare const version = "0.46.0-alpha-20260105114825-21a288f5ce8422d00716d16112b4066f405342dc";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,2 +1,2 @@
1
- export declare const version = "0.46.0-alpha-20251228154027-642b870bbba981b4b79341b2fbb051e340db927f";
1
+ export declare const version = "0.46.0-alpha-20260105114825-21a288f5ce8422d00716d16112b4066f405342dc";
2
2
  //# sourceMappingURL=version.d.ts.map