msw 0.21.3 → 0.22.3

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.
Files changed (49) hide show
  1. package/README.md +3 -9
  2. package/lib/esm/errors-deps.js +6 -7
  3. package/lib/esm/fetch-deps.js +44 -22
  4. package/lib/esm/{matchRequestUrl-deps.js → getCallFrame-deps.js} +32 -5
  5. package/lib/esm/graphql.js +601 -465
  6. package/lib/esm/index.js +56 -50
  7. package/lib/esm/mockServiceWorker.js +16 -10
  8. package/lib/esm/rest-deps.js +10 -1
  9. package/lib/esm/rest.js +1 -1
  10. package/lib/types/context/errors.d.ts +3 -3
  11. package/lib/types/context/json.d.ts +5 -1
  12. package/lib/types/index.d.ts +3 -2
  13. package/lib/types/native/index.d.ts +1 -7
  14. package/lib/types/node/createSetupServer.d.ts +2 -23
  15. package/{node/node/createSetupServer.d.ts → lib/types/node/glossary.d.ts} +12 -13
  16. package/lib/types/node/index.d.ts +1 -0
  17. package/lib/types/node/setupServer.d.ts +1 -7
  18. package/lib/types/response.d.ts +7 -2
  19. package/lib/types/rest.d.ts +60 -30
  20. package/lib/types/setupWorker/glossary.d.ts +22 -0
  21. package/lib/types/setupWorker/setupWorker.d.ts +1 -19
  22. package/lib/types/utils/handlers/requestHandler.d.ts +13 -1
  23. package/lib/types/utils/internal/getCallFrame.d.ts +4 -0
  24. package/lib/types/utils/internal/isObject.d.ts +4 -0
  25. package/lib/types/utils/internal/mergeRight.d.ts +1 -1
  26. package/lib/types/utils/request/onUnhandledRequest.d.ts +1 -1
  27. package/lib/umd/index.js +720 -519
  28. package/lib/umd/mockServiceWorker.js +16 -10
  29. package/native/index.js +2017 -125
  30. package/node/index.js +2017 -125
  31. package/package.json +34 -32
  32. package/lib/types/LiveStorage.d.ts +0 -17
  33. package/node/context/delay.d.ts +0 -11
  34. package/node/context/fetch.d.ts +0 -8
  35. package/node/context/set.d.ts +0 -2
  36. package/node/context/status.d.ts +0 -2
  37. package/node/node/index.d.ts +0 -5
  38. package/node/node/setupServer.d.ts +0 -7
  39. package/node/response.d.ts +0 -25
  40. package/node/utils/NetworkError.d.ts +0 -3
  41. package/node/utils/getResponse.d.ts +0 -14
  42. package/node/utils/handlers/requestHandler.d.ts +0 -74
  43. package/node/utils/handlers/requestHandlerUtils.d.ts +0 -4
  44. package/node/utils/internal/compose.d.ts +0 -5
  45. package/node/utils/internal/isNodeProcess.d.ts +0 -5
  46. package/node/utils/internal/jsonParse.d.ts +0 -5
  47. package/node/utils/request/getPublicUrlFromRequest.d.ts +0 -6
  48. package/node/utils/request/onUnhandledRequest.d.ts +0 -5
  49. package/node/utils/request/parseBody.d.ts +0 -5
package/lib/umd/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MockServiceWorker = {}));
5
5
  }(this, (function (exports) { 'use strict';
6
6
 
7
- var codes = {
7
+ var statuses = {
8
8
  "100": "Continue",
9
9
  "101": "Switching Protocols",
10
10
  "102": "Processing",
@@ -70,11 +70,6 @@
70
70
  "511": "Network Authentication Required"
71
71
  };
72
72
 
73
- var statuses = /*#__PURE__*/Object.freeze({
74
- __proto__: null,
75
- 'default': codes
76
- });
77
-
78
73
  const status = (statusCode, statusText) => {
79
74
  return (res) => {
80
75
  res.status = statusCode;
@@ -584,16 +579,54 @@
584
579
  };
585
580
 
586
581
  /**
587
- * Returns a GraphQL body payload.
582
+ * Determines if the given value is an object.
588
583
  */
589
- const data = (payload) => {
584
+ function isObject(value) {
585
+ return value != null && typeof value === 'object' && !Array.isArray(value);
586
+ }
587
+
588
+ /**
589
+ * Deeply merges two given objects with the right one
590
+ * having a priority during property assignment.
591
+ */
592
+ function mergeRight(left, right) {
593
+ return Object.entries(right).reduce((result, [key, rightValue]) => {
594
+ const leftValue = result[key];
595
+ if (Array.isArray(leftValue) && Array.isArray(rightValue)) {
596
+ result[key] = leftValue.concat(rightValue);
597
+ return result;
598
+ }
599
+ if (isObject(leftValue) && isObject(rightValue)) {
600
+ result[key] = mergeRight(leftValue, rightValue);
601
+ return result;
602
+ }
603
+ result[key] = rightValue;
604
+ return result;
605
+ }, Object.assign({}, left));
606
+ }
607
+
608
+ /**
609
+ * Sets the given value as the JSON body of the response.
610
+ * @example
611
+ * res(json({ key: 'value' }))
612
+ * res(json('Some string'))
613
+ * res(json([1, '2', false, { ok: true }]))
614
+ */
615
+ const json = (body, { merge = false } = {}) => {
590
616
  return (res) => {
591
617
  res.headers.set('Content-Type', 'application/json');
592
- res.body = JSON.stringify({ data: payload });
618
+ res.body = merge ? mergeRight(res.body || {}, body) : body;
593
619
  return res;
594
620
  };
595
621
  };
596
622
 
623
+ /**
624
+ * Returns a GraphQL body payload.
625
+ */
626
+ const data = (payload) => {
627
+ return json({ data: payload }, { merge: true });
628
+ };
629
+
597
630
  /**
598
631
  * Returns a boolean indicating if the current process is running in NodeJS environment.
599
632
  * @see https://github.com/mswjs/msw/pull/255
@@ -634,25 +667,13 @@
634
667
  };
635
668
 
636
669
  /**
637
- * Sets the given value as the JSON body of the response.
638
- * @example
639
- * res(json({ key: 'value' }))
640
- * res(json('Some string'))
641
- * res(json([1, '2', false, { ok: true }]))
642
- */
643
- const json = (body) => {
644
- return (res) => {
645
- res.headers.set('Content-Type', 'application/json');
646
- res.body = JSON.stringify(body);
647
- return res;
648
- };
649
- };
650
-
651
- /**
652
- * Returns a list of GraphQL errors.
670
+ * Sets a given list of GraphQL errors on the mocked response.
653
671
  */
654
672
  const errors = (errorsList) => {
655
- return json({ errors: errorsList });
673
+ if (errorsList == null) {
674
+ return (res) => res;
675
+ }
676
+ return json({ errors: errorsList }, { merge: true });
656
677
  };
657
678
 
658
679
  const useFetch = isNodeProcess() ? require('node-fetch') : window.fetch;
@@ -728,18 +749,18 @@
728
749
  });
729
750
 
730
751
  /*! *****************************************************************************
731
- Copyright (c) Microsoft Corporation.
752
+ Copyright (c) Microsoft Corporation. All rights reserved.
753
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
754
+ this file except in compliance with the License. You may obtain a copy of the
755
+ License at http://www.apache.org/licenses/LICENSE-2.0
732
756
 
733
- Permission to use, copy, modify, and/or distribute this software for any
734
- purpose with or without fee is hereby granted.
757
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
758
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
759
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
760
+ MERCHANTABLITY OR NON-INFRINGEMENT.
735
761
 
736
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
737
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
738
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
739
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
740
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
741
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
742
- PERFORMANCE OF THIS SOFTWARE.
762
+ See the Apache Version 2.0 License for specific language governing permissions
763
+ and limitations under the License.
743
764
  ***************************************************************************** */
744
765
 
745
766
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -920,6 +941,17 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
920
941
  }
921
942
  }
922
943
 
944
+ /**
945
+ * Internal response transformer to ensure response JSON body
946
+ * is always stringified.
947
+ */
948
+ const stringifyJsonBody = (res) => {
949
+ var _a, _b;
950
+ if (res.body && ((_b = (_a = res.headers) === null || _a === void 0 ? void 0 : _a.get('content-type')) === null || _b === void 0 ? void 0 : _b.endsWith('json'))) {
951
+ res.body = JSON.stringify(res.body);
952
+ }
953
+ return res;
954
+ };
923
955
  const defaultResponse = {
924
956
  status: 200,
925
957
  statusText: 'OK',
@@ -927,16 +959,23 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
927
959
  delay: 0,
928
960
  once: false,
929
961
  };
930
- function createResponseComposition(overrides = {}) {
962
+ const defaultResponseTransformers = [
963
+ stringifyJsonBody,
964
+ ];
965
+ function createResponseComposition(responseOverrides, defaultTransformers = defaultResponseTransformers) {
931
966
  return (...transformers) => {
932
- const resolvedResponse = Object.assign({}, defaultResponse, {
967
+ const initialResponse = Object.assign({}, defaultResponse, {
933
968
  headers: new lib.Headers({
934
969
  'x-powered-by': 'msw',
935
970
  }),
936
- }, overrides);
937
- if (transformers.length > 0) {
938
- return compose(...transformers)(resolvedResponse);
939
- }
971
+ }, responseOverrides);
972
+ const resolvedTransformers = [
973
+ ...defaultTransformers,
974
+ ...transformers,
975
+ ].filter(Boolean);
976
+ const resolvedResponse = resolvedTransformers.length > 0
977
+ ? compose(...resolvedTransformers)(initialResponse)
978
+ : initialResponse;
940
979
  return resolvedResponse;
941
980
  };
942
981
  }
@@ -2378,9 +2417,9 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
2378
2417
  });
2379
2418
  };
