@graphql-tools/executor-http 1.2.2 → 1.2.3-alpha-73dbe3a2dabb6b84105c4dac3586696daa3d4fcb

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @graphql-tools/executor-http
2
2
 
3
+ ## 1.2.3-alpha-73dbe3a2dabb6b84105c4dac3586696daa3d4fcb
4
+
5
+ ### Patch Changes
6
+
7
+ - [#381](https://github.com/graphql-hive/gateway/pull/381) [`73dbe3a`](https://github.com/graphql-hive/gateway/commit/73dbe3a2dabb6b84105c4dac3586696daa3d4fcb) Thanks [@ardatan](https://github.com/ardatan)! - Like HMAC Upstream Signature plugin, different components of the gateway were using different ways of serializing the execution request.
8
+ Some of them were ignoring `variables` if it is empty, some of not, this was causing the signature generation to be different for the same query.
9
+ For example, it was working as expected in Proxy mode, but not working as expected in Federation Gateway mode.
10
+
11
+ With this change, now we have a shared helper to serialize the upstream execution request with a memoized `print` function for query AST etc to have a consistent serialization so consistent signature generation for HMAC.
12
+
3
13
  ## 1.2.2
4
14
 
5
15
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1,13 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  var gatewayAbortSignalAny = require('@graphql-hive/gateway-abort-signal-any');
4
+ var executorCommon = require('@graphql-tools/executor-common');
4
5
  var utils = require('@graphql-tools/utils');
5
6
  var disposablestack = require('@whatwg-node/disposablestack');
6
7
  var fetch = require('@whatwg-node/fetch');
7
8
  var valueOrPromise = require('value-or-promise');
8
9
  var extractFiles = require('extract-files');
9
- var graphql = require('graphql');
10
10
  var repeater = require('@repeaterjs/repeater');
11
+ var graphql = require('graphql');
11
12
  var browser = require('meros/browser');
12
13
  var node = require('meros/node');
13
14
 
@@ -121,10 +122,6 @@ function isBlob(obj) {
121
122
  return typeof obj.arrayBuffer === "function";
122
123
  }
123
124
 
124
- const defaultPrintFn = utils.memoize1(function defaultPrintFn2(document) {
125
- return graphql.stripIgnoredCharacters(graphql.print(document));
126
- });
127
-
128
125
  function createAbortErrorReason() {
129
126
  return new Error("Executor was disposed.");
130
127
  }
@@ -302,7 +299,7 @@ function createSignalWrapper(signal) {
302
299
  });
303
300
  }
304
301
  function buildHTTPExecutor(options) {
305
- const printFn = options?.print ?? defaultPrintFn;
302
+ const printFn = options?.print ?? executorCommon.defaultPrintFn;
306
303
  const disposeCtrl = new AbortController();
307
304
  const sharedSignal = createSignalWrapper(disposeCtrl.signal);
308
305
  const baseExecutor = (request, excludeQuery) => {
@@ -355,12 +352,11 @@ function buildHTTPExecutor(options) {
355
352
  };
356
353
  const query = printFn(request.document);
357
354
  let serializeFn = function serialize() {
358
- return {
359
- query: excludeQuery ? void 0 : printFn(request.document),
360
- variables: (request.variables && Object.keys(request.variables).length) > 0 ? request.variables : void 0,
361
- operationName: request.operationName ? request.operationName : void 0,
362
- extensions: request.extensions && Object.keys(request.extensions).length > 0 ? request.extensions : void 0
363
- };
355
+ return executorCommon.executionRequestToGraphQLParams({
356
+ executionRequest: request,
357
+ excludeQuery,
358
+ printFn
359
+ });
364
360
  };
365
361
  if (options?.apq) {
366
362
  serializeFn = function serializeWithAPQ() {
@@ -370,12 +366,14 @@ function buildHTTPExecutor(options) {
370
366
  version: 1,
371
367
  sha256Hash
372
368
  };
373
- return {
374
- query: excludeQuery ? void 0 : query,
375
- variables: (request.variables && Object.keys(request.variables).length) > 0 ? request.variables : void 0,
376
- operationName: request.operationName ? request.operationName : void 0,
377
- extensions
378
- };
369
+ return executorCommon.executionRequestToGraphQLParams({
370
+ executionRequest: {
371
+ ...request,
372
+ extensions
373
+ },
374
+ excludeQuery,
375
+ printFn
376
+ });
379
377
  });
380
378
  };
381
379
  }
package/dist/index.d.cts CHANGED
@@ -80,12 +80,6 @@ interface HTTPExecutorOptions {
80
80
  */
81
81
  disposable?: boolean;
82
82
  }
83
- type SerializedRequest = {
84
- query?: string;
85
- variables?: Record<string, any>;
86
- operationName?: string;
87
- extensions?: any;
88
- };
89
83
  type HeadersConfig = Record<string, string>;