2380
2419
 
2381
- function onUnhandledRequest(request, onUnhandledRequest = 'bypass') {
2382
- if (typeof onUnhandledRequest === 'function') {
2383
- onUnhandledRequest(request);
2420
+ function onUnhandledRequest(request, handler = 'bypass') {
2421
+ if (typeof handler === 'function') {
2422
+ handler(request);
2384
2423
  return;
2385
2424
  }
2386
2425
  const publicUrl = getPublicUrlFromRequest(request);
@@ -2391,7 +2430,7 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
2391
2430
  rest.${request.method.toLowerCase()}('${publicUrl}', (req, res, ctx) => {
2392
2431
  return res(ctx.text('body'))
2393
2432
  })`;
2394
- switch (onUnhandledRequest) {
2433
+ switch (handler) {
2395
2434
  case 'error': {
2396
2435
  throw new Error(`[MSW] Error: ${message}`);
2397
2436
  }
@@ -2558,8 +2597,8 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
2558
2597
  const { payload: actualChecksum } = yield context.events.once('INTEGRITY_CHECK_RESPONSE');
2559
2598
  // Compare the response from the Service Worker and the
2560
2599
  // global variable set by webpack upon build.
2561
- if (actualChecksum !== "d1e0e502f550d40a34bee90822e4bf98") {
2562
- throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"d1e0e502f550d40a34bee90822e4bf98"}).`);
2600
+ if (actualChecksum !== "65d33ca82955e1c5928aed19d1bdf3f9") {
2601
+ throw new Error(`Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"65d33ca82955e1c5928aed19d1bdf3f9"}).`);
2563
2602
  }
2564
2603
  return serviceWorker;
2565
2604
  });
@@ -2590,30 +2629,6 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
2590
2629
  });
2591
2630
  }
2592
2631
 
2593
- function isObject(obj) {
2594
- return typeof obj === 'object';
2595
- }
2596
- /**
2597
- * Deeply merges two given objects with the right one
2598
- * having a priority during property assignment.
2599
- */
2600
- function mergeRight(a, b) {
2601
- const result = Object.assign({}, a);
2602
- Object.entries(b).forEach(([key, value]) => {
2603
- const existingValue = result[key];
2604
- if (Array.isArray(existingValue) && Array.isArray(value)) {
2605
- result[key] = existingValue.concat(value);
2606
- return;
2607
- }
2608
- if (isObject(existingValue) && isObject(value)) {
2609
- result[key] = mergeRight(existingValue, value);
2610
- return;
2611
- }
2612
- result[key] = value;
2613
- });
2614
- return result;
2615
- }
2616
-
2617
2632
  const DEFAULT_START_OPTIONS = {
2618
2633
  serviceWorker: {
2619
2634
  url: '/mockServiceWorker.js',
@@ -2803,6 +2818,18 @@ If this message still persists after updating, please report an issue: https://g
2803
2818
  resetHandlers(...nextHandlers) {
2804
2819
  context.requestHandlers = resetHandlers(requestHandlers, ...nextHandlers);
2805
2820
  },
2821
+ printHandlers() {
2822
+ context.requestHandlers.forEach((handler) => {
2823
+ const meta = handler.getMetaInfo();
2824
+ console.groupCollapsed(meta.header);
2825
+ console.log(`Declaration: ${meta.callFrame}`);
2826
+ console.log('Resolver: %s', handler.resolver);
2827
+ if (['rest'].includes(meta.type)) {
2828
+ console.log('Match:', `https://mswjs.io/repl?path=${meta.mask}`);
2829
+ }
2830
+ console.groupEnd();
2831
+ });
2832
+ },
2806
2833
  };
2807
2834
  }
2808
2835
 
@@ -2859,13 +2886,13 @@ If this message still persists after updating, please report an issue: https://g
2859
2886
  .replace(/\?/g, '\\?')
2860
2887
  // Ignore trailing slashes
2861
2888
  .replace(/\/+$/, '')
2862
- // Replace wildcard with any single character sequence
2863
- .replace(/\*+/g, '.+')
2889
+ // Replace wildcard with any zero-to-any character sequence
2890
+ .replace(/\*+/g, '.*')
2864
2891
  // Replace parameters with named capturing groups
2865
- .replace(/:([^\d|^\/][a-zA-Z0-9]*(?=(?:\/|\\.)|$))/g, (_, match) => `(?<${match}>.+?)`)
2892
+ .replace(/:([^\d|^\/][a-zA-Z0-9_]*(?=(?:\/|\\.)|$))/g, (_, paramName) => `(?<${paramName}>[^\/]+?)`)
2866
2893
  // Allow optional trailing slash
2867
2894
  .concat('(\\/|$)');
2868
- return new RegExp(pattern, 'g');
2895
+ return new RegExp(pattern, 'gi');
2869
2896
  };
2870
2897
 
2871
2898
  /**
@@ -2886,6 +2913,7 @@ If this message still persists after updating, please report an issue: https://g
2886
2913
 
2887
2914
  var getCleanUrl_1 = createCommonjsModule(function (module, exports) {
2888
2915
  Object.defineProperty(exports, "__esModule", { value: true });
2916
+ exports.getCleanUrl = void 0;
2889
2917
  /**
2890
2918
  * Removes query parameters and hashes from a given URL.
2891
2919
  */
@@ -2894,6 +2922,7 @@ If this message still persists after updating, please report an issue: https://g
2894
2922
  return [isAbsolute && url.origin, url.pathname].filter(Boolean).join('');
2895
2923
  }
2896
2924
  exports.getCleanUrl = getCleanUrl;
2925
+
2897
2926
  });
2898
2927
 