90
84
  declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & {
91
85
  fetch: SyncFetchFn;
@@ -98,4 +92,4 @@ declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>
98
92
  }): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
99
93
  declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
100
94
 
101
- export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SerializedRequest, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode };
95
+ export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode };
package/dist/index.d.ts CHANGED
@@ -80,12 +80,6 @@ interface HTTPExecutorOptions {
80
80
  */
81
81
  disposable?: boolean;
82
82
  }
83
- type SerializedRequest = {
84
- query?: string;
85
- variables?: Record<string, any>;
86
- operationName?: string;
87
- extensions?: any;
88
- };
89
83
  type HeadersConfig = Record<string, string>;
90
84
  declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & {
91
85
  fetch: SyncFetchFn;
@@ -98,4 +92,4 @@ declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>
98
92
  }): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
99
93
  declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>): DisposableAsyncExecutor<any, HTTPExecutorOptions>;
100
94
 
101
- export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SerializedRequest, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode };
95
+ export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode };
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { abortSignalAny } from '@graphql-hive/gateway-abort-signal-any';
2
- import { isAsyncIterable, isPromise, mapMaybePromise, memoize1, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, getOperationASTFromRequest } from '@graphql-tools/utils';
2
+ import { defaultPrintFn, executionRequestToGraphQLParams } from '@graphql-tools/executor-common';
3
+ import { isAsyncIterable, isPromise, mapMaybePromise, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, memoize1, getOperationASTFromRequest } from '@graphql-tools/utils';
3
4
  import { DisposableSymbols } from '@whatwg-node/disposablestack';
4
5
  import { File, FormData, TextEncoder, crypto, TextDecoder, fetch } from '@whatwg-node/fetch';
5
6
  import { ValueOrPromise } from 'value-or-promise';
6
7
  import { extractFiles, isExtractableFile } from 'extract-files';
7
- import { stripIgnoredCharacters, print, GraphQLError } from 'graphql';
8
8
  import { Repeater } from '@repeaterjs/repeater';
9
+ import { GraphQLError } from 'graphql';
9
10
  import { meros as meros$1 } from 'meros/browser';
10
11
  import { meros } from 'meros/node';
11
12
 
@@ -119,10 +120,6 @@ function isBlob(obj) {
119
120
  return typeof obj.arrayBuffer === "function";
120
121
  }
121
122
 
122
- const defaultPrintFn = memoize1(function defaultPrintFn2(document) {
123
- return stripIgnoredCharacters(print(document));
124
- });
125
-
126
123
  function createAbortErrorReason() {
127
124
  return new Error("Executor was disposed.");
128
125
  }
@@ -353,12 +350,11 @@ function buildHTTPExecutor(options) {
353
350
  };
354
351
  const query = printFn(request.document);
355
352
  let serializeFn = function serialize() {
356
- return {
357
- query: excludeQuery ? void 0 : printFn(request.document),
358
- variables: (request.variables && Object.keys(request.variables).length) > 0 ? request.variables : void 0,
359
- operationName: request.operationName ? request.operationName : void 0,
360
- extensions: request.extensions && Object.keys(request.extensions).length > 0 ? request.extensions : void 0
361
- };
353
+ return executionRequestToGraphQLParams({
354
+ executionRequest: request,
355
+ excludeQuery,
356
+ printFn
357
+ });
362
358
  };
363
359
  if (options?.apq) {
364
360
  serializeFn = function serializeWithAPQ() {
@@ -368,12 +364,14 @@ function buildHTTPExecutor(options) {
368
364
  version: 1,
369
365
  sha256Hash
370
366
  };
371
- return {
372
- query: excludeQuery ? void 0 : query,
373
- variables: (request.variables && Object.keys(request.variables).length) > 0 ? request.variables : void 0,
374
- operationName: request.operationName ? request.operationName : void 0,
375
- extensions
376
- };
367
+ return executionRequestToGraphQLParams({
368
+ executionRequest: {
369
+ ...request,
370
+ extensions
371
+ },
372
+ excludeQuery,
373
+ printFn
374
+ });
377
375
  });
378
376
  };
379
377
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/executor-http",
3
- "version": "1.2.2",
3
+ "version": "1.2.3-alpha-73dbe3a2dabb6b84105c4dac3586696daa3d4fcb",
4
4
  "type": "module",
5
5
  "description": "A set of utils for faster development of GraphQL tools",
6
6
  "repository": {
@@ -40,6 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@graphql-hive/gateway-abort-signal-any": "^0.0.2",
43
+ "@graphql-tools/executor-common": "^0.0.0",
43
44
  "@graphql-tools/utils": "^10.7.0",
44
45
  "@repeaterjs/repeater": "^3.0.4",
45
46
  "@whatwg-node/disposablestack": "^0.0.5",