2899
2928
  /**
@@ -2952,6 +2981,31 @@ If this message still persists after updating, please report an issue: https://g
2952
2981
  return match(cleanMask, cleanRequestUrl);
2953
2982
  }
2954
2983
 
2984
+ /**
2985
+ * Return the stack trace frame of a function's invocation.
2986
+ */
2987
+ function getCallFrame() {
2988
+ try {
2989
+ const inspectionError = new Error();
2990
+ inspectionError.name = 'Inspection Error';
2991
+ throw inspectionError;
2992
+ }
2993
+ catch (error) {
2994
+ const frames = error.stack.split('\n');
2995
+ // Get the first frame that doesn't reference the library's internal trace.
2996
+ // Assume that frame is the invocation frame.
2997
+ const declarationFrame = frames.slice(1).find((frame) => {
2998
+ return !/(node_modules)?\/lib\/(umd|esm)\//.test(frame);
2999
+ });
3000
+ if (!declarationFrame) {
3001
+ return;
3002
+ }
3003
+ // Extract file reference from the stack frame.
3004
+ const [, declarationPath] = declarationFrame.match(/\((.+?)\)$/) || [];
3005
+ return declarationPath;
3006
+ }
3007
+ }
3008
+
2955
3009
  (function (RESTMethods) {
2956
3010
  RESTMethods["HEAD"] = "HEAD";
2957
3011
  RESTMethods["GET"] = "GET";
@@ -2975,6 +3029,7 @@ If this message still persists after updating, please report an issue: https://g
2975
3029
  const createRestHandler = (method) => {
2976
3030
  return (mask, resolver) => {
2977
3031
  const resolvedMask = getUrlByMask(mask);
3032
+ const callFrame = getCallFrame();
2978
3033
  return {
2979
3034
  parse(req) {
2980
3035
  // Match the request during parsing to prevent matching it twice
@@ -3025,6 +3080,14 @@ ${queryParams
3025
3080
  console.log('Response', loggedResponse);
3026
3081
  console.groupEnd();
3027
3082
  },
3083
+ getMetaInfo() {
3084
+ return {
3085
+ type: 'rest',
3086
+ header: `[rest] ${method} ${mask.toString()}`,
3087
+ mask,
3088
+ callFrame,
3089
+ };
3090
+ },
3028
3091
  };
3029
3092
  };
3030
3093
  };
@@ -3038,154 +3101,19 @@ ${queryParams
3038
3101
  options: createRestHandler(exports.RESTMethods.OPTIONS),
3039
3102
  };
3040
3103
 
3041
- // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
3042
- var nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;
3043
-
3044
3104
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3045
- var MAX_ARRAY_LENGTH = 10;
3046
- var MAX_RECURSIVE_DEPTH = 2;
3047
- /**
3048
- * Used to print values in error messages.
3049
- */
3050
-
3051
- function inspect(value) {
3052
- return formatValue(value, []);
3053
- }
3054
-
3055
- function formatValue(value, seenValues) {
3056
- switch (_typeof(value)) {
3057
- case 'string':
3058
- return JSON.stringify(value);
3059
-
3060
- case 'function':
3061
- return value.name ? "[function ".concat(value.name, "]") : '[function]';
3062
-
3063
- case 'object':
3064
- if (value === null) {
3065
- return 'null';
3066
- }
3067
-
3068
- return formatObjectValue(value, seenValues);
3069
-
3070
- default:
3071
- return String(value);
3072
- }
3073
- }
3074
-
3075
- function formatObjectValue(value, previouslySeenValues) {
3076
- if (previouslySeenValues.indexOf(value) !== -1) {
3077
- return '[Circular]';
3078
- }
3079
-
3080
- var seenValues = [].concat(previouslySeenValues, [value]);
3081
- var customInspectFn = getCustomFn(value);
3082
-
3083
- if (customInspectFn !== undefined) {
3084
- // $FlowFixMe(>=0.90.0)
3085
- var customValue = customInspectFn.call(value); // check for infinite recursion
3086
-
3087
- if (customValue !== value) {
3088
- return typeof customValue === 'string' ? customValue : formatValue(customValue, seenValues);
3089
- }
3090
- } else if (Array.isArray(value)) {
3091
- return formatArray(value, seenValues);
3092
- }
3093
-
3094
- return formatObject(value, seenValues);
3095
- }
3096
-
3097
- function formatObject(object, seenValues) {
3098
- var keys = Object.keys(object);
3099
-
3100
- if (keys.length === 0) {
3101
- return '{}';
3102
- }
3103
-
3104
- if (seenValues.length > MAX_RECURSIVE_DEPTH) {
3105
- return '[' + getObjectTag(object) + ']';
3106
- }
3107
-
3108
- var properties = keys.map(function (key) {
3109
- var value = formatValue(object[key], seenValues);
3110
- return key + ': ' + value;
3111
- });
3112
- return '{ ' + properties.join(', ') + ' }';
3113
- }
3114
-
3115
- function formatArray(array, seenValues) {
3116
- if (array.length === 0) {
3117
- return '[]';
3118
- }
3119
-
3120
- if (seenValues.length > MAX_RECURSIVE_DEPTH) {
3121
- return '[Array]';
3122
- }
3123
-
3124
- var len = Math.min(MAX_ARRAY_LENGTH, array.length);
3125
- var remaining = array.length - len;
3126
- var items = [];
3127
-
3128
- for (var i = 0; i < len; ++i) {
3129
- items.push(formatValue(array[i], seenValues));
3130
- }
3131
-
3132
- if (remaining === 1) {
3133
- items.push('... 1 more item');
3134
- } else if (remaining > 1) {
3135
- items.push("... ".concat(remaining, " more items"));
3136
- }
3137
-
3138
- return '[' + items.join(', ') + ']';
3139
- }
3140
-
3141
- function getCustomFn(object) {
3142
- var customInspectFn = object[String(nodejsCustomInspectSymbol)];
3143
-
3144
- if (typeof customInspectFn === 'function') {
3145
- return customInspectFn;
3146
- }
3147
-
3148
- if (typeof object.inspect === 'function') {
3149
- return object.inspect;
3150
- }
3151
- }
3152
-
3153
- function getObjectTag(object) {
3154
- var tag = Object.prototype.toString.call(object).replace(/^\[object /, '').replace(/]$/, '');
3155
-
3156
- if (tag === 'Object' && typeof object.constructor === 'function') {
3157
- var name = object.constructor.name;
3158
-
3159
- if (typeof name === 'string' && name !== '') {
3160
- return name;
3161
- }
3162
- }
3163
-
3164
- return tag;
3165
- }
3166
-
3167
- function devAssert(condition, message) {
3168
- var booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js')
3169
-
3170
- if (!booleanCondition) {
3171
- throw new Error(message);
3172
- }
3173
- }
3174
-
3175
- function _typeof$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); }
3176
3105
 
3177
3106
  /**
3178
3107
  * Return true if `value` is object-like. A value is object-like if it's not
3179
3108
  * `null` and has a `typeof` result of "object".
3180
3109
  */
3181
3110
  function isObjectLike(value) {
3182
- return _typeof$1(value) == 'object' && value !== null;
3111
+ return _typeof(value) == 'object' && value !== null;
3183
3112
  }
3184
3113
 
3185
3114
  // In ES2015 (or a polyfilled) environment, this will be Symbol.iterator
3186
3115
 
3187
- var SYMBOL_TO_STRING_TAG = // $FlowFixMe Flow doesn't define `Symbol.toStringTag` yet
3188
- typeof Symbol === 'function' ? Symbol.toStringTag : '@@toStringTag';
3116
+ var SYMBOL_TO_STRING_TAG = typeof Symbol === 'function' && Symbol.toStringTag != null ? Symbol.toStringTag : '@@toStringTag';
3189
3117
 
3190
3118
  /**
3191
3119
  * Represents a location in a Source.
@@ -3278,7 +3206,7 @@ ${queryParams
3278
3206
  return whitespace(len - str.length) + str;
3279
3207
  }
3280
3208
 
3281
- function _typeof$2(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$2 = function _typeof(obj) { return typeof obj; }; } else { _typeof$2 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$2(obj); }
3209
+ function _typeof$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); }
3282
3210
 
3283
3211
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3284
3212
 
@@ -3290,7 +3218,7 @@ ${queryParams
3290
3218
 
3291
3219
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
3292
3220
 
3293
- function _possibleConstructorReturn(self, call) { if (call && (_typeof$2(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
3221
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof$1(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
3294
3222
 
3295
3223
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
3296
3224
 
@@ -3509,7 +3437,7 @@ ${queryParams
3509
3437
  value: function toString() {
3510
3438
  return printError(this);
3511
3439
  } // FIXME: workaround to not break chai comparisons, should be remove in v16
3512
- // $FlowFixMe Flow doesn't support computed properties yet
3440
+ // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
3513
3441
 
3514
3442
  }, {
3515
3443
  key: SYMBOL_TO_STRING_TAG,
@@ -3626,6 +3554,9 @@ ${queryParams
3626
3554
  }
3627
3555
  }
3628
3556
 
3557
+ // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
3558
+ var nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;
3559
+
3629
3560
  /**
3630
3561
  * The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
3631
3562
  */
@@ -3750,42 +3681,6 @@ ${queryParams
3750
3681
  * The list of all possible AST node types.
3751
3682
  */
3752
3683
 
3753
- function _defineProperties$1(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
3754
-
3755
- function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; }
3756
-
3757
- /**
3758
- * A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
3759
- * optional, but they are useful for clients who store GraphQL documents in source files.
3760
- * For example, if the GraphQL input starts at line 40 in a file named `Foo.graphql`, it might
3761
- * be useful for `name` to be `"Foo.graphql"` and location to be `{ line: 40, column: 1 }`.
3762
- * The `line` and `column` properties in `locationOffset` are 1-indexed.
3763
- */
3764
- var Source = /*#__PURE__*/function () {
3765
- function Source(body) {
3766
- var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GraphQL request';
3767
- var locationOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
3768
- line: 1,
3769
- column: 1
3770
- };
3771
- this.body = body;
3772
- this.name = name;
3773
- this.locationOffset = locationOffset;
3774
- this.locationOffset.line > 0 || devAssert(0, 'line in locationOffset is 1-indexed and must be positive.');
3775
- this.locationOffset.column > 0 || devAssert(0, 'column in locationOffset is 1-indexed and must be positive.');
3776
- } // $FlowFixMe Flow doesn't support computed properties yet
3777
-
3778
-
3779
- _createClass$1(Source, [{
3780
- key: SYMBOL_TO_STRING_TAG,
3781
- get: function get() {
3782
- return 'Source';
3783
- }
3784
- }]);
3785
-
3786
- return Source;
3787
- }();
3788
-
3789
3684
  /**
3790
3685
  * An exported enum describing the different kinds of tokens that the
3791
3686
  * lexer emits.
@@ -3818,8 +3713,213 @@ ${queryParams
3818
3713
  * The enum type representing the token kinds values.
3819
3714
  */
3820
3715
 
3716
+ function _typeof$2(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$2 = function _typeof(obj) { return typeof obj; }; } else { _typeof$2 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$2(obj); }
3717
+ var MAX_ARRAY_LENGTH = 10;
3718
+ var MAX_RECURSIVE_DEPTH = 2;
3821
3719
  /**
3822
- * The set of allowed directive location values.
3720
+ * Used to print values in error messages.
3721
+ */
3722
+
3723
+ function inspect(value) {
3724
+ return formatValue(value, []);
3725
+ }
3726
+
3727
+ function formatValue(value, seenValues) {
3728
+ switch (_typeof$2(value)) {
3729
+ case 'string':
3730
+ return JSON.stringify(value);
3731
+
3732
+ case 'function':
3733
+ return value.name ? "[function ".concat(value.name, "]") : '[function]';
3734
+
3735
+ case 'object':
3736
+ if (value === null) {
3737
+ return 'null';
3738
+ }
3739
+
3740
+ return formatObjectValue(value, seenValues);
3741
+
3742
+ default:
3743
+ return String(value);
3744
+ }
3745
+ }
3746
+
3747
+ function formatObjectValue(value, previouslySeenValues) {
3748
+ if (previouslySeenValues.indexOf(value) !== -1) {
3749
+ return '[Circular]';
3750
+ }
3751
+
3752
+ var seenValues = [].concat(previouslySeenValues, [value]);
3753
+ var customInspectFn = getCustomFn(value);
3754
+
3755
+ if (customInspectFn !== undefined) {
3756
+ var customValue = customInspectFn.call(value); // check for infinite recursion
3757
+
3758
+ if (customValue !== value) {
3759
+ return typeof customValue === 'string' ? customValue : formatValue(customValue, seenValues);
3760
+ }
3761
+ } else if (Array.isArray(value)) {
3762
+ return formatArray(value, seenValues);
3763
+ }
3764
+
3765
+ return formatObject(value, seenValues);
3766
+ }
3767
+
3768
+ function formatObject(object, seenValues) {
3769
+ var keys = Object.keys(object);
3770
+
3771
+ if (keys.length === 0) {
3772
+ return '{}';
3773
+ }
3774
+
3775
+ if (seenValues.length > MAX_RECURSIVE_DEPTH) {
3776
+ return '[' + getObjectTag(object) + ']';
3777
+ }
3778
+
3779
+ var properties = keys.map(function (key) {
3780
+ var value = formatValue(object[key], seenValues);
3781
+ return key + ': ' + value;
3782
+ });
3783
+ return '{ ' + properties.join(', ') + ' }';
3784
+ }
3785
+
3786
+ function formatArray(array, seenValues) {
3787
+ if (array.length === 0) {
3788
+ return '[]';
3789
+ }
3790
+
3791
+ if (seenValues.length > MAX_RECURSIVE_DEPTH) {
3792
+ return '[Array]';
3793
+ }
3794
+
3795
+ var len = Math.min(MAX_ARRAY_LENGTH, array.length);
3796
+ var remaining = array.length - len;
3797
+ var items = [];
3798
+
3799
+ for (var i = 0; i < len; ++i) {
3800
+ items.push(formatValue(array[i], seenValues));
3801
+ }
3802
+
3803
+ if (remaining === 1) {
3804
+ items.push('... 1 more item');
3805
+ } else if (remaining > 1) {
3806
+ items.push("... ".concat(remaining, " more items"));
3807
+ }
3808
+
3809
+ return '[' + items.join(', ') + ']';
3810
+ }
3811
+
3812
+ function getCustomFn(object) {
3813
+ var customInspectFn = object[String(nodejsCustomInspectSymbol)];
3814
+
3815
+ if (typeof customInspectFn === 'function') {
3816
+ return customInspectFn;
3817
+ }
3818
+
3819
+ if (typeof object.inspect === 'function') {
3820
+ return object.inspect;
3821
+ }
3822
+ }
3823
+
3824
+ function getObjectTag(object) {
3825
+ var tag = Object.prototype.toString.call(object).replace(/^\[object /, '').replace(/]$/, '');
3826
+
3827
+ if (tag === 'Object' && typeof object.constructor === 'function') {
3828
+ var name = object.constructor.name;
3829
+
3830
+ if (typeof name === 'string' && name !== '') {
3831
+ return name;
3832
+ }
3833
+ }
3834
+
3835
+ return tag;
3836
+ }
3837
+
3838
+ function devAssert(condition, message) {
3839
+ var booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js')
3840
+
3841
+ if (!booleanCondition) {
3842
+ throw new Error(message);
3843
+ }
3844
+ }
3845
+
3846
+ /**
3847
+ * A replacement for instanceof which includes an error warning when multi-realm
3848
+ * constructors are detected.
3849
+ */
3850
+ // See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
3851
+ // See: https://webpack.js.org/guides/production/
3852
+ var instanceOf = process.env.NODE_ENV === 'production' ? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
3853
+ // eslint-disable-next-line no-shadow
3854
+ function instanceOf(value, constructor) {
3855
+ return value instanceof constructor;
3856
+ } : // eslint-disable-next-line no-shadow
3857
+ function instanceOf(value, constructor) {
3858
+ if (value instanceof constructor) {
3859
+ return true;
3860
+ }
3861
+
3862
+ if (value) {
3863
+ var valueClass = value.constructor;
3864
+ var className = constructor.name;
3865
+
3866
+ if (className && valueClass && valueClass.name === className) {
3867
+ throw new Error("Cannot use ".concat(className, " \"").concat(value, "\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results."));
3868
+ }
3869
+ }
3870
+
3871
+ return false;
3872
+ };
3873
+
3874
+ function _defineProperties$1(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
3875
+
3876
+ function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; }
3877
+
3878
+ /**
3879
+ * A representation of source input to GraphQL. The `name` and `locationOffset` parameters are
3880
+ * optional, but they are useful for clients who store GraphQL documents in source files.
3881
+ * For example, if the GraphQL input starts at line 40 in a file named `Foo.graphql`, it might
3882
+ * be useful for `name` to be `"Foo.graphql"` and location to be `{ line: 40, column: 1 }`.
3883
+ * The `line` and `column` properties in `locationOffset` are 1-indexed.
3884
+ */
3885
+ var Source = /*#__PURE__*/function () {
3886
+ function Source(body) {
3887
+ var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'GraphQL request';
3888
+ var locationOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
3889
+ line: 1,
3890
+ column: 1
3891
+ };
3892
+ typeof body === 'string' || devAssert(0, "Body must be a string. Received: ".concat(inspect(body), "."));
3893
+ this.body = body;
3894
+ this.name = name;
3895
+ this.locationOffset = locationOffset;
3896
+ this.locationOffset.line > 0 || devAssert(0, 'line in locationOffset is 1-indexed and must be positive.');
3897
+ this.locationOffset.column > 0 || devAssert(0, 'column in locationOffset is 1-indexed and must be positive.');
3898
+ } // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
3899
+
3900
+
3901
+ _createClass$1(Source, [{
3902
+ key: SYMBOL_TO_STRING_TAG,
3903
+ get: function get() {
3904
+ return 'Source';
3905
+ }
3906
+ }]);
3907
+
3908
+ return Source;
3909
+ }();
3910
+ /**
3911
+ * Test if the given value is a Source object.
3912
+ *
3913
+ * @internal
3914
+ */
3915
+
3916
+ // eslint-disable-next-line no-redeclare
3917
+ function isSource(source) {
3918
+ return instanceOf(source, Source);
3919
+ }
3920
+
3921
+ /**
3922
+ * The set of allowed directive location values.
3823
3923
  */
3824
3924
  var DirectiveLocation = Object.freeze({
3825
3925
  // Request Definitions
@@ -3860,7 +3960,7 @@ ${queryParams
3860
3960
  // Expand a block string's raw value into independent lines.
3861
3961
  var lines = rawString.split(/\r\n|[\n\r]/g); // Remove common indentation from all lines but first.
3862
3962
 
3863
- var commonIndent = getBlockStringIndentation(lines);
3963
+ var commonIndent = getBlockStringIndentation(rawString);
3864
3964
 
3865
3965
  if (commonIndent !== 0) {
3866
3966
  for (var i = 1; i < lines.length; i++) {
@@ -3869,56 +3969,78 @@ ${queryParams
3869
3969
  } // Remove leading and trailing blank lines.
3870
3970
 
3871
3971
 
3872
- while (lines.length > 0 && isBlank(lines[0])) {
3873
- lines.shift();
3972
+ var startLine = 0;
3973
+
3974
+ while (startLine < lines.length && isBlank(lines[startLine])) {
3975
+ ++startLine;
3874
3976
  }
3875
3977
 
3876
- while (lines.length > 0 && isBlank(lines[lines.length - 1])) {
3877
- lines.pop();
3978
+ var endLine = lines.length;
3979
+
3980
+ while (endLine > startLine && isBlank(lines[endLine - 1])) {
3981
+ --endLine;
3878
3982
  } // Return a string of the lines joined with U+000A.
3879
3983
 
3880
3984
 
3881
- return lines.join('\n');
3985
+ return lines.slice(startLine, endLine).join('\n');
3986
+ }
3987
+
3988
+ function isBlank(str) {
3989
+ for (var i = 0; i < str.length; ++i) {
3990
+ if (str[i] !== ' ' && str[i] !== '\t') {
3991
+ return false;
3992
+ }
3993
+ }
3994
+
3995
+ return true;
3882
3996
  }
3883
3997
  /**
3884
3998
  * @internal
3885
3999
  */
3886
4000
 
3887
- function getBlockStringIndentation(lines) {
3888
- var commonIndent = null;
3889
4001
 
3890
- for (var i = 1; i < lines.length; i++) {
3891
- var line = lines[i];
3892
- var indent = leadingWhitespace(line);
4002
+ function getBlockStringIndentation(value) {
4003
+ var _commonIndent;
3893
4004
 
3894
- if (indent === line.length) {
3895
- continue; // skip empty lines
3896
- }
4005
+ var isFirstLine = true;
4006
+ var isEmptyLine = true;
4007
+ var indent = 0;
4008
+ var commonIndent = null;
4009
+
4010
+ for (var i = 0; i < value.length; ++i) {
4011
+ switch (value.charCodeAt(i)) {
4012
+ case 13:
4013
+ // \r
4014
+ if (value.charCodeAt(i + 1) === 10) {
4015
+ ++i; // skip \r\n as one symbol
4016
+ }
3897
4017
 
3898
- if (commonIndent === null || indent < commonIndent) {
3899
- commonIndent = indent;
4018
+ // falls through
3900
4019
 
3901
- if (commonIndent === 0) {
4020
+ case 10:
4021
+ // \n
4022
+ isFirstLine = false;
4023
+ isEmptyLine = true;
4024
+ indent = 0;
3902
4025
  break;
3903
- }
3904
- }
3905
- }
3906
4026
 
3907
- return commonIndent === null ? 0 : commonIndent;
3908
- }
4027
+ case 9: // \t
3909
4028
 
3910
- function leadingWhitespace(str) {
3911
- var i = 0;
4029
+ case 32:
4030
+ // <space>
4031
+ ++indent;
4032
+ break;
3912
4033
 
3913
- while (i < str.length && (str[i] === ' ' || str[i] === '\t')) {
3914
- i++;
4034
+ default:
4035
+ if (isEmptyLine && !isFirstLine && (commonIndent === null || indent < commonIndent)) {
4036
+ commonIndent = indent;
4037
+ }
4038
+
4039
+ isEmptyLine = false;
4040
+ }
3915
4041
  }
3916
4042
 
3917
- return i;
3918
- }
3919
-
3920
- function isBlank(str) {
3921
- return leadingWhitespace(str) === str.length;
4043
+ return (_commonIndent = commonIndent) !== null && _commonIndent !== void 0 ? _commonIndent : 0;
3922
4044
  }
3923
4045
 
3924
4046
  /**
@@ -4017,161 +4139,257 @@ ${queryParams
4017
4139
  var source = lexer.source;
4018
4140
  var body = source.body;
4019
4141
  var bodyLength = body.length;
4020
- var pos = positionAfterWhitespace(body, prev.end, lexer);
4021
- var line = lexer.line;
4022
- var col = 1 + pos - lexer.lineStart;
4142
+ var pos = prev.end;
4023
4143
 
4024
- if (pos >= bodyLength) {
4025
- return new Token(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);
4026
- }
4144
+ while (pos < bodyLength) {
4145
+ var code = body.charCodeAt(pos);
4146
+ var _line = lexer.line;
4027
4147
 
4028
- var code = body.charCodeAt(pos); // SourceCharacter
4148
+ var _col = 1 + pos - lexer.lineStart; // SourceCharacter
4029
4149
 
4030
- switch (code) {
4031
- // !
4032
- case 33:
4033
- return new Token(TokenKind.BANG, pos, pos + 1, line, col, prev);
4034
- // #
4035
4150
 
4036
- case 35:
4037
- return readComment(source, pos, line, col, prev);
4038
- // $
4151
+ switch (code) {
4152
+ case 0xfeff: // <BOM>
4039
4153
 
4040
- case 36:
4041
- return new Token(TokenKind.DOLLAR, pos, pos + 1, line, col, prev);
4042
- // &
4154
+ case 9: // \t
4043
4155
 
4044
- case 38:
4045
- return new Token(TokenKind.AMP, pos, pos + 1, line, col, prev);
4046
- // (
4156
+ case 32: // <space>
4047
4157
 
4048
- case 40:
4049
- return new Token(TokenKind.PAREN_L, pos, pos + 1, line, col, prev);
4050
- // )
4158
+ case 44:
4159
+ // ,
4160
+ ++pos;
4161
+ continue;
4051
4162
 
4052
- case 41:
4053
- return new Token(TokenKind.PAREN_R, pos, pos + 1, line, col, prev);
4054
- // .
4163
+ case 10:
4164
+ // \n
4165
+ ++pos;
4166
+ ++lexer.line;
4167
+ lexer.lineStart = pos;
4168
+ continue;
4055
4169
 
4056
- case 46:
4057
- if (body.charCodeAt(pos + 1) === 46 && body.charCodeAt(pos + 2) === 46) {
4058
- return new Token(TokenKind.SPREAD, pos, pos + 3, line, col, prev);
4059
- }
4170
+ case 13:
4171
+ // \r
4172
+ if (body.charCodeAt(pos + 1) === 10) {
4173
+ pos += 2;
4174
+ } else {
4175
+ ++pos;
4176
+ }
4060
4177
 
4061
- break;
4062
- // :
4063
-
4064
- case 58:
4065
- return new Token(TokenKind.COLON, pos, pos + 1, line, col, prev);
4066
- // =
4067
-
4068
- case 61:
4069
- return new Token(TokenKind.EQUALS, pos, pos + 1, line, col, prev);
4070
- // @
4071
-
4072
- case 64:
4073
- return new Token(TokenKind.AT, pos, pos + 1, line, col, prev);
4074
- // [
4075
-
4076
- case 91:
4077
- return new Token(TokenKind.BRACKET_L, pos, pos + 1, line, col, prev);
4078
- // ]
4079
-
4080
- case 93:
4081
- return new Token(TokenKind.BRACKET_R, pos, pos + 1, line, col, prev);
4082
- // {
4083
-
4084
- case 123:
4085
- return new Token(TokenKind.BRACE_L, pos, pos + 1, line, col, prev);
4086
- // |
4087
-
4088
- case 124:
4089
- return new Token(TokenKind.PIPE, pos, pos + 1, line, col, prev);
4090
- // }
4091
-
4092
- case 125:
4093
- return new Token(TokenKind.BRACE_R, pos, pos + 1, line, col, prev);
4094
- // A-Z _ a-z
4095
-
4096
- case 65:
4097
- case 66:
4098
- case 67:
4099
- case 68:
4100
- case 69:
4101
- case 70:
4102
- case 71:
4103
- case 72:
4104
- case 73:
4105
- case 74:
4106
- case 75:
4107
- case 76:
4108
- case 77:
4109
- case 78:
4110
- case 79:
4111
- case 80:
4112
- case 81:
4113
- case 82:
4114
- case 83:
4115
- case 84:
4116
- case 85:
4117
- case 86:
4118
- case 87:
4119
- case 88:
4120
- case 89:
4121
- case 90:
4122
- case 95:
4123
- case 97:
4124
- case 98:
4125
- case 99:
4126
- case 100:
4127
- case 101:
4128
- case 102:
4129
- case 103:
4130
- case 104:
4131
- case 105:
4132
- case 106:
4133
- case 107:
4134
- case 108:
4135
- case 109:
4136
- case 110:
4137
- case 111:
4138
- case 112:
4139
- case 113:
4140
- case 114:
4141
- case 115:
4142
- case 116:
4143
- case 117:
4144
- case 118:
4145
- case 119:
4146
- case 120:
4147
- case 121:
4148
- case 122:
4149
- return readName(source, pos, line, col, prev);
4150
- // - 0-9
4151
-
4152
- case 45:
4153
- case 48:
4154
- case 49:
4155
- case 50:
4156
- case 51:
4157
- case 52:
4158
- case 53:
4159
- case 54:
4160
- case 55:
4161
- case 56:
4162
- case 57:
4163
- return readNumber(source, pos, code, line, col, prev);
4164
- // "
4165
-
4166
- case 34:
4167
- if (body.charCodeAt(pos + 1) === 34 && body.charCodeAt(pos + 2) === 34) {
4168
- return readBlockString(source, pos, line, col, prev, lexer);
4169
- }
4178
+ ++lexer.line;
4179
+ lexer.lineStart = pos;
4180
+ continue;
4181
+
4182
+ case 33:
4183
+ // !
4184
+ return new Token(TokenKind.BANG, pos, pos + 1, _line, _col, prev);
4185
+
4186
+ case 35:
4187
+ // #
4188
+ return readComment(source, pos, _line, _col, prev);
4189
+
4190
+ case 36:
4191
+ // $
4192
+ return new Token(TokenKind.DOLLAR, pos, pos + 1, _line, _col, prev);
4193
+
4194
+ case 38:
4195
+ // &
4196
+ return new Token(TokenKind.AMP, pos, pos + 1, _line, _col, prev);
4197
+
4198
+ case 40:
4199
+ // (
4200
+ return new Token(TokenKind.PAREN_L, pos, pos + 1, _line, _col, prev);
4201
+
4202
+ case 41:
4203
+ // )
4204
+ return new Token(TokenKind.PAREN_R, pos, pos + 1, _line, _col, prev);
4205
+
4206
+ case 46:
4207
+ // .
4208
+ if (body.charCodeAt(pos + 1) === 46 && body.charCodeAt(pos + 2) === 46) {
4209
+ return new Token(TokenKind.SPREAD, pos, pos + 3, _line, _col, prev);
4210
+ }
4211
+
4212
+ break;
4213
+
4214
+ case 58:
4215
+ // :
4216
+ return new Token(TokenKind.COLON, pos, pos + 1, _line, _col, prev);
4217
+
4218
+ case 61:
4219
+ // =
4220
+ return new Token(TokenKind.EQUALS, pos, pos + 1, _line, _col, prev);
4221
+
4222
+ case 64:
4223
+ // @
4224
+ return new Token(TokenKind.AT, pos, pos + 1, _line, _col, prev);
4225
+
4226
+ case 91:
4227
+ // [
4228
+ return new Token(TokenKind.BRACKET_L, pos, pos + 1, _line, _col, prev);
4229
+
4230
+ case 93:
4231
+ // ]
4232
+ return new Token(TokenKind.BRACKET_R, pos, pos + 1, _line, _col, prev);
4233
+
4234
+ case 123:
4235
+ // {
4236
+ return new Token(TokenKind.BRACE_L, pos, pos + 1, _line, _col, prev);
4237
+
4238
+ case 124:
4239
+ // |
4240
+ return new Token(TokenKind.PIPE, pos, pos + 1, _line, _col, prev);
4241
+
4242
+ case 125:
4243
+ // }
4244
+ return new Token(TokenKind.BRACE_R, pos, pos + 1, _line, _col, prev);
4245
+
4246
+ case 34:
4247
+ // "
4248
+ if (body.charCodeAt(pos + 1) === 34 && body.charCodeAt(pos + 2) === 34) {
4249
+ return readBlockString(source, pos, _line, _col, prev, lexer);
4250
+ }
4251
+
4252
+ return readString(source, pos, _line, _col, prev);
4253
+
4254
+ case 45: // -
4255
+
4256
+ case 48: // 0
4257
+
4258
+ case 49: // 1
4259
+
4260
+ case 50: // 2
4261
+
4262
+ case 51: // 3
4263
+
4264
+ case 52: // 4
4265
+
4266
+ case 53: // 5
4267
+
4268
+ case 54: // 6
4269
+
4270
+ case 55: // 7
4271
+
4272
+ case 56: // 8
4273
+
4274
+ case 57:
4275
+ // 9
4276
+ return readNumber(source, pos, code, _line, _col, prev);
4277
+
4278
+ case 65: // A
4279
+
4280
+ case 66: // B
4281
+
4282
+ case 67: // C
4283
+
4284
+ case 68: // D
4285
+
4286
+ case 69: // E
4287
+
4288
+ case 70: // F
4289
+
4290
+ case 71: // G
4291
+
4292
+ case 72: // H
4293
+
4294
+ case 73: // I
4295
+
4296
+ case 74: // J
4297
+
4298
+ case 75: // K
4299
+
4300
+ case 76: // L
4301
+
4302
+ case 77: // M
4303
+
4304
+ case 78: // N
4305
+
4306
+ case 79: // O
4307
+
4308
+ case 80: // P
4309
+
4310
+ case 81: // Q
4311
+
4312
+ case 82: // R
4313
+
4314
+ case 83: // S
4315
+
4316
+ case 84: // T
4317
+
4318
+ case 85: // U
4319
+
4320
+ case 86: // V
4321
+
4322
+ case 87: // W
4323
+
4324
+ case 88: // X
4325
+
4326
+ case 89: // Y
4327
+
4328
+ case 90: // Z
4329
+
4330
+ case 95: // _
4331
+
4332
+ case 97: // a
4170
4333
 
4171
- return readString(source, pos, line, col, prev);
4334
+ case 98: // b
4335
+
4336
+ case 99: // c
4337
+
4338
+ case 100: // d
4339
+
4340
+ case 101: // e
4341
+
4342
+ case 102: // f
4343
+
4344
+ case 103: // g
4345
+
4346
+ case 104: // h
4347
+
4348
+ case 105: // i
4349
+
4350
+ case 106: // j
4351
+
4352
+ case 107: // k
4353
+
4354
+ case 108: // l
4355
+
4356
+ case 109: // m
4357
+
4358
+ case 110: // n
4359
+
4360
+ case 111: // o
4361
+
4362
+ case 112: // p
4363
+
4364
+ case 113: // q
4365
+
4366
+ case 114: // r
4367
+
4368
+ case 115: // s
4369
+
4370
+ case 116: // t
4371
+
4372
+ case 117: // u
4373
+
4374
+ case 118: // v
4375
+
4376
+ case 119: // w
4377
+
4378
+ case 120: // x
4379
+
4380
+ case 121: // y
4381
+
4382
+ case 122:
4383
+ // z
4384
+ return readName(source, pos, _line, _col, prev);
4385
+ }
4386
+
4387
+ throw syntaxError(source, pos, unexpectedCharacterMessage(code));
4172
4388
  }
4173
4389
 
4174
- throw syntaxError(source, pos, unexpectedCharacterMessage(code));
4390
+ var line = lexer.line;
4391
+ var col = 1 + pos - lexer.lineStart;
4392
+ return new Token(TokenKind.EOF, bodyLength, bodyLength, line, col, prev);
4175
4393
  }
4176
4394
  /**
4177
4395
  * Report a message that an unexpected character was encountered.
@@ -4190,43 +4408,6 @@ ${queryParams
4190
4408
 
4191
4409
  return "Cannot parse the unexpected character ".concat(printCharCode(code), ".");
4192
4410
  }
4193
- /**
4194
- * Reads from body starting at startPosition until it finds a non-whitespace
4195
- * character, then returns the position of that character for lexing.
4196
- */
4197
-
4198
-
4199
- function positionAfterWhitespace(body, startPosition, lexer) {
4200
- var bodyLength = body.length;
4201
- var position = startPosition;
4202
-
4203
- while (position < bodyLength) {
4204
- var code = body.charCodeAt(position); // tab | space | comma | BOM
4205
-
4206
- if (code === 9 || code === 32 || code === 44 || code === 0xfeff) {
4207
- ++position;
4208
- } else if (code === 10) {
4209
- // new line
4210
- ++position;
4211
- ++lexer.line;
4212
- lexer.lineStart = position;
4213
- } else if (code === 13) {
4214
- // carriage return
4215
- if (body.charCodeAt(position + 1) === 10) {
4216
- position += 2;
4217
- } else {
4218
- ++position;
4219
- }
4220
-
4221
- ++lexer.line;
4222
- lexer.lineStart = position;
4223
- } else {
4224
- break;
4225
- }
4226
- }
4227
-
4228
- return position;
4229
- }
4230
4411
  /**
4231
4412
  * Reads a comment token from the source file.
4232
4413
  *
@@ -4547,11 +4728,21 @@ ${queryParams
4547
4728
  var parser = new Parser(source, options);
4548
4729
  return parser.parseDocument();
4549
4730
  }
4731
+ /**
4732
+ * This class is exported only to assist people in implementing their own parsers
4733
+ * without duplicating too much code and should be used only as last resort for cases
4734
+ * such as experimental syntax or if certain features could not be contributed upstream.
4735
+ *
4736
+ * It is still part of the internal API and is versioned, so any changes to it are never
4737
+ * considered breaking changes. If you still need to support multiple versions of the
4738
+ * library, please use the `versionInfo` variable for version detection.
4739
+ *
4740
+ * @internal
4741
+ */
4550
4742
 
4551
4743
  var Parser = /*#__PURE__*/function () {
4552
4744
  function Parser(source, options) {
4553
- var sourceObj = typeof source === 'string' ? new Source(source) : source;
4554
- sourceObj instanceof Source || devAssert(0, "Must provide Source. Received: ".concat(inspect(sourceObj), "."));
4745
+ var sourceObj = isSource(source) ? source : new Source(source);
4555
4746
  this._lexer = new Lexer(sourceObj);
4556
4747
  this._options = options;
4557
4748
  }
@@ -5296,21 +5487,25 @@ ${queryParams
5296
5487
  ;
5297
5488
 
5298
5489
  _proto.parseImplementsInterfaces = function parseImplementsInterfaces() {
5299
- var types = [];
5490
+ var _this$_options2;
5491
+
5492
+ if (!this.expectOptionalKeyword('implements')) {
5493
+ return [];
5494
+ }
5495
+
5496
+ if (((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.allowLegacySDLImplementsInterfaces) === true) {
5497
+ var types = []; // Optional leading ampersand
5300
5498
 
5301
- if (this.expectOptionalKeyword('implements')) {
5302
- // Optional leading ampersand
5303
5499
  this.expectOptionalToken(TokenKind.AMP);
5304
5500
 
5305
5501
  do {
5306
- var _this$_options2;
5307
-
5308
5502
  types.push(this.parseNamedType());
5309
- } while (this.expectOptionalToken(TokenKind.AMP) || // Legacy support for the SDL?
5310
- ((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.allowLegacySDLImplementsInterfaces) === true && this.peek(TokenKind.NAME));
5503
+ } while (this.expectOptionalToken(TokenKind.AMP) || this.peek(TokenKind.NAME));
5504
+
5505
+ return types;
5311
5506
  }
5312
5507
 
5313
- return types;
5508
+ return this.delimitedMany(TokenKind.AMP, this.parseNamedType);
5314
5509
  }
5315
5510
  /**
5316
5511
  * FieldsDefinition : { FieldDefinition+ }
@@ -5446,18 +5641,7 @@ ${queryParams
5446
5641
  ;
5447
5642
 
5448
5643
  _proto.parseUnionMemberTypes = function parseUnionMemberTypes() {
5449
- var types = [];
5450
-
5451
- if (this.expectOptionalToken(TokenKind.EQUALS)) {
5452
- // Optional leading pipe
5453
- this.expectOptionalToken(TokenKind.PIPE);
5454
-
5455
- do {
5456
- types.push(this.parseNamedType());
5457
- } while (this.expectOptionalToken(TokenKind.PIPE));
5458
- }
5459
-
5460
- return types;
5644
+ return this.expectOptionalToken(TokenKind.EQUALS) ? this.delimitedMany(TokenKind.PIPE, this.parseNamedType) : [];
5461
5645
  }
5462
5646
  /**
5463
5647
  * EnumTypeDefinition :
@@ -5808,15 +5992,7 @@ ${queryParams
5808
5992
  ;
5809
5993
 
5810
5994
  _proto.parseDirectiveLocations = function parseDirectiveLocations() {
5811
- // Optional leading pipe
5812
- this.expectOptionalToken(TokenKind.PIPE);
5813
- var locations = [];
5814
-
5815
- do {
5816
- locations.push(this.parseDirectiveLocation());
5817
- } while (this.expectOptionalToken(TokenKind.PIPE));
5818
-
5819
- return locations;
5995
+ return this.delimitedMany(TokenKind.PIPE, this.parseDirectiveLocation);
5820
5996
  }
5821
5997
  /*
5822
5998
  * DirectiveLocation :
@@ -5859,8 +6035,7 @@ ${queryParams
5859
6035
  } // Core parsing utility functions
5860
6036
 
5861
6037
  /**
5862
- * Returns a location object, used to identify the place in
5863
- * the source that created a given parsed object.
6038
+ * Returns a location object, used to identify the place in the source that created a given parsed object.
5864
6039
  */
5865
6040
  ;
5866
6041
 
@@ -5880,8 +6055,8 @@ ${queryParams
5880
6055
  return this._lexer.token.kind === kind;
5881
6056
  }
5882
6057
  /**
5883
- * If the next token is of the given kind, return that token after advancing
5884
- * the lexer. Otherwise, do not change the parser state and throw an error.
6058
+ * If the next token is of the given kind, return that token after advancing the lexer.
6059
+ * Otherwise, do not change the parser state and throw an error.
5885
6060
  */
5886
6061
  ;
5887
6062
 
@@ -5897,8 +6072,8 @@ ${queryParams
5897
6072
  throw syntaxError(this._lexer.source, token.start, "Expected ".concat(getTokenKindDesc(kind), ", found ").concat(getTokenDesc(token), "."));
5898
6073
  }
5899
6074
  /**
5900
- * If the next token is of the given kind, return that token after advancing
5901
- * the lexer. Otherwise, do not change the parser state and return undefined.
6075
+ * If the next token is of the given kind, return that token after advancing the lexer.
6076
+ * Otherwise, do not change the parser state and return undefined.
5902
6077
  */
5903
6078
  ;
5904
6079
 
@@ -5929,8 +6104,8 @@ ${queryParams
5929
6104
  }
5930
6105
  }
5931
6106
  /**
5932
- * If the next token is a given keyword, return "true" after advancing
5933
- * the lexer. Otherwise, do not change the parser state and return "false".
6107
+ * If the next token is a given keyword, return "true" after advancing the lexer.
6108
+ * Otherwise, do not change the parser state and return "false".
5934
6109
  */
5935
6110
  ;
5936
6111
 
@@ -5946,8 +6121,7 @@ ${queryParams
5946
6121
  return false;
5947
6122
  }
5948
6123
  /**
5949
- * Helper function for creating an error when an unexpected lexed token
5950
- * is encountered.
6124
+ * Helper function for creating an error when an unexpected lexed token is encountered.
5951
6125
  */
5952
6126
  ;
5953
6127
 
@@ -5956,10 +6130,9 @@ ${queryParams
5956
6130
  return syntaxError(this._lexer.source, token.start, "Unexpected ".concat(getTokenDesc(token), "."));
5957
6131
  }
5958
6132
  /**
5959
- * Returns a possibly empty list of parse nodes, determined by
5960
- * the parseFn. This list begins with a lex token of openKind
5961
- * and ends with a lex token of closeKind. Advances the parser
5962
- * to the next lex token after the closing token.
6133
+ * Returns a possibly empty list of parse nodes, determined by the parseFn.
6134
+ * This list begins with a lex token of openKind and ends with a lex token of closeKind.
6135
+ * Advances the parser to the next lex token after the closing token.
5963
6136
  */
5964
6137
  ;
5965
6138
 
@@ -5975,10 +6148,9 @@ ${queryParams
5975
6148
  }
5976
6149
  /**
5977
6150
  * Returns a list of parse nodes, determined by the parseFn.
5978
- * It can be empty only if open token is missing otherwise it will always
5979
- * return non-empty list that begins with a lex token of openKind and ends
5980
- * with a lex token of closeKind. Advances the parser to the next lex token
5981
- * after the closing token.
6151
+ * It can be empty only if open token is missing otherwise it will always return non-empty list
6152
+ * that begins with a lex token of openKind and ends with a lex token of closeKind.
6153
+ * Advances the parser to the next lex token after the closing token.
5982
6154
  */
5983
6155
  ;
5984
6156
 
@@ -5996,10 +6168,9 @@ ${queryParams
5996
6168
  return [];
5997
6169
  }
5998
6170
  /**
5999
- * Returns a non-empty list of parse nodes, determined by
6000
- * the parseFn. This list begins with a lex token of openKind
6001
- * and ends with a lex token of closeKind. Advances the parser
6002
- * to the next lex token after the closing token.
6171
+ * Returns a non-empty list of parse nodes, determined by the parseFn.
6172
+ * This list begins with a lex token of openKind and ends with a lex token of closeKind.
6173
+ * Advances the parser to the next lex token after the closing token.
6003
6174
  */
6004
6175
  ;
6005
6176
 
@@ -6011,22 +6182,38 @@ ${queryParams
6011
6182
  nodes.push(parseFn.call(this));
6012
6183
  } while (!this.expectOptionalToken(closeKind));
6013
6184
 
6185
+ return nodes;
6186
+ }
6187
+ /**
6188
+ * Returns a non-empty list of parse nodes, determined by the parseFn.
6189
+ * This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind.
6190
+ * Advances the parser to the next lex token after last item in the list.
6191
+ */
6192
+ ;
6193
+
6194
+ _proto.delimitedMany = function delimitedMany(delimiterKind, parseFn) {
6195
+ this.expectOptionalToken(delimiterKind);
6196
+ var nodes = [];
6197
+
6198
+ do {
6199
+ nodes.push(parseFn.call(this));
6200
+ } while (this.expectOptionalToken(delimiterKind));
6201
+
6014
6202
  return nodes;
6015
6203
  };
6016
6204
 
6017
6205
  return Parser;
6018
6206
  }();
6019
6207
  /**
6020
- * A helper function to describe a token as a string for debugging
6208
+ * A helper function to describe a token as a string for debugging.
6021
6209
  */
6022
6210
 
6023
-
6024
6211
  function getTokenDesc(token) {
6025
6212
  var value = token.value;
6026
6213
  return getTokenKindDesc(token.kind) + (value != null ? " \"".concat(value, "\"") : '');
6027
6214
  }
6028
6215
  /**
6029
- * A helper function to describe a token kind as a string for debugging
6216
+ * A helper function to describe a token kind as a string for debugging.
6030
6217
  */
6031
6218
 
6032
6219
 
@@ -6055,6 +6242,7 @@ ${queryParams
6055
6242
  };
6056
6243
  }
6057
6244
  function graphQLRequestHandler(expectedOperationType, expectedOperationName, mask, resolver) {
6245
+ const callFrame = getCallFrame();
6058
6246
  return {
6059
6247
  resolver,
6060
6248
  parse(req) {
@@ -6126,6 +6314,17 @@ ${queryParams
6126
6314
  console.log('Response:', loggedResponse);
6127
6315
  console.groupEnd();
6128
6316
  },
6317
+ getMetaInfo() {
6318
+ const header = expectedOperationType === 'all'
6319
+ ? `[graphql] ${expectedOperationType} (origin: ${mask.toString()})`
6320
+ : `[graphql] ${expectedOperationType} ${expectedOperationName} (origin: ${mask.toString()})`;
6321
+ return {
6322
+ type: 'graphql',
6323
+ header,
6324
+ mask,
6325
+ callFrame,
6326
+ };
6327
+ },
6129
6328
  };
6130
6329
  }
6131
6330
  const createGraphQLScopedHandler = (expectedOperationType, mask) => {
@@ -6153,7 +6352,9 @@ ${queryParams
6153
6352
  const graphql = Object.assign(Object.assign({}, graphqlStandardHandlers), { link: createGraphQLLink });
6154
6353
 
6155
6354
  exports.context = index;
6355
+ exports.createResponseComposition = createResponseComposition;
6156
6356
  exports.defaultContext = defaultContext;
6357
+ exports.defaultResponse = defaultResponse;
6157
6358
  exports.graphql = graphql;
6158
6359
  exports.graphqlContext = graphqlContext;
6159
6360
  exports.matchRequestUrl = matchRequestUrl;