msw 2.15.0 → 3.0.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/README.md +8 -0
- package/cli/init.js +12 -9
- package/cli/invariant.js +2 -2
- package/lib/_chunks/attach-sibling-handlers.js +360 -0
- package/lib/_chunks/attach-sibling-handlers.js.map +1 -0
- package/lib/_chunks/colors.js +18 -0
- package/lib/_chunks/colors.js.map +1 -0
- package/lib/_chunks/cookie-store.js +348 -0
- package/lib/_chunks/cookie-store.js.map +1 -0
- package/lib/_chunks/execute-handlers.js +29 -0
- package/lib/_chunks/execute-handlers.js.map +1 -0
- package/lib/_chunks/handlers-controller.d.ts +262 -0
- package/lib/_chunks/has-ref-counted.js +9 -0
- package/lib/_chunks/has-ref-counted.js.map +1 -0
- package/lib/_chunks/http-handler.d.ts +72 -0
- package/lib/_chunks/http-handler.js +182 -0
- package/lib/_chunks/http-handler.js.map +1 -0
- package/lib/_chunks/http-response.js +137 -0
- package/lib/_chunks/http-response.js.map +1 -0
- package/lib/{core → _chunks}/http.d.ts +15 -18
- package/lib/_chunks/http.js +30 -0
- package/lib/_chunks/http.js.map +1 -0
- package/lib/_chunks/interceptor-source.d.ts +163 -0
- package/lib/_chunks/interceptor-source.js +756 -0
- package/lib/_chunks/interceptor-source.js.map +1 -0
- package/lib/_chunks/is-object.js +11 -0
- package/lib/_chunks/is-object.js.map +1 -0
- package/lib/_chunks/match-request-url.d.ts +14 -0
- package/lib/_chunks/request-handler.d.ts +295 -0
- package/lib/_chunks/request-handler.js +369 -0
- package/lib/_chunks/request-handler.js.map +1 -0
- package/lib/_chunks/shared-options.d.ts +20 -0
- package/lib/_chunks/sse.d.ts +95 -0
- package/lib/_chunks/sse.js +599 -0
- package/lib/_chunks/sse.js.map +1 -0
- package/lib/_chunks/symbols.js +22 -0
- package/lib/_chunks/symbols.js.map +1 -0
- package/lib/_chunks/websocket-upgrade.js +46 -0
- package/lib/_chunks/websocket-upgrade.js.map +1 -0
- package/lib/_chunks/ws.d.ts +133 -0
- package/lib/_chunks/ws.js +293 -0
- package/lib/_chunks/ws.js.map +1 -0
- package/lib/browser/index.d.ts +225 -96
- package/lib/browser/index.js +555 -3694
- package/lib/browser/index.js.map +1 -1
- package/lib/core/experimental/index.d.ts +3 -17
- package/lib/core/experimental/index.js +2 -38
- package/lib/core/index.d.ts +15 -27
- package/lib/core/index.js +15 -64
- package/lib/graphql/index.d.ts +550 -0
- package/lib/graphql/index.js +1244 -0
- package/lib/graphql/index.js.map +1 -0
- package/lib/http/index.d.ts +4 -0
- package/lib/http/index.js +4 -0
- package/lib/iife/index.js +35857 -28422
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +185 -86
- package/lib/node/index.d.ts +79 -104
- package/lib/node/index.js +103 -201
- package/lib/node/index.js.map +1 -1
- package/lib/sse/index.d.ts +2 -0
- package/lib/sse/index.js +2 -0
- package/lib/{core → utils}/bypass.d.ts +5 -4
- package/lib/utils/bypass.js +41 -0
- package/lib/utils/bypass.js.map +1 -0
- package/lib/utils/delay.d.ts +15 -0
- package/lib/utils/delay.js +45 -0
- package/lib/utils/delay.js.map +1 -0
- package/lib/utils/get-clean-url-string.d.ts +9 -0
- package/lib/utils/get-clean-url-string.js +15 -0
- package/lib/utils/get-clean-url-string.js.map +1 -0
- package/lib/utils/get-response.d.ts +13 -0
- package/lib/utils/get-response.js +23 -0
- package/lib/utils/get-response.js.map +1 -0
- package/lib/utils/is-common-asset-request.d.ts +22 -0
- package/lib/utils/is-common-asset-request.js +31 -0
- package/lib/utils/is-common-asset-request.js.map +1 -0
- package/lib/utils/passthrough.d.ts +31 -0
- package/lib/utils/passthrough.js +41 -0
- package/lib/utils/passthrough.js.map +1 -0
- package/lib/vite/index.d.ts +44 -0
- package/lib/vite/index.js +90 -0
- package/lib/vite/index.js.map +1 -0
- package/lib/vite/runtime.d.ts +6 -0
- package/lib/vite/runtime.js +77 -0
- package/lib/vite/runtime.js.map +1 -0
- package/lib/ws/index.d.ts +4 -0
- package/lib/ws/index.js +4 -0
- package/package.json +93 -201
- package/src/browser/default-network-options.ts +31 -0
- package/src/browser/glossary.ts +11 -23
- package/src/browser/index.ts +5 -1
- package/src/browser/setup-worker.ts +15 -68
- package/src/browser/sources/fallback-http-source.ts +1 -1
- package/src/browser/sources/service-worker-source.ts +76 -69
- package/src/browser/tsconfig.browser.json +4 -2
- package/src/browser/utils/{deserializeRequest.ts → deserialize-request.ts} +3 -4
- package/src/browser/utils/{getAbsoluteWorkerUrl.test.ts → get-absolute-worker-url.test.ts} +3 -3
- package/src/browser/utils/get-worker-instance.ts +2 -2
- package/src/browser/utils/should-invalidate-worker.test.ts +11 -11
- package/src/browser/utils/should-invalidate-worker.ts +1 -1
- package/src/browser/utils/validate-worker-scope.ts +1 -1
- package/src/browser/utils/{workerChannel.ts → worker-channel.ts} +42 -20
- package/src/core/experimental/define-network.test.ts +43 -8
- package/src/core/experimental/define-network.ts +32 -13
- package/src/core/experimental/frames/http-frame.test.ts +15 -13
- package/src/core/experimental/frames/http-frame.ts +10 -9
- package/src/core/experimental/frames/websocket-frame.test.ts +129 -15
- package/src/core/experimental/frames/websocket-frame.ts +71 -20
- package/src/core/experimental/handlers-controller.test.ts +141 -34
- package/src/core/experimental/handlers-controller.ts +107 -30
- package/src/core/experimental/index.ts +1 -0
- package/src/core/experimental/on-unhandled-frame.test.ts +19 -19
- package/src/core/experimental/on-unhandled-frame.ts +7 -12
- package/src/core/experimental/request-utils.test.ts +4 -29
- package/src/core/experimental/request-utils.ts +0 -14
- package/src/core/experimental/sources/interceptor-source.ts +44 -29
- package/src/core/experimental/sources/network-source.test.ts +3 -3
- package/src/core/experimental/sources/network-source.ts +3 -3
- package/src/core/handlers/handler.ts +42 -0
- package/src/core/handlers/{RequestHandler.ts → request-handler.ts} +26 -41
- package/src/core/index.ts +35 -58
- package/src/core/shared-options.ts +21 -0
- package/src/core/type-utils.ts +18 -0
- package/src/core/utils/{cookieStore.ts → cookie-store.ts} +14 -9
- package/src/core/utils/{executeHandlers.ts → execute-handlers.ts} +2 -2
- package/src/core/utils/http-status-messages.ts +69 -0
- package/src/core/utils/internal/{attachSiblingHandlers.ts → attach-sibling-handlers.ts} +20 -0
- package/src/core/utils/internal/{devUtils.test.ts → dev-utils.test.ts} +3 -3
- package/src/core/utils/internal/{Disposable.ts → disposable.ts} +1 -1
- package/src/core/utils/internal/{getCallFrame.test.ts → get-call-frame.test.ts} +1 -1
- package/src/core/utils/internal/{getCallFrame.ts → get-call-frame.ts} +1 -1
- package/src/core/utils/internal/{hasRefCounted.test.ts → has-ref-counted.test.ts} +4 -4
- package/src/core/utils/internal/{hasRefCounted.ts → has-ref-counted.ts} +1 -1
- package/src/core/utils/internal/{isIterable.test.ts → is-iterable.test.ts} +1 -1
- package/src/core/utils/internal/is-iterable.ts +16 -0
- package/src/core/utils/internal/{isObject.test.ts → is-object.test.ts} +1 -1
- package/src/core/utils/internal/{isStringEqual.test.ts → is-string-equal.test.ts} +7 -7
- package/src/core/utils/internal/{jsonParse.test.ts → json-parse.test.ts} +1 -1
- package/src/core/utils/internal/observe-response-body-stream.test.ts +7 -7
- package/src/core/utils/internal/observe-response-body-stream.ts +3 -4
- package/src/core/utils/internal/{parseMultipartData.test.ts → parse-multipart-data.test.ts} +1 -1
- package/src/core/utils/internal/{parseMultipartData.ts → parse-multipart-data.ts} +1 -1
- package/src/core/utils/internal/{toReadonlyArray.test.ts → to-readonly-array.test.ts} +4 -4
- package/src/core/utils/logging/colors.ts +13 -0
- package/src/core/utils/logging/{getStatusCodeColor.test.ts → get-status-code-color.test.ts} +1 -1
- package/src/core/utils/logging/{getTimestamp.test.ts → get-timestamp.test.ts} +1 -1
- package/src/core/utils/logging/{serializeRequest.test.ts → serialize-request.test.ts} +1 -1
- package/src/core/utils/logging/{serializeResponse.test.ts → serialize-response.test.ts} +8 -10
- package/src/core/utils/logging/{serializeResponse.ts → serialize-response.ts} +2 -4
- package/src/core/utils/matching/match-request-url.test.ts +90 -0
- package/src/core/utils/matching/match-request-url.ts +45 -0
- package/src/core/utils/matching/{normalizePath.node.test.ts → normalize-path.node.test.ts} +2 -4
- package/src/core/utils/matching/{normalizePath.test.ts → normalize-path.test.ts} +2 -4
- package/src/core/utils/matching/{normalizePath.ts → normalize-path.ts} +8 -5
- package/src/core/utils/request/{getAllAcceptedMimeTypes.test.ts → get-all-accepted-mime-types.test.ts} +14 -14
- package/src/core/utils/request/get-request-cookies.ts +76 -0
- package/src/core/utils/request/store-response-cookies.ts +15 -0
- package/src/core/utils/request/{toPublicUrl.node.test.ts → to-public-url.node.test.ts} +1 -1
- package/src/core/utils/request/{toPublicUrl.test.ts → to-public-url.test.ts} +2 -2
- package/src/core/utils/{HttpResponse/decorators.ts → response-decorators.ts} +6 -8
- package/src/core/utils/url/{getAbsoluteUrl.node.test.ts → get-absolute-url.node.test.ts} +5 -7
- package/src/core/utils/url/{getAbsoluteUrl.test.ts → get-absolute-url.test.ts} +7 -7
- package/src/core/utils/url/{getAbsoluteUrl.ts → get-absolute-url.ts} +1 -1
- package/src/core/utils/url/is-absolute-url.test.ts +30 -0
- package/src/{core/handlers/GraphQLHandler.test.ts → graphql/graphql-handler.test.ts} +37 -36
- package/src/{core/handlers/GraphQLHandler.ts → graphql/graphql-handler.ts} +54 -41
- package/src/graphql/graphql-subscription-event.ts +39 -0
- package/src/graphql/graphql-subscription.test.ts +208 -0
- package/src/graphql/graphql-subscription.ts +1487 -0
- package/src/graphql/graphql.test.ts +14 -0
- package/src/graphql/graphql.ts +179 -0
- package/src/graphql/index.ts +34 -0
- package/src/{core/utils/internal/parseGraphQLRequest.test.ts → graphql/parse-graphql-request.test.ts} +47 -6
- package/src/{core/utils/internal/parseGraphQLRequest.ts → graphql/parse-graphql-request.ts} +59 -32
- package/src/{core/handlers/HttpHandler.test.ts → http/http-handler.test.ts} +22 -22
- package/src/{core/handlers/HttpHandler.ts → http/http-handler.ts} +16 -18
- package/src/{core/HttpResponse.test.ts → http/http-response.test.ts} +25 -27
- package/src/{core/HttpResponse.ts → http/http-response.ts} +15 -17
- package/src/{core → http}/http.ts +7 -7
- package/src/http/index.test.ts +19 -0
- package/src/http/index.ts +22 -0
- package/src/http/symbols.ts +19 -0
- package/src/iife/index.ts +2 -0
- package/src/mockServiceWorker.js +183 -84
- package/src/node/async-handlers-controller.test.ts +4 -4
- package/src/node/glossary.ts +8 -4
- package/src/node/index.ts +1 -6
- package/src/node/setup-server-common.ts +16 -73
- package/src/node/setup-server.ts +9 -40
- package/src/sse/index.test.ts +14 -0
- package/src/sse/index.ts +7 -0
- package/src/{core → sse}/sse.ts +25 -21
- package/src/tsconfig.core.build.json +5 -1
- package/src/tsconfig.core.json +8 -1
- package/src/tsconfig.node.json +1 -1
- package/src/tsconfig.src.json +1 -1
- package/src/{core → utils}/bypass.test.ts +22 -5
- package/src/{core → utils}/bypass.ts +11 -0
- package/src/{core → utils}/delay.ts +5 -5
- package/src/utils/get-clean-url-string.test.ts +24 -0
- package/src/utils/get-clean-url-string.ts +16 -0
- package/src/{core/getResponse.test.ts → utils/get-response.test.ts} +9 -9
- package/src/{core/getResponse.ts → utils/get-response.ts} +2 -2
- package/src/{core/isCommonAssetRequest.ts → utils/is-common-asset-request.ts} +4 -3
- package/src/utils/passthrough.test.ts +41 -0
- package/src/utils/passthrough.ts +46 -0
- package/src/vite/client.d.ts +16 -0
- package/src/vite/index.ts +4 -0
- package/src/vite/options.d.ts +5 -0
- package/src/vite/plugin.test.ts +918 -0
- package/src/vite/plugin.ts +133 -0
- package/src/vite/runtime.ts +117 -0
- package/src/vite/tsconfig.build.json +7 -0
- package/src/ws/index.ts +23 -0
- package/src/{core/ws/utils/attachWebSocketLogger.ts → ws/utils/attach-websocket-logger.ts} +45 -23
- package/src/{core/ws/utils/getMessageLength.test.ts → ws/utils/get-message-length.test.ts} +4 -4
- package/src/{core/ws/utils/getMessageLength.ts → ws/utils/get-message-length.ts} +1 -1
- package/src/{core/ws/utils/getPublicData.test.ts → ws/utils/get-public-data.test.ts} +7 -7
- package/src/ws/utils/get-public-data.ts +23 -0
- package/src/{core/ws/utils/truncateMessage.test.ts → ws/utils/truncate-message.test.ts} +3 -3
- package/src/{core/ws/WebSocketClientManager.test.ts → ws/websocket-client-manager.test.ts} +8 -9
- package/src/{core/ws/WebSocketClientManager.ts → ws/websocket-client-manager.ts} +24 -28
- package/src/{core/ws/WebSocketClientStore.ts → ws/websocket-client-store.ts} +2 -2
- package/src/{core/handlers/WebSocketHandler.test.ts → ws/websocket-handler.test.ts} +15 -15
- package/src/{core/handlers/WebSocketHandler.ts → ws/websocket-handler.ts} +144 -32
- package/src/{core/ws/WebSocketIndexedDBClientStore.ts → ws/websocket-indexeddb-client-store.ts} +12 -13
- package/src/{core/ws/WebSocketMemoryClientStore.ts → ws/websocket-memory-client-store.ts} +4 -4
- package/src/ws/websocket-upgrade.ts +83 -0
- package/src/{core → ws}/ws.test.ts +3 -4
- package/src/{core → ws}/ws.ts +106 -53
- package/browser/package.json +0 -31
- package/cli/package.json +0 -3
- package/config/package.json +0 -3
- package/config/scripts/postinstall.js +0 -36
- package/lib/browser/index.d.mts +0 -112
- package/lib/browser/index.mjs +0 -3706
- package/lib/browser/index.mjs.map +0 -1
- package/lib/core/HttpResponse-BE_Y2Ak9.d.mts +0 -389
- package/lib/core/HttpResponse-DL-P1EeG.d.ts +0 -389
- package/lib/core/HttpResponse.d.mts +0 -6
- package/lib/core/HttpResponse.d.ts +0 -6
- package/lib/core/HttpResponse.js +0 -176
- package/lib/core/HttpResponse.js.map +0 -1
- package/lib/core/HttpResponse.mjs +0 -159
- package/lib/core/HttpResponse.mjs.map +0 -1
- package/lib/core/bypass.d.mts +0 -16
- package/lib/core/bypass.js +0 -42
- package/lib/core/bypass.js.map +0 -1
- package/lib/core/bypass.mjs +0 -22
- package/lib/core/bypass.mjs.map +0 -1
- package/lib/core/delay.d.mts +0 -18
- package/lib/core/delay.d.ts +0 -18
- package/lib/core/delay.js +0 -77
- package/lib/core/delay.js.map +0 -1
- package/lib/core/delay.mjs +0 -57
- package/lib/core/delay.mjs.map +0 -1
- package/lib/core/experimental/compat.d.mts +0 -17
- package/lib/core/experimental/compat.d.ts +0 -17
- package/lib/core/experimental/compat.js +0 -55
- package/lib/core/experimental/compat.js.map +0 -1
- package/lib/core/experimental/compat.mjs +0 -37
- package/lib/core/experimental/compat.mjs.map +0 -1
- package/lib/core/experimental/define-network.d.mts +0 -75
- package/lib/core/experimental/define-network.d.ts +0 -75
- package/lib/core/experimental/define-network.js +0 -134
- package/lib/core/experimental/define-network.js.map +0 -1
- package/lib/core/experimental/define-network.mjs +0 -119
- package/lib/core/experimental/define-network.mjs.map +0 -1
- package/lib/core/experimental/frames/http-frame.d.mts +0 -77
- package/lib/core/experimental/frames/http-frame.d.ts +0 -77
- package/lib/core/experimental/frames/http-frame.js +0 -197
- package/lib/core/experimental/frames/http-frame.js.map +0 -1
- package/lib/core/experimental/frames/http-frame.mjs +0 -181
- package/lib/core/experimental/frames/http-frame.mjs.map +0 -1
- package/lib/core/experimental/frames/network-frame.d.mts +0 -12
- package/lib/core/experimental/frames/network-frame.d.ts +0 -12
- package/lib/core/experimental/frames/network-frame.js +0 -35
- package/lib/core/experimental/frames/network-frame.js.map +0 -1
- package/lib/core/experimental/frames/network-frame.mjs +0 -15
- package/lib/core/experimental/frames/network-frame.mjs.map +0 -1
- package/lib/core/experimental/frames/websocket-frame.d.mts +0 -55
- package/lib/core/experimental/frames/websocket-frame.d.ts +0 -55
- package/lib/core/experimental/frames/websocket-frame.js +0 -131
- package/lib/core/experimental/frames/websocket-frame.js.map +0 -1
- package/lib/core/experimental/frames/websocket-frame.mjs +0 -118
- package/lib/core/experimental/frames/websocket-frame.mjs.map +0 -1
- package/lib/core/experimental/handlers-controller.d.mts +0 -36
- package/lib/core/experimental/handlers-controller.d.ts +0 -36
- package/lib/core/experimental/handlers-controller.js +0 -146
- package/lib/core/experimental/handlers-controller.js.map +0 -1
- package/lib/core/experimental/handlers-controller.mjs +0 -126
- package/lib/core/experimental/handlers-controller.mjs.map +0 -1
- package/lib/core/experimental/index.d.mts +0 -17
- package/lib/core/experimental/index.js.map +0 -1
- package/lib/core/experimental/index.mjs +0 -27
- package/lib/core/experimental/index.mjs.map +0 -1
- package/lib/core/experimental/on-unhandled-frame.d.mts +0 -12
- package/lib/core/experimental/on-unhandled-frame.d.ts +0 -12
- package/lib/core/experimental/on-unhandled-frame.js +0 -91
- package/lib/core/experimental/on-unhandled-frame.js.map +0 -1
- package/lib/core/experimental/on-unhandled-frame.mjs +0 -71
- package/lib/core/experimental/on-unhandled-frame.mjs.map +0 -1
- package/lib/core/experimental/request-utils.d.mts +0 -12
- package/lib/core/experimental/request-utils.d.ts +0 -12
- package/lib/core/experimental/request-utils.js +0 -50
- package/lib/core/experimental/request-utils.js.map +0 -1
- package/lib/core/experimental/request-utils.mjs +0 -30
- package/lib/core/experimental/request-utils.mjs.map +0 -1
- package/lib/core/experimental/setup-api.d.mts +0 -33
- package/lib/core/experimental/setup-api.d.ts +0 -33
- package/lib/core/experimental/setup-api.js +0 -58
- package/lib/core/experimental/setup-api.js.map +0 -1
- package/lib/core/experimental/setup-api.mjs +0 -40
- package/lib/core/experimental/setup-api.mjs.map +0 -1
- package/lib/core/experimental/sources/interceptor-source.d.mts +0 -28
- package/lib/core/experimental/sources/interceptor-source.d.ts +0 -28
- package/lib/core/experimental/sources/interceptor-source.js +0 -155
- package/lib/core/experimental/sources/interceptor-source.js.map +0 -1
- package/lib/core/experimental/sources/interceptor-source.mjs +0 -135
- package/lib/core/experimental/sources/interceptor-source.mjs.map +0 -1
- package/lib/core/experimental/sources/network-source.d.mts +0 -31
- package/lib/core/experimental/sources/network-source.d.ts +0 -31
- package/lib/core/experimental/sources/network-source.js +0 -51
- package/lib/core/experimental/sources/network-source.js.map +0 -1
- package/lib/core/experimental/sources/network-source.mjs +0 -32
- package/lib/core/experimental/sources/network-source.mjs.map +0 -1
- package/lib/core/getResponse.d.mts +0 -18
- package/lib/core/getResponse.d.ts +0 -18
- package/lib/core/getResponse.js +0 -35
- package/lib/core/getResponse.js.map +0 -1
- package/lib/core/getResponse.mjs +0 -17
- package/lib/core/getResponse.mjs.map +0 -1
- package/lib/core/graphql.d.mts +0 -76
- package/lib/core/graphql.d.ts +0 -76
- package/lib/core/graphql.js +0 -91
- package/lib/core/graphql.js.map +0 -1
- package/lib/core/graphql.mjs +0 -74
- package/lib/core/graphql.mjs.map +0 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +0 -6
- package/lib/core/handlers/GraphQLHandler.d.ts +0 -6
- package/lib/core/handlers/GraphQLHandler.js +0 -232
- package/lib/core/handlers/GraphQLHandler.js.map +0 -1
- package/lib/core/handlers/GraphQLHandler.mjs +0 -221
- package/lib/core/handlers/GraphQLHandler.mjs.map +0 -1
- package/lib/core/handlers/HttpHandler.d.mts +0 -75
- package/lib/core/handlers/HttpHandler.d.ts +0 -75
- package/lib/core/handlers/HttpHandler.js +0 -129
- package/lib/core/handlers/HttpHandler.js.map +0 -1
- package/lib/core/handlers/HttpHandler.mjs +0 -113
- package/lib/core/handlers/HttpHandler.mjs.map +0 -1
- package/lib/core/handlers/RequestHandler.d.mts +0 -6
- package/lib/core/handlers/RequestHandler.d.ts +0 -6
- package/lib/core/handlers/RequestHandler.js +0 -365
- package/lib/core/handlers/RequestHandler.js.map +0 -1
- package/lib/core/handlers/RequestHandler.mjs +0 -348
- package/lib/core/handlers/RequestHandler.mjs.map +0 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +0 -49
- package/lib/core/handlers/WebSocketHandler.d.ts +0 -49
- package/lib/core/handlers/WebSocketHandler.js +0 -178
- package/lib/core/handlers/WebSocketHandler.js.map +0 -1
- package/lib/core/handlers/WebSocketHandler.mjs +0 -160
- package/lib/core/handlers/WebSocketHandler.mjs.map +0 -1
- package/lib/core/http.d.mts +0 -31
- package/lib/core/http.js +0 -41
- package/lib/core/http.js.map +0 -1
- package/lib/core/http.mjs +0 -25
- package/lib/core/http.mjs.map +0 -1
- package/lib/core/index.d.mts +0 -27
- package/lib/core/index.js.map +0 -1
- package/lib/core/index.mjs +0 -52
- package/lib/core/index.mjs.map +0 -1
- package/lib/core/isCommonAssetRequest.d.mts +0 -20
- package/lib/core/isCommonAssetRequest.d.ts +0 -20
- package/lib/core/isCommonAssetRequest.js +0 -42
- package/lib/core/isCommonAssetRequest.js.map +0 -1
- package/lib/core/isCommonAssetRequest.mjs +0 -22
- package/lib/core/isCommonAssetRequest.mjs.map +0 -1
- package/lib/core/on-unhandled-frame-0KmwUmeV.d.ts +0 -56
- package/lib/core/on-unhandled-frame-gkokW4Rr.d.mts +0 -56
- package/lib/core/passthrough.d.mts +0 -24
- package/lib/core/passthrough.d.ts +0 -24
- package/lib/core/passthrough.js +0 -33
- package/lib/core/passthrough.js.map +0 -1
- package/lib/core/passthrough.mjs +0 -13
- package/lib/core/passthrough.mjs.map +0 -1
- package/lib/core/sharedOptions.d.mts +0 -68
- package/lib/core/sharedOptions.d.ts +0 -68
- package/lib/core/sharedOptions.js +0 -17
- package/lib/core/sharedOptions.js.map +0 -1
- package/lib/core/sharedOptions.mjs +0 -1
- package/lib/core/sharedOptions.mjs.map +0 -1
- package/lib/core/sse.d.mts +0 -102
- package/lib/core/sse.d.ts +0 -102
- package/lib/core/sse.js +0 -690
- package/lib/core/sse.js.map +0 -1
- package/lib/core/sse.mjs +0 -672
- package/lib/core/sse.mjs.map +0 -1
- package/lib/core/typeUtils.d.mts +0 -12
- package/lib/core/typeUtils.d.ts +0 -12
- package/lib/core/typeUtils.js +0 -17
- package/lib/core/typeUtils.js.map +0 -1
- package/lib/core/typeUtils.mjs +0 -1
- package/lib/core/typeUtils.mjs.map +0 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +0 -22
- package/lib/core/utils/HttpResponse/decorators.d.ts +0 -22
- package/lib/core/utils/HttpResponse/decorators.js +0 -84
- package/lib/core/utils/HttpResponse/decorators.js.map +0 -1
- package/lib/core/utils/HttpResponse/decorators.mjs +0 -54
- package/lib/core/utils/HttpResponse/decorators.mjs.map +0 -1
- package/lib/core/utils/cookieStore.d.mts +0 -13
- package/lib/core/utils/cookieStore.d.ts +0 -13
- package/lib/core/utils/cookieStore.js +0 -90
- package/lib/core/utils/cookieStore.js.map +0 -1
- package/lib/core/utils/cookieStore.mjs +0 -74
- package/lib/core/utils/cookieStore.mjs.map +0 -1
- package/lib/core/utils/executeHandlers.d.mts +0 -6
- package/lib/core/utils/executeHandlers.d.ts +0 -6
- package/lib/core/utils/executeHandlers.js +0 -51
- package/lib/core/utils/executeHandlers.js.map +0 -1
- package/lib/core/utils/executeHandlers.mjs +0 -31
- package/lib/core/utils/executeHandlers.mjs.map +0 -1
- package/lib/core/utils/handleRequest.d.mts +0 -30
- package/lib/core/utils/handleRequest.d.ts +0 -30
- package/lib/core/utils/handleRequest.js +0 -76
- package/lib/core/utils/handleRequest.js.map +0 -1
- package/lib/core/utils/handleRequest.mjs +0 -58
- package/lib/core/utils/handleRequest.mjs.map +0 -1
- package/lib/core/utils/internal/Disposable.d.mts +0 -7
- package/lib/core/utils/internal/Disposable.d.ts +0 -7
- package/lib/core/utils/internal/Disposable.js +0 -51
- package/lib/core/utils/internal/Disposable.js.map +0 -1
- package/lib/core/utils/internal/Disposable.mjs +0 -31
- package/lib/core/utils/internal/Disposable.mjs.map +0 -1
- package/lib/core/utils/internal/attachSiblingHandlers.d.mts +0 -15
- package/lib/core/utils/internal/attachSiblingHandlers.d.ts +0 -15
- package/lib/core/utils/internal/attachSiblingHandlers.js +0 -44
- package/lib/core/utils/internal/attachSiblingHandlers.js.map +0 -1
- package/lib/core/utils/internal/attachSiblingHandlers.mjs +0 -24
- package/lib/core/utils/internal/attachSiblingHandlers.mjs.map +0 -1
- package/lib/core/utils/internal/checkGlobals.d.mts +0 -3
- package/lib/core/utils/internal/checkGlobals.d.ts +0 -3
- package/lib/core/utils/internal/checkGlobals.js +0 -34
- package/lib/core/utils/internal/checkGlobals.js.map +0 -1
- package/lib/core/utils/internal/checkGlobals.mjs +0 -14
- package/lib/core/utils/internal/checkGlobals.mjs.map +0 -1
- package/lib/core/utils/internal/devUtils.d.mts +0 -28
- package/lib/core/utils/internal/devUtils.d.ts +0 -28
- package/lib/core/utils/internal/devUtils.js +0 -48
- package/lib/core/utils/internal/devUtils.js.map +0 -1
- package/lib/core/utils/internal/devUtils.mjs +0 -28
- package/lib/core/utils/internal/devUtils.mjs.map +0 -1
- package/lib/core/utils/internal/getCallFrame.d.mts +0 -6
- package/lib/core/utils/internal/getCallFrame.d.ts +0 -6
- package/lib/core/utils/internal/getCallFrame.js +0 -41
- package/lib/core/utils/internal/getCallFrame.js.map +0 -1
- package/lib/core/utils/internal/getCallFrame.mjs +0 -21
- package/lib/core/utils/internal/getCallFrame.mjs.map +0 -1
- package/lib/core/utils/internal/hasRefCounted.d.mts +0 -3
- package/lib/core/utils/internal/hasRefCounted.d.ts +0 -3
- package/lib/core/utils/internal/hasRefCounted.js +0 -34
- package/lib/core/utils/internal/hasRefCounted.js.map +0 -1
- package/lib/core/utils/internal/hasRefCounted.mjs +0 -14
- package/lib/core/utils/internal/hasRefCounted.mjs.map +0 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +0 -19
- package/lib/core/utils/internal/isHandlerKind.d.ts +0 -19
- package/lib/core/utils/internal/isHandlerKind.js +0 -30
- package/lib/core/utils/internal/isHandlerKind.js.map +0 -1
- package/lib/core/utils/internal/isHandlerKind.mjs +0 -10
- package/lib/core/utils/internal/isHandlerKind.mjs.map +0 -1
- package/lib/core/utils/internal/isIterable.d.mts +0 -20
- package/lib/core/utils/internal/isIterable.d.ts +0 -20
- package/lib/core/utils/internal/isIterable.js +0 -30
- package/lib/core/utils/internal/isIterable.js.map +0 -1
- package/lib/core/utils/internal/isIterable.mjs +0 -10
- package/lib/core/utils/internal/isIterable.mjs.map +0 -1
- package/lib/core/utils/internal/isObject.d.mts +0 -6
- package/lib/core/utils/internal/isObject.d.ts +0 -6
- package/lib/core/utils/internal/isObject.js +0 -27
- package/lib/core/utils/internal/isObject.js.map +0 -1
- package/lib/core/utils/internal/isObject.mjs +0 -7
- package/lib/core/utils/internal/isObject.mjs.map +0 -1
- package/lib/core/utils/internal/isStringEqual.d.mts +0 -6
- package/lib/core/utils/internal/isStringEqual.d.ts +0 -6
- package/lib/core/utils/internal/isStringEqual.js +0 -27
- package/lib/core/utils/internal/isStringEqual.js.map +0 -1
- package/lib/core/utils/internal/isStringEqual.mjs +0 -7
- package/lib/core/utils/internal/isStringEqual.mjs.map +0 -1
- package/lib/core/utils/internal/jsonParse.d.mts +0 -7
- package/lib/core/utils/internal/jsonParse.d.ts +0 -7
- package/lib/core/utils/internal/jsonParse.js +0 -31
- package/lib/core/utils/internal/jsonParse.js.map +0 -1
- package/lib/core/utils/internal/jsonParse.mjs +0 -11
- package/lib/core/utils/internal/jsonParse.mjs.map +0 -1
- package/lib/core/utils/internal/mergeRight.d.mts +0 -7
- package/lib/core/utils/internal/mergeRight.d.ts +0 -7
- package/lib/core/utils/internal/mergeRight.js +0 -43
- package/lib/core/utils/internal/mergeRight.js.map +0 -1
- package/lib/core/utils/internal/mergeRight.mjs +0 -23
- package/lib/core/utils/internal/mergeRight.mjs.map +0 -1
- package/lib/core/utils/internal/observe-response-body-stream.d.mts +0 -18
- package/lib/core/utils/internal/observe-response-body-stream.d.ts +0 -18
- package/lib/core/utils/internal/observe-response-body-stream.js +0 -64
- package/lib/core/utils/internal/observe-response-body-stream.js.map +0 -1
- package/lib/core/utils/internal/observe-response-body-stream.mjs +0 -44
- package/lib/core/utils/internal/observe-response-body-stream.mjs.map +0 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +0 -6
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +0 -6
- package/lib/core/utils/internal/parseGraphQLRequest.js +0 -146
- package/lib/core/utils/internal/parseGraphQLRequest.js.map +0 -1
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +0 -129
- package/lib/core/utils/internal/parseGraphQLRequest.mjs.map +0 -1
- package/lib/core/utils/internal/parseMultipartData.d.mts +0 -14
- package/lib/core/utils/internal/parseMultipartData.d.ts +0 -14
- package/lib/core/utils/internal/parseMultipartData.js +0 -84
- package/lib/core/utils/internal/parseMultipartData.js.map +0 -1
- package/lib/core/utils/internal/parseMultipartData.mjs +0 -64
- package/lib/core/utils/internal/parseMultipartData.mjs.map +0 -1
- package/lib/core/utils/internal/pipeEvents.d.mts +0 -8
- package/lib/core/utils/internal/pipeEvents.d.ts +0 -8
- package/lib/core/utils/internal/pipeEvents.js +0 -37
- package/lib/core/utils/internal/pipeEvents.js.map +0 -1
- package/lib/core/utils/internal/pipeEvents.mjs +0 -17
- package/lib/core/utils/internal/pipeEvents.mjs.map +0 -1
- package/lib/core/utils/internal/toReadonlyArray.d.mts +0 -6
- package/lib/core/utils/internal/toReadonlyArray.d.ts +0 -6
- package/lib/core/utils/internal/toReadonlyArray.js +0 -29
- package/lib/core/utils/internal/toReadonlyArray.js.map +0 -1
- package/lib/core/utils/internal/toReadonlyArray.mjs +0 -9
- package/lib/core/utils/internal/toReadonlyArray.mjs.map +0 -1
- package/lib/core/utils/internal/tryCatch.d.mts +0 -3
- package/lib/core/utils/internal/tryCatch.d.ts +0 -3
- package/lib/core/utils/internal/tryCatch.js +0 -32
- package/lib/core/utils/internal/tryCatch.js.map +0 -1
- package/lib/core/utils/internal/tryCatch.mjs +0 -12
- package/lib/core/utils/internal/tryCatch.mjs.map +0 -1
- package/lib/core/utils/logging/getStatusCodeColor.d.mts +0 -11
- package/lib/core/utils/logging/getStatusCodeColor.d.ts +0 -11
- package/lib/core/utils/logging/getStatusCodeColor.js +0 -40
- package/lib/core/utils/logging/getStatusCodeColor.js.map +0 -1
- package/lib/core/utils/logging/getStatusCodeColor.mjs +0 -20
- package/lib/core/utils/logging/getStatusCodeColor.mjs.map +0 -1
- package/lib/core/utils/logging/getTimestamp.d.mts +0 -9
- package/lib/core/utils/logging/getTimestamp.d.ts +0 -9
- package/lib/core/utils/logging/getTimestamp.js +0 -32
- package/lib/core/utils/logging/getTimestamp.js.map +0 -1
- package/lib/core/utils/logging/getTimestamp.mjs +0 -12
- package/lib/core/utils/logging/getTimestamp.mjs.map +0 -1
- package/lib/core/utils/logging/serializeRequest.d.mts +0 -12
- package/lib/core/utils/logging/serializeRequest.d.ts +0 -12
- package/lib/core/utils/logging/serializeRequest.js +0 -34
- package/lib/core/utils/logging/serializeRequest.js.map +0 -1
- package/lib/core/utils/logging/serializeRequest.mjs +0 -14
- package/lib/core/utils/logging/serializeRequest.mjs.map +0 -1
- package/lib/core/utils/logging/serializeResponse.d.mts +0 -9
- package/lib/core/utils/logging/serializeResponse.d.ts +0 -9
- package/lib/core/utils/logging/serializeResponse.js +0 -48
- package/lib/core/utils/logging/serializeResponse.js.map +0 -1
- package/lib/core/utils/logging/serializeResponse.mjs +0 -18
- package/lib/core/utils/logging/serializeResponse.mjs.map +0 -1
- package/lib/core/utils/matching/matchRequestUrl.d.mts +0 -20
- package/lib/core/utils/matching/matchRequestUrl.d.ts +0 -20
- package/lib/core/utils/matching/matchRequestUrl.js +0 -55
- package/lib/core/utils/matching/matchRequestUrl.js.map +0 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs +0 -35
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +0 -1
- package/lib/core/utils/matching/normalizePath.d.mts +0 -13
- package/lib/core/utils/matching/normalizePath.d.ts +0 -13
- package/lib/core/utils/matching/normalizePath.js +0 -33
- package/lib/core/utils/matching/normalizePath.js.map +0 -1
- package/lib/core/utils/matching/normalizePath.mjs +0 -13
- package/lib/core/utils/matching/normalizePath.mjs.map +0 -1
- package/lib/core/utils/request/getAllAcceptedMimeTypes.d.mts +0 -14
- package/lib/core/utils/request/getAllAcceptedMimeTypes.d.ts +0 -14
- package/lib/core/utils/request/getAllAcceptedMimeTypes.js +0 -61
- package/lib/core/utils/request/getAllAcceptedMimeTypes.js.map +0 -1
- package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs +0 -41
- package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs.map +0 -1
- package/lib/core/utils/request/getRequestCookies.d.mts +0 -3
- package/lib/core/utils/request/getRequestCookies.d.ts +0 -3
- package/lib/core/utils/request/getRequestCookies.js +0 -79
- package/lib/core/utils/request/getRequestCookies.js.map +0 -1
- package/lib/core/utils/request/getRequestCookies.mjs +0 -62
- package/lib/core/utils/request/getRequestCookies.mjs.map +0 -1
- package/lib/core/utils/request/onUnhandledRequest.d.mts +0 -9
- package/lib/core/utils/request/onUnhandledRequest.d.ts +0 -9
- package/lib/core/utils/request/onUnhandledRequest.js +0 -76
- package/lib/core/utils/request/onUnhandledRequest.js.map +0 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs +0 -56
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +0 -1
- package/lib/core/utils/request/storeResponseCookies.d.mts +0 -3
- package/lib/core/utils/request/storeResponseCookies.d.ts +0 -3
- package/lib/core/utils/request/storeResponseCookies.js +0 -32
- package/lib/core/utils/request/storeResponseCookies.js.map +0 -1
- package/lib/core/utils/request/storeResponseCookies.mjs +0 -12
- package/lib/core/utils/request/storeResponseCookies.mjs.map +0 -1
- package/lib/core/utils/request/toPublicUrl.d.mts +0 -7
- package/lib/core/utils/request/toPublicUrl.d.ts +0 -7
- package/lib/core/utils/request/toPublicUrl.js +0 -31
- package/lib/core/utils/request/toPublicUrl.js.map +0 -1
- package/lib/core/utils/request/toPublicUrl.mjs +0 -11
- package/lib/core/utils/request/toPublicUrl.mjs.map +0 -1
- package/lib/core/utils/toResponseInit.d.mts +0 -3
- package/lib/core/utils/toResponseInit.d.ts +0 -3
- package/lib/core/utils/toResponseInit.js +0 -31
- package/lib/core/utils/toResponseInit.js.map +0 -1
- package/lib/core/utils/toResponseInit.mjs +0 -11
- package/lib/core/utils/toResponseInit.mjs.map +0 -1
- package/lib/core/utils/url/cleanUrl.d.mts +0 -7
- package/lib/core/utils/url/cleanUrl.d.ts +0 -7
- package/lib/core/utils/url/cleanUrl.js +0 -31
- package/lib/core/utils/url/cleanUrl.js.map +0 -1
- package/lib/core/utils/url/cleanUrl.mjs +0 -11
- package/lib/core/utils/url/cleanUrl.mjs.map +0 -1
- package/lib/core/utils/url/getAbsoluteUrl.d.mts +0 -6
- package/lib/core/utils/url/getAbsoluteUrl.d.ts +0 -6
- package/lib/core/utils/url/getAbsoluteUrl.js +0 -38
- package/lib/core/utils/url/getAbsoluteUrl.js.map +0 -1
- package/lib/core/utils/url/getAbsoluteUrl.mjs +0 -18
- package/lib/core/utils/url/getAbsoluteUrl.mjs.map +0 -1
- package/lib/core/utils/url/isAbsoluteUrl.d.mts +0 -6
- package/lib/core/utils/url/isAbsoluteUrl.d.ts +0 -6
- package/lib/core/utils/url/isAbsoluteUrl.js +0 -27
- package/lib/core/utils/url/isAbsoluteUrl.js.map +0 -1
- package/lib/core/utils/url/isAbsoluteUrl.mjs +0 -7
- package/lib/core/utils/url/isAbsoluteUrl.mjs.map +0 -1
- package/lib/core/ws/WebSocketClientManager.d.mts +0 -65
- package/lib/core/ws/WebSocketClientManager.d.ts +0 -65
- package/lib/core/ws/WebSocketClientManager.js +0 -163
- package/lib/core/ws/WebSocketClientManager.js.map +0 -1
- package/lib/core/ws/WebSocketClientManager.mjs +0 -143
- package/lib/core/ws/WebSocketClientManager.mjs.map +0 -1
- package/lib/core/ws/WebSocketClientStore.d.mts +0 -13
- package/lib/core/ws/WebSocketClientStore.d.ts +0 -13
- package/lib/core/ws/WebSocketClientStore.js +0 -26
- package/lib/core/ws/WebSocketClientStore.js.map +0 -1
- package/lib/core/ws/WebSocketClientStore.mjs +0 -6
- package/lib/core/ws/WebSocketClientStore.mjs.map +0 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.mts +0 -14
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.ts +0 -14
- package/lib/core/ws/WebSocketIndexedDBClientStore.js +0 -131
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +0 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +0 -111
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +0 -1
- package/lib/core/ws/WebSocketMemoryClientStore.d.mts +0 -12
- package/lib/core/ws/WebSocketMemoryClientStore.d.ts +0 -12
- package/lib/core/ws/WebSocketMemoryClientStore.js +0 -42
- package/lib/core/ws/WebSocketMemoryClientStore.js.map +0 -1
- package/lib/core/ws/WebSocketMemoryClientStore.mjs +0 -22
- package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +0 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +0 -20
- package/lib/core/ws/handleWebSocketEvent.d.ts +0 -20
- package/lib/core/ws/handleWebSocketEvent.js +0 -61
- package/lib/core/ws/handleWebSocketEvent.js.map +0 -1
- package/lib/core/ws/handleWebSocketEvent.mjs +0 -43
- package/lib/core/ws/handleWebSocketEvent.mjs.map +0 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +0 -18
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +0 -18
- package/lib/core/ws/utils/attachWebSocketLogger.js +0 -228
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +0 -1
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +0 -208
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +0 -1
- package/lib/core/ws/utils/getMessageLength.d.mts +0 -11
- package/lib/core/ws/utils/getMessageLength.d.ts +0 -11
- package/lib/core/ws/utils/getMessageLength.js +0 -34
- package/lib/core/ws/utils/getMessageLength.js.map +0 -1
- package/lib/core/ws/utils/getMessageLength.mjs +0 -14
- package/lib/core/ws/utils/getMessageLength.mjs.map +0 -1
- package/lib/core/ws/utils/getPublicData.d.mts +0 -5
- package/lib/core/ws/utils/getPublicData.d.ts +0 -5
- package/lib/core/ws/utils/getPublicData.js +0 -37
- package/lib/core/ws/utils/getPublicData.js.map +0 -1
- package/lib/core/ws/utils/getPublicData.mjs +0 -17
- package/lib/core/ws/utils/getPublicData.mjs.map +0 -1
- package/lib/core/ws/utils/truncateMessage.d.mts +0 -3
- package/lib/core/ws/utils/truncateMessage.d.ts +0 -3
- package/lib/core/ws/utils/truncateMessage.js +0 -31
- package/lib/core/ws/utils/truncateMessage.js.map +0 -1
- package/lib/core/ws/utils/truncateMessage.mjs +0 -11
- package/lib/core/ws/utils/truncateMessage.mjs.map +0 -1
- package/lib/core/ws/webSocketInterceptor.d.mts +0 -5
- package/lib/core/ws/webSocketInterceptor.d.ts +0 -5
- package/lib/core/ws/webSocketInterceptor.js +0 -26
- package/lib/core/ws/webSocketInterceptor.js.map +0 -1
- package/lib/core/ws/webSocketInterceptor.mjs +0 -6
- package/lib/core/ws/webSocketInterceptor.mjs.map +0 -1
- package/lib/core/ws.d.mts +0 -88
- package/lib/core/ws.d.ts +0 -88
- package/lib/core/ws.js +0 -94
- package/lib/core/ws.js.map +0 -1
- package/lib/core/ws.mjs +0 -80
- package/lib/core/ws.mjs.map +0 -1
- package/lib/native/index.d.mts +0 -66
- package/lib/native/index.d.ts +0 -66
- package/lib/native/index.js +0 -88
- package/lib/native/index.js.map +0 -1
- package/lib/native/index.mjs +0 -67
- package/lib/native/index.mjs.map +0 -1
- package/lib/node/index.d.mts +0 -113
- package/lib/node/index.mjs +0 -185
- package/lib/node/index.mjs.map +0 -1
- package/lib/shims/cookie.d.mts +0 -7
- package/lib/shims/cookie.d.ts +0 -7
- package/lib/shims/cookie.js +0 -294
- package/lib/shims/cookie.mjs +0 -286
- package/lib/shims/statuses.d.mts +0 -6
- package/lib/shims/statuses.d.ts +0 -6
- package/lib/shims/statuses.js +0 -195
- package/lib/shims/statuses.mjs +0 -187
- package/native/package.json +0 -30
- package/node/package.json +0 -33
- package/src/browser/utils/pruneGetRequestBody.test.ts +0 -51
- package/src/browser/utils/pruneGetRequestBody.ts +0 -21
- package/src/core/experimental/compat.ts +0 -50
- package/src/core/experimental/setup-api.ts +0 -55
- package/src/core/graphql.test.ts +0 -11
- package/src/core/graphql.ts +0 -136
- package/src/core/passthrough.test.ts +0 -11
- package/src/core/passthrough.ts +0 -25
- package/src/core/sharedOptions.ts +0 -71
- package/src/core/typeUtils.ts +0 -26
- package/src/core/utils/handleRequest.test.ts +0 -574
- package/src/core/utils/handleRequest.ts +0 -117
- package/src/core/utils/internal/checkGlobals.ts +0 -17
- package/src/core/utils/internal/isHandlerKind.test.ts +0 -62
- package/src/core/utils/internal/isHandlerKind.ts +0 -17
- package/src/core/utils/internal/isIterable.ts +0 -32
- package/src/core/utils/internal/mergeRight.test.ts +0 -43
- package/src/core/utils/internal/mergeRight.ts +0 -30
- package/src/core/utils/internal/pipeEvents.test.ts +0 -14
- package/src/core/utils/internal/pipeEvents.ts +0 -26
- package/src/core/utils/internal/tryCatch.test.ts +0 -29
- package/src/core/utils/internal/tryCatch.ts +0 -11
- package/src/core/utils/matching/matchRequestUrl.test.ts +0 -267
- package/src/core/utils/matching/matchRequestUrl.ts +0 -77
- package/src/core/utils/request/getRequestCookies.ts +0 -88
- package/src/core/utils/request/onUnhandledRequest.node.test.ts +0 -62
- package/src/core/utils/request/onUnhandledRequest.test.ts +0 -226
- package/src/core/utils/request/onUnhandledRequest.ts +0 -81
- package/src/core/utils/request/storeResponseCookies.ts +0 -15
- package/src/core/utils/url/cleanUrl.test.ts +0 -22
- package/src/core/utils/url/cleanUrl.ts +0 -16
- package/src/core/utils/url/isAbsoluteUrl.test.ts +0 -32
- package/src/core/ws/handleWebSocketEvent.ts +0 -68
- package/src/core/ws/utils/getPublicData.ts +0 -18
- package/src/core/ws/webSocketInterceptor.ts +0 -3
- package/src/native/index.ts +0 -44
- package/src/package.json +0 -3
- package/src/shims/cookie.ts +0 -7
- package/src/shims/statuses.ts +0 -6
- /package/src/browser/utils/{getAbsoluteWorkerUrl.ts → get-absolute-worker-url.ts} +0 -0
- /package/src/core/utils/internal/{devUtils.ts → dev-utils.ts} +0 -0
- /package/src/core/utils/internal/{isObject.ts → is-object.ts} +0 -0
- /package/src/core/utils/internal/{isStringEqual.ts → is-string-equal.ts} +0 -0
- /package/src/core/utils/internal/{jsonParse.ts → json-parse.ts} +0 -0
- /package/src/core/utils/internal/{toReadonlyArray.ts → to-readonly-array.ts} +0 -0
- /package/src/core/utils/logging/{getStatusCodeColor.ts → get-status-code-color.ts} +0 -0
- /package/src/core/utils/logging/{getTimestamp.ts → get-timestamp.ts} +0 -0
- /package/src/core/utils/logging/{serializeRequest.ts → serialize-request.ts} +0 -0
- /package/src/core/utils/request/{getAllAcceptedMimeTypes.ts → get-all-accepted-mime-types.ts} +0 -0
- /package/src/core/utils/request/{toPublicUrl.ts → to-public-url.ts} +0 -0
- /package/src/core/utils/{toResponseInit.ts → to-response-init.ts} +0 -0
- /package/src/core/utils/url/{isAbsoluteUrl.ts → is-absolute-url.ts} +0 -0
- /package/src/{core → http}/http.test.ts +0 -0
- /package/src/{core/ws/utils/truncateMessage.ts → ws/utils/truncate-message.ts} +0 -0
|
@@ -0,0 +1,1244 @@
|
|
|
1
|
+
import { a as matchRequestUrl, m as devUtils, n as jsonParse, r as toPublicUrl, s as getTimestamp } from "../_chunks/cookie-store.js";
|
|
2
|
+
import { t as RequestHandler } from "../_chunks/request-handler.js";
|
|
3
|
+
import { a as serializeRequest, i as serializeResponse, o as getStatusCodeColor, r as getAllRequestCookies } from "../_chunks/http-handler.js";
|
|
4
|
+
import { t as http } from "../_chunks/http.js";
|
|
5
|
+
import { a as WebSocketHandler, s as kConnect, t as attachSiblingHandlers } from "../_chunks/attach-sibling-handlers.js";
|
|
6
|
+
import { t as colors } from "../_chunks/colors.js";
|
|
7
|
+
import { n as webSocketUpgrade } from "../_chunks/websocket-upgrade.js";
|
|
8
|
+
import { n as kDefaultContentType } from "../_chunks/symbols.js";
|
|
9
|
+
import { invariant } from "outvariant";
|
|
10
|
+
import { createRequestId, resolveWebSocketUrl } from "@mswjs/interceptors";
|
|
11
|
+
import { Emitter, TypedEvent } from "rettime";
|
|
12
|
+
import { OperationTypeNode, parse } from "graphql";
|
|
13
|
+
import { stringToHeaders } from "headers-polyfill";
|
|
14
|
+
//#region src/core/utils/internal/parse-multipart-data.ts
|
|
15
|
+
function parseContentHeaders(headersString) {
|
|
16
|
+
const headers = stringToHeaders(headersString);
|
|
17
|
+
const contentType = headers.get("content-type") || "text/plain";
|
|
18
|
+
const disposition = headers.get("content-disposition");
|
|
19
|
+
if (!disposition) throw new Error("\"Content-Disposition\" header is required.");
|
|
20
|
+
const directives = disposition.split(";").reduce((acc, chunk) => {
|
|
21
|
+
const [name, ...rest] = chunk.trim().split("=");
|
|
22
|
+
acc[name] = rest.join("=");
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
return {
|
|
26
|
+
name: directives.name?.slice(1, -1),
|
|
27
|
+
filename: directives.filename?.slice(1, -1),
|
|
28
|
+
contentType
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parses a given string as a multipart/form-data.
|
|
33
|
+
* Does not throw an exception on an invalid multipart string.
|
|
34
|
+
*/
|
|
35
|
+
function parseMultipartData(data, headers) {
|
|
36
|
+
const contentType = headers?.get("content-type");
|
|
37
|
+
if (!contentType) return;
|
|
38
|
+
const [, ...directives] = contentType.split(/; */);
|
|
39
|
+
const boundary = directives.filter((d) => d.startsWith("boundary=")).map((s) => s.replace(/^boundary=/, ""))[0];
|
|
40
|
+
if (!boundary) return;
|
|
41
|
+
const boundaryRegExp = new RegExp(`--+${boundary.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`);
|
|
42
|
+
const fields = data.split(boundaryRegExp).filter((chunk) => chunk.startsWith("\r\n") && chunk.endsWith("\r\n")).map((chunk) => chunk.trimStart().replace(/\r\n$/, ""));
|
|
43
|
+
if (!fields.length) return;
|
|
44
|
+
const parsedBody = {};
|
|
45
|
+
try {
|
|
46
|
+
for (const field of fields) {
|
|
47
|
+
const [contentHeaders, ...rest] = field.split("\r\n\r\n");
|
|
48
|
+
const contentBody = rest.join("\r\n\r\n");
|
|
49
|
+
const { contentType, filename, name } = parseContentHeaders(contentHeaders);
|
|
50
|
+
const value = filename === void 0 ? contentBody : new File([contentBody], filename, { type: contentType });
|
|
51
|
+
const parsedValue = parsedBody[name];
|
|
52
|
+
if (parsedValue === void 0) parsedBody[name] = value;
|
|
53
|
+
else if (Array.isArray(parsedValue)) parsedBody[name] = [...parsedValue, value];
|
|
54
|
+
else parsedBody[name] = [parsedValue, value];
|
|
55
|
+
}
|
|
56
|
+
return parsedBody;
|
|
57
|
+
} catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/graphql/parse-graphql-request.ts
|
|
63
|
+
function parseDocumentNode(node, operationName) {
|
|
64
|
+
const operationDefs = node.definitions.filter((definition) => {
|
|
65
|
+
return definition.kind === "OperationDefinition";
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* @note A document may bundle multiple operations (e.g. the ones
|
|
69
|
+
* emitted by GraphQL Code Generator). Honor the requested operation
|
|
70
|
+
* name, and resolve nothing if the document has no such operation.
|
|
71
|
+
* Falling back to the first operation would silently resolve one the
|
|
72
|
+
* client never asked for.
|
|
73
|
+
*/
|
|
74
|
+
const operationDef = operationName ? operationDefs.find((definition) => {
|
|
75
|
+
return definition.name?.value === operationName;
|
|
76
|
+
}) : operationDefs[0];
|
|
77
|
+
return {
|
|
78
|
+
operationType: operationDef?.operation,
|
|
79
|
+
/**
|
|
80
|
+
* @note Echo the requested operation name even when the document
|
|
81
|
+
* has no such operation. It makes the "unhandled operation" warnings
|
|
82
|
+
* name the operation the client actually asked for.
|
|
83
|
+
*/
|
|
84
|
+
operationName: operationDef?.name?.value || operationName || void 0
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async function parseQuery(query, operationName) {
|
|
88
|
+
try {
|
|
89
|
+
return parseDocumentNode(parse(query), operationName);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function extractMultipartVariables(variables, map, files) {
|
|
95
|
+
const operations = { variables };
|
|
96
|
+
for (const [key, pathArray] of Object.entries(map)) {
|
|
97
|
+
if (!(key in files)) throw new Error(`Given files do not have a key '${key}' .`);
|
|
98
|
+
for (const dotPath of pathArray) {
|
|
99
|
+
const [lastPath, ...reversedPaths] = dotPath.split(".").reverse();
|
|
100
|
+
const paths = reversedPaths.reverse();
|
|
101
|
+
let target = operations;
|
|
102
|
+
for (const path of paths) {
|
|
103
|
+
if (!(path in target)) throw new Error(`Property '${path}' is not in operations.`);
|
|
104
|
+
target = target[path];
|
|
105
|
+
}
|
|
106
|
+
target[lastPath] = files[key];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return operations.variables;
|
|
110
|
+
}
|
|
111
|
+
async function getGraphQLInput(request) {
|
|
112
|
+
switch (request.method) {
|
|
113
|
+
case "GET": {
|
|
114
|
+
const url = new URL(request.url);
|
|
115
|
+
const query = url.searchParams.get("query");
|
|
116
|
+
const variables = url.searchParams.get("variables") || "";
|
|
117
|
+
return {
|
|
118
|
+
query,
|
|
119
|
+
variables: jsonParse(variables),
|
|
120
|
+
operationName: url.searchParams.get("operationName")
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
case "POST": {
|
|
124
|
+
const requestClone = request.clone();
|
|
125
|
+
if (request.headers.get("content-type")?.includes("multipart/form-data")) {
|
|
126
|
+
const responseJson = parseMultipartData(await requestClone.text(), request.headers);
|
|
127
|
+
if (!responseJson) return null;
|
|
128
|
+
const { operations, map, ...files } = responseJson;
|
|
129
|
+
const parsedOperations = jsonParse(operations) || {};
|
|
130
|
+
if (!parsedOperations.query) return null;
|
|
131
|
+
const parsedMap = jsonParse(map || "") || {};
|
|
132
|
+
const variables = parsedOperations.variables ? extractMultipartVariables(parsedOperations.variables, parsedMap, files) : {};
|
|
133
|
+
return {
|
|
134
|
+
query: parsedOperations.query,
|
|
135
|
+
variables,
|
|
136
|
+
operationName: parsedOperations.operationName
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const requestJson = await requestClone.json().catch(() => null);
|
|
140
|
+
if (requestJson?.query) {
|
|
141
|
+
const { query, variables, operationName } = requestJson;
|
|
142
|
+
return {
|
|
143
|
+
query,
|
|
144
|
+
variables,
|
|
145
|
+
operationName
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
default: return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Determines if a given request can be considered a GraphQL request.
|
|
155
|
+
* Does not parse the query and does not guarantee its validity.
|
|
156
|
+
*/
|
|
157
|
+
async function parseGraphQLRequest(request) {
|
|
158
|
+
const input = await getGraphQLInput(request);
|
|
159
|
+
if (!input || !input.query) return;
|
|
160
|
+
const { query, variables, operationName } = input;
|
|
161
|
+
const parsedResult = await parseQuery(query, operationName);
|
|
162
|
+
if (parsedResult instanceof Error) {
|
|
163
|
+
const requestPublicUrl = toPublicUrl(request.url);
|
|
164
|
+
throw new Error(devUtils.formatMessage("Failed to intercept a GraphQL request to \"%s %s\": cannot parse query. See the error message from the parser below.\n\n%s", request.method, requestPublicUrl, parsedResult.message));
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
query: input.query,
|
|
168
|
+
operationType: parsedResult.operationType,
|
|
169
|
+
operationName: parsedResult.operationName,
|
|
170
|
+
variables
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/core/utils/request/get-all-accepted-mime-types.ts
|
|
175
|
+
/**
|
|
176
|
+
* Returns all accepted mime types, ordered by precedence as defined
|
|
177
|
+
* in [RFC 7231 Section 5.3.2](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2).
|
|
178
|
+
*
|
|
179
|
+
* Precedence rules (highest to lowest):
|
|
180
|
+
* 1. Quality value (`q` parameter, default 1).
|
|
181
|
+
* 2. Specificity: `type/subtype` > `type/*` > `*\/*`.
|
|
182
|
+
* 3. Number of media type parameters (more = more specific).
|
|
183
|
+
*
|
|
184
|
+
* Types with `q=0` are excluded (explicitly not acceptable).
|
|
185
|
+
*/
|
|
186
|
+
function getAllAcceptedMimeTypes(acceptHeader) {
|
|
187
|
+
if (acceptHeader == null) return [];
|
|
188
|
+
const accepted = [];
|
|
189
|
+
for (const part of acceptHeader.split(",")) {
|
|
190
|
+
const [type, ...params] = part.split(";").map((v) => v.trim());
|
|
191
|
+
let quality = 1;
|
|
192
|
+
let parameterCount = 0;
|
|
193
|
+
for (const param of params) {
|
|
194
|
+
const [key, value] = param.split("=").map((v) => v.trim());
|
|
195
|
+
if (key === "q") quality = Number(value);
|
|
196
|
+
else parameterCount++;
|
|
197
|
+
}
|
|
198
|
+
if (quality === 0) continue;
|
|
199
|
+
const [mediaType, mediaSubtype] = type.split("/");
|
|
200
|
+
const specificity = mediaType === "*" ? 0 : mediaSubtype === "*" ? 1 : 2;
|
|
201
|
+
accepted.push({
|
|
202
|
+
type,
|
|
203
|
+
quality,
|
|
204
|
+
specificity,
|
|
205
|
+
parameterCount
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
if (!accepted.length) return [];
|
|
209
|
+
return accepted.sort((left, right) => {
|
|
210
|
+
if (right.quality !== left.quality) return right.quality - left.quality;
|
|
211
|
+
if (right.specificity !== left.specificity) return right.specificity - left.specificity;
|
|
212
|
+
return right.parameterCount - left.parameterCount;
|
|
213
|
+
}).map((entry) => entry.type);
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/graphql/graphql-handler.ts
|
|
217
|
+
function isDocumentNode(value) {
|
|
218
|
+
if (value == null) return false;
|
|
219
|
+
return typeof value === "object" && "kind" in value && "definitions" in value;
|
|
220
|
+
}
|
|
221
|
+
function isDocumentTypeDecoration(value) {
|
|
222
|
+
return value instanceof String;
|
|
223
|
+
}
|
|
224
|
+
var GraphQLHandler = class GraphQLHandler extends RequestHandler {
|
|
225
|
+
endpoint;
|
|
226
|
+
static parsedRequestCache = /* @__PURE__ */ new WeakMap();
|
|
227
|
+
static #parseOperationName(predicate, operationType) {
|
|
228
|
+
const getOperationName = (node) => {
|
|
229
|
+
invariant(node.operationType === operationType, "Failed to create a GraphQL handler: provided a DocumentNode with a mismatched operation type (expected \"%s\" but got \"%s\").", operationType, node.operationType);
|
|
230
|
+
invariant(node.operationName, "Failed to create a GraphQL handler: provided a DocumentNode without operation name");
|
|
231
|
+
return node.operationName;
|
|
232
|
+
};
|
|
233
|
+
if (isDocumentNode(predicate)) return getOperationName(parseDocumentNode(predicate));
|
|
234
|
+
if (isDocumentTypeDecoration(predicate)) {
|
|
235
|
+
const documentNode = parse(predicate.toString());
|
|
236
|
+
invariant(isDocumentNode(documentNode), "Failed to create a GraphQL handler: given TypedDocumentString (%s) does not produce a valid DocumentNode", predicate);
|
|
237
|
+
return getOperationName(parseDocumentNode(documentNode));
|
|
238
|
+
}
|
|
239
|
+
return predicate;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Creates a GraphQL handler information object from the given
|
|
243
|
+
* operation predicate. Normalizes `DocumentNode` and typed document
|
|
244
|
+
* string predicates to plain operation names.
|
|
245
|
+
*/
|
|
246
|
+
static parseGraphQLRequestInfo(args) {
|
|
247
|
+
const operationName = GraphQLHandler.#parseOperationName(args.predicate, args.operationType);
|
|
248
|
+
const displayOperationName = typeof operationName === "function" ? "[custom predicate]" : operationName;
|
|
249
|
+
return {
|
|
250
|
+
header: args.operationType === "all" ? `${args.operationType} (origin: ${args.url.toString()})` : `${args.operationType}${displayOperationName ? ` ${displayOperationName}` : ""} (origin: ${args.url.toString()})`,
|
|
251
|
+
operationType: args.operationType,
|
|
252
|
+
operationName
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
constructor(operationType, predicate, endpoint, resolver, options) {
|
|
256
|
+
super({
|
|
257
|
+
info: GraphQLHandler.parseGraphQLRequestInfo({
|
|
258
|
+
operationType,
|
|
259
|
+
predicate,
|
|
260
|
+
url: endpoint
|
|
261
|
+
}),
|
|
262
|
+
resolver,
|
|
263
|
+
options
|
|
264
|
+
});
|
|
265
|
+
this.endpoint = endpoint;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Parses the request body, once per request, cached across all
|
|
269
|
+
* GraphQL handlers. This is done to avoid multiple parsing of the
|
|
270
|
+
* request body, which each requires a clone of the request.
|
|
271
|
+
*/
|
|
272
|
+
async parseGraphQLRequestOrGetFromCache(request) {
|
|
273
|
+
if (!GraphQLHandler.parsedRequestCache.has(request)) GraphQLHandler.parsedRequestCache.set(request, await parseGraphQLRequest(request).catch((error) => {
|
|
274
|
+
console.error(error);
|
|
275
|
+
}));
|
|
276
|
+
return GraphQLHandler.parsedRequestCache.get(request);
|
|
277
|
+
}
|
|
278
|
+
async parse(args) {
|
|
279
|
+
const match = matchRequestUrl(new URL(args.request.url), this.endpoint);
|
|
280
|
+
const cookies = getAllRequestCookies(args.request);
|
|
281
|
+
if (!match.matches) return {
|
|
282
|
+
match,
|
|
283
|
+
cookies
|
|
284
|
+
};
|
|
285
|
+
const parsedResult = await this.parseGraphQLRequestOrGetFromCache(args.request);
|
|
286
|
+
if (typeof parsedResult === "undefined") return {
|
|
287
|
+
match,
|
|
288
|
+
cookies
|
|
289
|
+
};
|
|
290
|
+
return {
|
|
291
|
+
match,
|
|
292
|
+
cookies,
|
|
293
|
+
query: parsedResult.query,
|
|
294
|
+
operationType: parsedResult.operationType,
|
|
295
|
+
operationName: parsedResult.operationName,
|
|
296
|
+
variables: parsedResult.variables
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
async predicate(args) {
|
|
300
|
+
if (args.parsedResult.operationType === void 0) return false;
|
|
301
|
+
if (!args.parsedResult.operationName && this.info.operationType !== "all") {
|
|
302
|
+
const publicUrl = toPublicUrl(args.request.url);
|
|
303
|
+
devUtils.warn(`\
|
|
304
|
+
Failed to intercept a GraphQL request at "${args.request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
305
|
+
|
|
306
|
+
Consider naming this operation or using the "operation()" request handler of "graphql.link()" to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/#graphqloperationresolver`);
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
const hasMatchingOperationType = this.info.operationType === "all" || args.parsedResult.operationType === this.info.operationType;
|
|
310
|
+
/**
|
|
311
|
+
* Check if the operation name matches the outgoing GraphQL request.
|
|
312
|
+
* @note Unlike the HTTP handler, the custom predicate functions are invoked
|
|
313
|
+
* during predicate, not parsing, because GraphQL request parsing happens first,
|
|
314
|
+
* and non-GraphQL requests are filtered out automatically.
|
|
315
|
+
*/
|
|
316
|
+
const hasMatchingOperationName = await this.matchOperationName({
|
|
317
|
+
request: args.request,
|
|
318
|
+
parsedResult: args.parsedResult
|
|
319
|
+
});
|
|
320
|
+
return args.parsedResult.match.matches && hasMatchingOperationType && hasMatchingOperationName;
|
|
321
|
+
}
|
|
322
|
+
async run(args) {
|
|
323
|
+
const result = await super.run(args);
|
|
324
|
+
if (result?.response == null) return result;
|
|
325
|
+
if (!(kDefaultContentType in result.response)) return result;
|
|
326
|
+
const acceptedMimeTypes = getAllAcceptedMimeTypes(args.request.headers.get("accept"));
|
|
327
|
+
if (acceptedMimeTypes.length === 0) return result;
|
|
328
|
+
const graphqlResponseIndex = acceptedMimeTypes.indexOf("application/graphql-response+json");
|
|
329
|
+
const jsonIndex = acceptedMimeTypes.indexOf("application/json");
|
|
330
|
+
/**
|
|
331
|
+
* Use the "application/graphql-response+json" response content type
|
|
332
|
+
* only when the client accepts it AND prefers it over "application/json"
|
|
333
|
+
* (i.e. it appears earlier in the precedence-sorted list, or "application/json"
|
|
334
|
+
* is not listed at all).
|
|
335
|
+
* @see https://github.com/graphql/graphql-over-http/blob/4d1df1fb829ec2dd3ecbf3c6aa4025bd356c270d/spec/GraphQLOverHTTP.md#accept
|
|
336
|
+
*/
|
|
337
|
+
if (graphqlResponseIndex !== -1 && (jsonIndex === -1 || graphqlResponseIndex <= jsonIndex)) result.response.headers.set("content-type", "application/graphql-response+json");
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
340
|
+
async matchOperationName(args) {
|
|
341
|
+
if (typeof this.info.operationName === "function") {
|
|
342
|
+
const customPredicateResult = await this.info.operationName({
|
|
343
|
+
request: args.request,
|
|
344
|
+
...this.extendResolverArgs({
|
|
345
|
+
request: args.request,
|
|
346
|
+
parsedResult: args.parsedResult
|
|
347
|
+
})
|
|
348
|
+
});
|
|
349
|
+
/**
|
|
350
|
+
* @note Keep the { matches } signature in case we decide to support path parameters
|
|
351
|
+
* in GraphQL handlers. If that happens, the custom predicate would have to be moved
|
|
352
|
+
* to the parsing phase, the same as we have for the HttpHandler, and the user will
|
|
353
|
+
* have a possibility to return parsed path parameters from the custom predicate.
|
|
354
|
+
*/
|
|
355
|
+
return typeof customPredicateResult === "boolean" ? customPredicateResult : customPredicateResult.matches;
|
|
356
|
+
}
|
|
357
|
+
if (this.info.operationName instanceof RegExp) return this.info.operationName.test(args.parsedResult.operationName || "");
|
|
358
|
+
return args.parsedResult.operationName === this.info.operationName;
|
|
359
|
+
}
|
|
360
|
+
extendResolverArgs(args) {
|
|
361
|
+
return {
|
|
362
|
+
query: args.parsedResult.query || "",
|
|
363
|
+
operationType: args.parsedResult.operationType,
|
|
364
|
+
operationName: args.parsedResult.operationName || "",
|
|
365
|
+
variables: args.parsedResult.variables || {},
|
|
366
|
+
cookies: args.parsedResult.cookies
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
async log(args) {
|
|
370
|
+
const loggedRequest = await serializeRequest(args.request);
|
|
371
|
+
const loggedResponse = await serializeResponse(args.response);
|
|
372
|
+
const statusColor = getStatusCodeColor(loggedResponse.status);
|
|
373
|
+
const requestInfo = args.parsedResult.operationName ? `${args.parsedResult.operationType} ${args.parsedResult.operationName}` : `anonymous ${args.parsedResult.operationType}`;
|
|
374
|
+
console.groupCollapsed(devUtils.formatMessage(`${getTimestamp()} ${requestInfo} (%c${loggedResponse.status} ${loggedResponse.statusText}%c)`), `color:${statusColor}`, "color:inherit");
|
|
375
|
+
console.log("Request:", loggedRequest);
|
|
376
|
+
console.log("Handler:", this);
|
|
377
|
+
console.log("Response:", loggedResponse);
|
|
378
|
+
console.groupEnd();
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/graphql/graphql-subscription-event.ts
|
|
383
|
+
/**
|
|
384
|
+
* Emitted when a GraphQL subscription is established over an
|
|
385
|
+
* intercepted WebSocket connection (i.e. matched by a subscription
|
|
386
|
+
* handler and resolved).
|
|
387
|
+
*
|
|
388
|
+
* @note The event is referenced by the WebSocket frame event map so
|
|
389
|
+
* the life-cycle event emitters derived from it (e.g. `server.events`)
|
|
390
|
+
* are typed correctly. It lives in its own module so the emitting
|
|
391
|
+
* `msw/graphql` module doesn't pull the entire frame graph, and the
|
|
392
|
+
* core stays free of the `graphql` dependency (the event carries
|
|
393
|
+
* plain data only).
|
|
394
|
+
*/
|
|
395
|
+
var GraphQLSubscriptionEvent = class extends TypedEvent {
|
|
396
|
+
operationName;
|
|
397
|
+
query;
|
|
398
|
+
variables;
|
|
399
|
+
request;
|
|
400
|
+
constructor(init) {
|
|
401
|
+
super("graphql:subscription");
|
|
402
|
+
this.operationName = init.operationName;
|
|
403
|
+
this.query = init.query;
|
|
404
|
+
this.variables = init.variables;
|
|
405
|
+
this.request = init.request;
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region src/graphql/graphql-subscription.ts
|
|
410
|
+
function createInitMessage(payload) {
|
|
411
|
+
return JSON.stringify({
|
|
412
|
+
type: "connection_init",
|
|
413
|
+
payload
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
function createAcknowledgeMessage() {
|
|
417
|
+
return JSON.stringify({ type: "connection_ack" });
|
|
418
|
+
}
|
|
419
|
+
function createNextMessage(args) {
|
|
420
|
+
return JSON.stringify({
|
|
421
|
+
id: args.id,
|
|
422
|
+
type: "next",
|
|
423
|
+
payload: args.payload
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
function createErrorMessage(args) {
|
|
427
|
+
return JSON.stringify({
|
|
428
|
+
id: args.id,
|
|
429
|
+
type: "error",
|
|
430
|
+
payload: args.payload
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
function createCompleteMessage(args) {
|
|
434
|
+
return JSON.stringify({
|
|
435
|
+
id: args.id,
|
|
436
|
+
type: "complete"
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
function createPongMessage() {
|
|
440
|
+
return JSON.stringify({ type: "pong" });
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Construct a request representing the WebSocket upgrade of the given
|
|
444
|
+
* connection. GraphQL subscriptions have no request of their own, so
|
|
445
|
+
* this describes the connection they are multiplexed over.
|
|
446
|
+
*/
|
|
447
|
+
function createUpgradeRequest(url) {
|
|
448
|
+
return new Request(url, { headers: {
|
|
449
|
+
connection: "upgrade",
|
|
450
|
+
upgrade: "websocket"
|
|
451
|
+
} });
|
|
452
|
+
}
|
|
453
|
+
function parseGraphQLWebSocketMessage(data) {
|
|
454
|
+
if (typeof data !== "string") return;
|
|
455
|
+
const message = jsonParse(data);
|
|
456
|
+
if (!message || typeof message.type !== "string") return;
|
|
457
|
+
return message;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Connect to the original server and initialize the `graphql-transport-ws`
|
|
461
|
+
* session for the given connection, at most once.
|
|
462
|
+
*
|
|
463
|
+
* @note The server connection is shared by every subscription of this
|
|
464
|
+
* client. Initializing it more than once makes a compliant GraphQL server
|
|
465
|
+
* close it ("Too many initialisation requests").
|
|
466
|
+
*/
|
|
467
|
+
function ensureUpstreamSession(connection) {
|
|
468
|
+
if (connection.upstreamSession) return connection.upstreamSession;
|
|
469
|
+
const { server } = connection;
|
|
470
|
+
connection.upstreamSession = new Promise((resolve) => {
|
|
471
|
+
server.addEventListener("message", (event) => {
|
|
472
|
+
if (parseGraphQLWebSocketMessage(event.data)?.type === "connection_ack") {
|
|
473
|
+
event.preventDefault();
|
|
474
|
+
resolve();
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
server.addEventListener("open", () => {
|
|
478
|
+
server.send(createInitMessage(connection.connectionParams));
|
|
479
|
+
}, { once: true });
|
|
480
|
+
server.connect();
|
|
481
|
+
});
|
|
482
|
+
return connection.upstreamSession;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* The `graphql-transport-ws` sessions of the intercepted WebSocket
|
|
486
|
+
* connections, keyed by the client id.
|
|
487
|
+
*
|
|
488
|
+
* @note This registry is module-level, and not per-transport, on purpose.
|
|
489
|
+
* Multiple `graphql.link()` calls to the same endpoint create multiple
|
|
490
|
+
* transports, and all of them must share a single session per connection.
|
|
491
|
+
* Otherwise, each transport binds its own protocol listeners to the same
|
|
492
|
+
* client, which makes it receive duplicate `connection_ack`/`pong` frames
|
|
493
|
+
* and resolves matching subscription handlers more than once.
|
|
494
|
+
*/
|
|
495
|
+
const connections = /* @__PURE__ */ new Map();
|
|
496
|
+
/**
|
|
497
|
+
* The WebSocket protocol implemented by the subscription transport.
|
|
498
|
+
* @see https://github.com/graphql/graphql-over-http/blob/main/rfcs/GraphQLOverWebSocket.md
|
|
499
|
+
*/
|
|
500
|
+
const GRAPHQL_WEBSOCKET_SUBPROTOCOL = "graphql-transport-ws";
|
|
501
|
+
function includesGraphQLProtocol(protocols) {
|
|
502
|
+
if (protocols == null) return false;
|
|
503
|
+
return (typeof protocols === "string" ? protocols.split(",") : protocols).some((protocol) => {
|
|
504
|
+
return protocol.trim() === GRAPHQL_WEBSOCKET_SUBPROTOCOL;
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* A WebSocket handler that only matches connections that requested the
|
|
509
|
+
* `graphql-transport-ws` protocol. Connections without it (e.g.
|
|
510
|
+
* arbitrary non-GraphQL WebSockets whose URL matched a permissive
|
|
511
|
+
* endpoint like a wildcard link) are left unhandled so they follow the
|
|
512
|
+
* regular unhandled connection flow (warnings, passthrough).
|
|
513
|
+
*/
|
|
514
|
+
var GraphQLWebSocketHandler = class extends WebSocketHandler {
|
|
515
|
+
async run(connection, resolutionContext) {
|
|
516
|
+
if (!includesGraphQLProtocol(connection.info.protocols)) return null;
|
|
517
|
+
return super.run(connection, resolutionContext);
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
/**
|
|
521
|
+
* A WebSocket handler implementing the `graphql-transport-ws` protocol
|
|
522
|
+
* session for a single GraphQL endpoint. One transport is shared across
|
|
523
|
+
* all subscription handlers created from the same `graphql.link()` call
|
|
524
|
+
* (attached to each of them as a sibling handler).
|
|
525
|
+
*
|
|
526
|
+
* The transport owns the protocol/session concerns: connection
|
|
527
|
+
* acknowledgement, keep-alive, the per-connection registry of active
|
|
528
|
+
* subscriptions, and dispatching parsed `subscribe` operations to the
|
|
529
|
+
* matching subscription handler.
|
|
530
|
+
*/
|
|
531
|
+
var GraphQLSubscriptionTransportHandler = class extends GraphQLWebSocketHandler {
|
|
532
|
+
/**
|
|
533
|
+
* Register the given handler as a subscriber to the GraphQL
|
|
534
|
+
* subscriptions on the given WebSocket connection. Subscribers are
|
|
535
|
+
* dispatched in registration order, which follows the handlers
|
|
536
|
+
* resolution order (runtime handlers take precedence).
|
|
537
|
+
*/
|
|
538
|
+
subscribe(connection, handler, subscriber) {
|
|
539
|
+
this.#getOrCreateConnection(connection).subscribers.set(handler, {
|
|
540
|
+
transport: this,
|
|
541
|
+
subscriber
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
getConnection(clientId) {
|
|
545
|
+
return connections.get(clientId);
|
|
546
|
+
}
|
|
547
|
+
async run(connection, resolutionContext) {
|
|
548
|
+
const handlerConnection = await super.run(connection, resolutionContext);
|
|
549
|
+
if (handlerConnection) {
|
|
550
|
+
const transportConnection = this.#getOrCreateConnection(handlerConnection);
|
|
551
|
+
if (resolutionContext?.events) transportConnection.events = resolutionContext.events;
|
|
552
|
+
}
|
|
553
|
+
return handlerConnection;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* End the given subscription without notifying the client. Used when
|
|
557
|
+
* the subscription has already been terminated over the wire (e.g. the
|
|
558
|
+
* original server completed it and that frame reached the client).
|
|
559
|
+
*/
|
|
560
|
+
endSubscription(args) {
|
|
561
|
+
const connection = connections.get(args.clientId);
|
|
562
|
+
if (connection) this.#endSubscription(connection, args.subscriptionId);
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Schedule a cleanup to run once the given subscription ends.
|
|
566
|
+
*
|
|
567
|
+
* @note If the subscription has already ended by the time this is
|
|
568
|
+
* called, the cleanup runs immediately. The resolver can no longer
|
|
569
|
+
* affect that subscription, so there is nothing left to wait for.
|
|
570
|
+
*/
|
|
571
|
+
finalize(args) {
|
|
572
|
+
const cleanups = connections.get(args.clientId)?.subscriptions.get(args.subscriptionId);
|
|
573
|
+
if (cleanups) {
|
|
574
|
+
cleanups.push(args.cleanup);
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
this.#exhaustCleanups([args.cleanup]);
|
|
578
|
+
}
|
|
579
|
+
async #endAllSubscriptions(connection) {
|
|
580
|
+
const pendingCleanups = [];
|
|
581
|
+
for (const subscriptionId of connection.subscriptions.keys()) pendingCleanups.push(this.#endSubscription(connection, subscriptionId));
|
|
582
|
+
await Promise.all(pendingCleanups);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* End the given subscription and run the cleanups scheduled for it.
|
|
586
|
+
*
|
|
587
|
+
* This is the single exit point for every way a subscription can end:
|
|
588
|
+
* completed by the mock, by the client, or by the original server;
|
|
589
|
+
* terminated with errors; dropped when the client disconnects; or
|
|
590
|
+
* detached from its resolver when the handlers are reset. Ending an
|
|
591
|
+
* already-ended subscription is a no-op, so the cleanups are
|
|
592
|
+
* guaranteed to run at most once.
|
|
593
|
+
*/
|
|
594
|
+
#endSubscription(connection, subscriptionId) {
|
|
595
|
+
const cleanups = connection.subscriptions.get(subscriptionId);
|
|
596
|
+
if (!cleanups) return Promise.resolve();
|
|
597
|
+
connection.subscriptions.delete(subscriptionId);
|
|
598
|
+
return this.#exhaustCleanups(cleanups);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Run the given cleanups as LIFO, consistently with `finalize()` in
|
|
602
|
+
* the request handlers. Cleanups are detached from the subscription
|
|
603
|
+
* life-cycle: nothing awaits them, so this must never reject.
|
|
604
|
+
*/
|
|
605
|
+
async #exhaustCleanups(cleanups) {
|
|
606
|
+
const errors = [];
|
|
607
|
+
for (let index = cleanups.length - 1; index >= 0; index--) try {
|
|
608
|
+
await cleanups[index]();
|
|
609
|
+
} catch (error) {
|
|
610
|
+
if (error instanceof Error) errors.push(error);
|
|
611
|
+
}
|
|
612
|
+
if (errors.length > 0) devUtils.error("Failed to execute the cleanup for a GraphQL subscription to \"%s\". Please see the original error below.", this.url.toString(), new AggregateError(errors));
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Send a `next` message with the given payload to the subscription.
|
|
616
|
+
*/
|
|
617
|
+
publish(args) {
|
|
618
|
+
const connection = this.#getConnectionForSubscription({
|
|
619
|
+
clientId: args.clientId,
|
|
620
|
+
subscriptionId: args.subscriptionId,
|
|
621
|
+
intent: "publish to"
|
|
622
|
+
});
|
|
623
|
+
if (!connection) return;
|
|
624
|
+
connection.client.send(createNextMessage({
|
|
625
|
+
id: args.subscriptionId,
|
|
626
|
+
payload: args.payload
|
|
627
|
+
}));
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Send a terminal `error` message to the subscription and
|
|
631
|
+
* removes it from the registry of active subscriptions.
|
|
632
|
+
*/
|
|
633
|
+
error(args) {
|
|
634
|
+
const connection = this.#getConnectionForSubscription({
|
|
635
|
+
clientId: args.clientId,
|
|
636
|
+
subscriptionId: args.subscriptionId,
|
|
637
|
+
intent: "error"
|
|
638
|
+
});
|
|
639
|
+
if (!connection) return;
|
|
640
|
+
connection.client.send(createErrorMessage({
|
|
641
|
+
id: args.subscriptionId,
|
|
642
|
+
payload: args.errors
|
|
643
|
+
}));
|
|
644
|
+
this.#endSubscription(connection, args.subscriptionId);
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Send a `complete` message to the subscription and removes it
|
|
648
|
+
* from the registry of active subscriptions.
|
|
649
|
+
*/
|
|
650
|
+
complete(args) {
|
|
651
|
+
const connection = this.#getConnectionForSubscription({
|
|
652
|
+
clientId: args.clientId,
|
|
653
|
+
subscriptionId: args.subscriptionId,
|
|
654
|
+
intent: "complete"
|
|
655
|
+
});
|
|
656
|
+
if (!connection) return;
|
|
657
|
+
connection.client.send(createCompleteMessage({ id: args.subscriptionId }));
|
|
658
|
+
this.#endSubscription(connection, args.subscriptionId);
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Drop this transport's subscribers and active subscriptions from the
|
|
662
|
+
* sessions it participates in. The sessions themselves are left intact:
|
|
663
|
+
* they are shared with the other transports of the same connection and
|
|
664
|
+
* own the protocol listeners for as long as the client stays connected.
|
|
665
|
+
*
|
|
666
|
+
* @note This method is invoked automatically when the handlers
|
|
667
|
+
* controller resets the handlers (e.g. `server.resetHandlers()`).
|
|
668
|
+
*/
|
|
669
|
+
reset() {
|
|
670
|
+
for (const connection of connections.values()) {
|
|
671
|
+
let ownsConnection = false;
|
|
672
|
+
for (const [handler, entry] of connection.subscribers) if (entry.transport === this) {
|
|
673
|
+
connection.subscribers.delete(handler);
|
|
674
|
+
ownsConnection = true;
|
|
675
|
+
}
|
|
676
|
+
if (ownsConnection) this.#endAllSubscriptions(connection);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Forget the sessions of this transport, ending their subscriptions.
|
|
681
|
+
* @note This method is invoked automatically when the network is
|
|
682
|
+
* disabled (e.g. `server.close()`).
|
|
683
|
+
*/
|
|
684
|
+
dispose() {
|
|
685
|
+
const pendingCleanups = [];
|
|
686
|
+
for (const [clientId, connection] of connections) {
|
|
687
|
+
for (const [handler, entry] of connection.subscribers) if (entry.transport === this) connection.subscribers.delete(handler);
|
|
688
|
+
if (connection.subscribers.size === 0) {
|
|
689
|
+
pendingCleanups.push(this.#endAllSubscriptions(connection));
|
|
690
|
+
connections.delete(clientId);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
if (pendingCleanups.length > 0) return Promise.all(pendingCleanups).then(() => {});
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* @note The transport is the sole owner of logging for GraphQL
|
|
697
|
+
* subscription connections. It logs parsed `graphql-transport-ws`
|
|
698
|
+
* frames instead of raw WebSocket messages.
|
|
699
|
+
*/
|
|
700
|
+
log(connection) {
|
|
701
|
+
return attachGraphQLSubscriptionLogger(connection);
|
|
702
|
+
}
|
|
703
|
+
[kConnect](connection) {
|
|
704
|
+
this.#getOrCreateConnection(connection);
|
|
705
|
+
return true;
|
|
706
|
+
}
|
|
707
|
+
#getOrCreateConnection(connection) {
|
|
708
|
+
const { client } = connection;
|
|
709
|
+
const existingConnection = connections.get(client.id);
|
|
710
|
+
if (existingConnection) return existingConnection;
|
|
711
|
+
const transportConnection = {
|
|
712
|
+
client: connection.client,
|
|
713
|
+
server: connection.server,
|
|
714
|
+
subscribers: /* @__PURE__ */ new Map(),
|
|
715
|
+
subscriptions: /* @__PURE__ */ new Map()
|
|
716
|
+
};
|
|
717
|
+
connections.set(client.id, transportConnection);
|
|
718
|
+
client.addEventListener("message", (event) => {
|
|
719
|
+
this.#handleClientMessage(client.id, event.data);
|
|
720
|
+
});
|
|
721
|
+
client.addEventListener("close", () => {
|
|
722
|
+
this.#endAllSubscriptions(transportConnection);
|
|
723
|
+
connections.delete(client.id);
|
|
724
|
+
});
|
|
725
|
+
return transportConnection;
|
|
726
|
+
}
|
|
727
|
+
#getConnectionForSubscription(args) {
|
|
728
|
+
const connection = connections.get(args.clientId);
|
|
729
|
+
if (!connection || !connection.subscriptions.has(args.subscriptionId)) {
|
|
730
|
+
devUtils.warn("Failed to %s the GraphQL subscription \"%s\": the subscription is no longer active.", args.intent, args.subscriptionId);
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
return connection;
|
|
734
|
+
}
|
|
735
|
+
#handleClientMessage(clientId, data) {
|
|
736
|
+
const connection = connections.get(clientId);
|
|
737
|
+
if (!connection) return;
|
|
738
|
+
const message = parseGraphQLWebSocketMessage(data);
|
|
739
|
+
if (!message) return;
|
|
740
|
+
switch (message.type) {
|
|
741
|
+
case "connection_init":
|
|
742
|
+
connection.connectionParams = message.payload;
|
|
743
|
+
connection.client.send(createAcknowledgeMessage());
|
|
744
|
+
break;
|
|
745
|
+
case "ping":
|
|
746
|
+
connection.client.send(createPongMessage());
|
|
747
|
+
break;
|
|
748
|
+
case "subscribe":
|
|
749
|
+
this.#handleSubscribeMessage(connection, message);
|
|
750
|
+
break;
|
|
751
|
+
case "complete": this.#endSubscription(connection, message.id);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
#handleSubscribeMessage(connection, message) {
|
|
755
|
+
let node;
|
|
756
|
+
try {
|
|
757
|
+
node = parseDocumentNode(parse(message.payload.query), message.payload.operationName);
|
|
758
|
+
} catch (error) {
|
|
759
|
+
devUtils.warn("Failed to intercept a GraphQL subscription to \"%s\": the subscription query is not a valid GraphQL document.\n\n%s", toPublicUrl(connection.client.url), error);
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
if (node.operationType !== OperationTypeNode.SUBSCRIPTION) {
|
|
763
|
+
devUtils.warn("Intercepted a GraphQL %s \"%s\" over WebSocket: only subscription operations are supported over the WebSocket transport.", node.operationType, node.operationName || "(anonymous)");
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
connection.subscriptions.set(message.id, []);
|
|
767
|
+
for (const { subscriber } of connection.subscribers.values()) if (subscriber({
|
|
768
|
+
node,
|
|
769
|
+
message
|
|
770
|
+
})) {
|
|
771
|
+
this.#emitSubscriptionEvent(connection, node, message);
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
devUtils.warn("Intercepted a GraphQL subscription \"%s\" to \"%s\" that has no matching subscription handler. If you wish to mock this subscription, create a subscription handler for it.", node.operationName || "(anonymous)", toPublicUrl(connection.client.url));
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Emit the "graphql:subscription" life-cycle event on the network.
|
|
778
|
+
* The event is emitted once the subscription has been established:
|
|
779
|
+
* matched by a subscription handler and resolved.
|
|
780
|
+
*/
|
|
781
|
+
#emitSubscriptionEvent(connection, node, message) {
|
|
782
|
+
if (!connection.events || !node.operationName) return;
|
|
783
|
+
connection.events.emit(new GraphQLSubscriptionEvent({
|
|
784
|
+
operationName: node.operationName,
|
|
785
|
+
query: message.payload.query,
|
|
786
|
+
variables: { ...message.payload.variables },
|
|
787
|
+
request: createUpgradeRequest(connection.client.url)
|
|
788
|
+
}));
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
/**
|
|
792
|
+
* A WebSocket handler intercepting GraphQL subscriptions by their
|
|
793
|
+
* operation name. Matching and resolution are delegated to it by the
|
|
794
|
+
* subscription transport (its sibling handler) so the first matching
|
|
795
|
+
* handler wins, respecting runtime handler overrides.
|
|
796
|
+
*/
|
|
797
|
+
var GraphQLSubscriptionHandler = class extends GraphQLWebSocketHandler {
|
|
798
|
+
info;
|
|
799
|
+
isUsed;
|
|
800
|
+
#operationName;
|
|
801
|
+
#transport;
|
|
802
|
+
#resolver;
|
|
803
|
+
#options;
|
|
804
|
+
constructor(args) {
|
|
805
|
+
super(args.url);
|
|
806
|
+
this.info = GraphQLHandler.parseGraphQLRequestInfo({
|
|
807
|
+
operationType: OperationTypeNode.SUBSCRIPTION,
|
|
808
|
+
predicate: args.operationName,
|
|
809
|
+
url: args.url
|
|
810
|
+
});
|
|
811
|
+
const { operationName } = this.info;
|
|
812
|
+
invariant(typeof operationName !== "function" && !isDocumentNode(operationName), "Failed to create a GraphQL subscription handler: custom predicates are not supported for subscriptions");
|
|
813
|
+
this.#operationName = operationName;
|
|
814
|
+
this.#transport = args.transport;
|
|
815
|
+
this.#resolver = args.resolver;
|
|
816
|
+
this.#options = args.options || {};
|
|
817
|
+
this.isUsed = false;
|
|
818
|
+
}
|
|
819
|
+
reset() {
|
|
820
|
+
this.isUsed = false;
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* @note Individual subscription handlers stay silent. The subscription
|
|
824
|
+
* transport owns the GraphQL-aware logging for the entire connection
|
|
825
|
+
* (a logger is attached once per matching handler otherwise).
|
|
826
|
+
*/
|
|
827
|
+
log() {
|
|
828
|
+
return function detachLogger() {};
|
|
829
|
+
}
|
|
830
|
+
[kConnect](connection) {
|
|
831
|
+
this.#transport.subscribe(connection, this, (args) => {
|
|
832
|
+
return this.#handleSubscribe(connection, args);
|
|
833
|
+
});
|
|
834
|
+
return true;
|
|
835
|
+
}
|
|
836
|
+
#handleSubscribe(connection, args) {
|
|
837
|
+
if (this.#options.once && this.isUsed) return false;
|
|
838
|
+
const { operationName } = args.node;
|
|
839
|
+
if (!operationName || !this.#matchesOperationName(operationName)) return false;
|
|
840
|
+
this.isUsed = true;
|
|
841
|
+
const subscription = new GraphQLSubscription({
|
|
842
|
+
message: args.message,
|
|
843
|
+
clientId: connection.client.id,
|
|
844
|
+
transport: this.#transport
|
|
845
|
+
});
|
|
846
|
+
this.#resolver({
|
|
847
|
+
params: connection.params,
|
|
848
|
+
operationName,
|
|
849
|
+
subscription,
|
|
850
|
+
request: createUpgradeRequest(connection.client.url),
|
|
851
|
+
finalize: (cleanup) => {
|
|
852
|
+
this.#transport.finalize({
|
|
853
|
+
clientId: connection.client.id,
|
|
854
|
+
subscriptionId: subscription.id,
|
|
855
|
+
cleanup
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
});
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
#matchesOperationName(operationName) {
|
|
862
|
+
if (this.#operationName instanceof RegExp) return this.#operationName.test(operationName);
|
|
863
|
+
return this.#operationName === operationName;
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
/**
|
|
867
|
+
* Representation of the intercepted GraphQL subscription.
|
|
868
|
+
*/
|
|
869
|
+
var GraphQLSubscription = class {
|
|
870
|
+
id;
|
|
871
|
+
query;
|
|
872
|
+
variables;
|
|
873
|
+
extensions;
|
|
874
|
+
#message;
|
|
875
|
+
#clientId;
|
|
876
|
+
#transport;
|
|
877
|
+
constructor(args) {
|
|
878
|
+
this.id = args.message.id;
|
|
879
|
+
this.query = args.message.payload.query;
|
|
880
|
+
this.variables = args.message.payload.variables || {};
|
|
881
|
+
this.extensions = args.message.payload.extensions;
|
|
882
|
+
this.#message = args.message;
|
|
883
|
+
this.#clientId = args.clientId;
|
|
884
|
+
this.#transport = args.transport;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Publish an execution result to the subscribed client.
|
|
888
|
+
*
|
|
889
|
+
* @example
|
|
890
|
+
* subscription.publish({
|
|
891
|
+
* data: {
|
|
892
|
+
* postAdded: {
|
|
893
|
+
* id: 'abc-123'
|
|
894
|
+
* }
|
|
895
|
+
* }
|
|
896
|
+
* })
|
|
897
|
+
*/
|
|
898
|
+
publish(payload) {
|
|
899
|
+
this.#transport.publish({
|
|
900
|
+
clientId: this.#clientId,
|
|
901
|
+
subscriptionId: this.id,
|
|
902
|
+
payload
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Use the given `Iterable` or `AsyncIterable` as the source
|
|
907
|
+
* of data for this subscription. Whenever the iterable yields a
|
|
908
|
+
* value, it gets published to this subscription.
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* subscription.from(async function* () {
|
|
912
|
+
* yield { text: 'hello world' }
|
|
913
|
+
* })
|
|
914
|
+
*/
|
|
915
|
+
async from(source) {
|
|
916
|
+
for await (const data of source) this.publish({ data });
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* Terminate this subscription with the given errors.
|
|
920
|
+
*
|
|
921
|
+
* @example
|
|
922
|
+
* subscription.error([{ message: 'Something went wrong' }])
|
|
923
|
+
*/
|
|
924
|
+
error(errors) {
|
|
925
|
+
this.#transport.error({
|
|
926
|
+
clientId: this.#clientId,
|
|
927
|
+
subscriptionId: this.id,
|
|
928
|
+
errors
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Marks this subscription as complete.
|
|
933
|
+
*
|
|
934
|
+
* @example
|
|
935
|
+
* subscription.complete()
|
|
936
|
+
*/
|
|
937
|
+
complete() {
|
|
938
|
+
this.#transport.complete({
|
|
939
|
+
clientId: this.#clientId,
|
|
940
|
+
subscriptionId: this.id
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Perform this GraphQL subscription as-is.
|
|
945
|
+
* This establishes a connection to the actual server, replays
|
|
946
|
+
* the intercepted subscription, and forwards the server payloads
|
|
947
|
+
* to the GraphQL client. You can intercept, modify, or prevent
|
|
948
|
+
* any of the original server messages.
|
|
949
|
+
*
|
|
950
|
+
* @example
|
|
951
|
+
* const postAddedSubscription = subscription.passthrough()
|
|
952
|
+
* postAddedSubscription.addEventListener('next', (event) => {
|
|
953
|
+
* event.preventDefault()
|
|
954
|
+
* event.data.payload.data.postAdded.id = 'mock-id'
|
|
955
|
+
* subscription.publish(event.data.payload)
|
|
956
|
+
* })
|
|
957
|
+
*/
|
|
958
|
+
passthrough() {
|
|
959
|
+
const connection = this.#transport.getConnection(this.#clientId);
|
|
960
|
+
/**
|
|
961
|
+
* @note One can only call this method inside the GraphQL subscription
|
|
962
|
+
* handler. By that point, the WebSocket connection has been established
|
|
963
|
+
* and intercepted so the connection reference is guaranteed.
|
|
964
|
+
*/
|
|
965
|
+
invariant(connection, "Failed to passthrough the GraphQL subscription (\"%s\"): the underlying WebSocket connection is closed", this.query);
|
|
966
|
+
return new GraphQLPassthroughSubscription({
|
|
967
|
+
server: connection.server,
|
|
968
|
+
message: this.#message,
|
|
969
|
+
upstreamSession: ensureUpstreamSession(connection),
|
|
970
|
+
onTerminate: () => {
|
|
971
|
+
this.#transport.endSubscription({
|
|
972
|
+
clientId: this.#clientId,
|
|
973
|
+
subscriptionId: this.id
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
/**
|
|
980
|
+
* Representation of a GraphQL subscription to the actual server.
|
|
981
|
+
* You interface with this object from the client's perspective.
|
|
982
|
+
*/
|
|
983
|
+
var GraphQLPassthroughSubscription = class {
|
|
984
|
+
#server;
|
|
985
|
+
#message;
|
|
986
|
+
#emitter;
|
|
987
|
+
#abortController;
|
|
988
|
+
#onTerminate;
|
|
989
|
+
constructor(args) {
|
|
990
|
+
this.#server = args.server;
|
|
991
|
+
this.#message = args.message;
|
|
992
|
+
this.#onTerminate = args.onTerminate;
|
|
993
|
+
this.#emitter = new Emitter();
|
|
994
|
+
this.#abortController = new AbortController();
|
|
995
|
+
args.upstreamSession.then(() => {
|
|
996
|
+
if (!this.#abortController.signal.aborted) this.#server.send(JSON.stringify(this.#message));
|
|
997
|
+
});
|
|
998
|
+
this.#server.addEventListener("message", (event) => {
|
|
999
|
+
const message = parseGraphQLWebSocketMessage(event.data);
|
|
1000
|
+
if (!message) return;
|
|
1001
|
+
switch (message.type) {
|
|
1002
|
+
case "connection_ack":
|
|
1003
|
+
event.preventDefault();
|
|
1004
|
+
this.#emitter.emit(new TypedEvent("connection_ack"));
|
|
1005
|
+
break;
|
|
1006
|
+
case "next": {
|
|
1007
|
+
if (message.id !== this.#message.id) break;
|
|
1008
|
+
const nextEvent = new TypedEvent("next", { data: message });
|
|
1009
|
+
this.#emitter.emit(nextEvent);
|
|
1010
|
+
if (nextEvent.defaultPrevented) event.preventDefault();
|
|
1011
|
+
break;
|
|
1012
|
+
}
|
|
1013
|
+
case "error": {
|
|
1014
|
+
if (message.id !== this.#message.id) break;
|
|
1015
|
+
const errorEvent = new TypedEvent("error", { data: message });
|
|
1016
|
+
this.#emitter.emit(errorEvent);
|
|
1017
|
+
if (errorEvent.defaultPrevented) {
|
|
1018
|
+
event.preventDefault();
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
this.#onTerminate();
|
|
1022
|
+
break;
|
|
1023
|
+
}
|
|
1024
|
+
case "complete": {
|
|
1025
|
+
if (message.id !== this.#message.id) break;
|
|
1026
|
+
const completeEvent = new TypedEvent("complete", { data: message });
|
|
1027
|
+
this.#emitter.emit(completeEvent);
|
|
1028
|
+
if (completeEvent.defaultPrevented) {
|
|
1029
|
+
event.preventDefault();
|
|
1030
|
+
break;
|
|
1031
|
+
}
|
|
1032
|
+
this.#onTerminate();
|
|
1033
|
+
break;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
}, { signal: this.#abortController.signal });
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Add an event listener to the given GraphQL subscription event.
|
|
1040
|
+
*
|
|
1041
|
+
* @example
|
|
1042
|
+
* const onPostAddedSubscription = subscription.passthrough()
|
|
1043
|
+
* onPostAddedSubscription.addEventListener('next', (event) => {
|
|
1044
|
+
* console.log(event.data)
|
|
1045
|
+
* // { id, payload, ... }
|
|
1046
|
+
* })
|
|
1047
|
+
*/
|
|
1048
|
+
addEventListener(event, listener) {
|
|
1049
|
+
this.#emitter.on(event, listener, { signal: this.#abortController.signal });
|
|
1050
|
+
}
|
|
1051
|
+
/**
|
|
1052
|
+
* Unsubscribe from this passthrough GraphQL subscription.
|
|
1053
|
+
* This stops this subscription on the original server.
|
|
1054
|
+
*
|
|
1055
|
+
* @note Unsubscribing from the original subscription has no
|
|
1056
|
+
* effect on the intercepted `subscription` object.
|
|
1057
|
+
*
|
|
1058
|
+
* @example
|
|
1059
|
+
* const onPostAddedSubscription = subscription.passthrough()
|
|
1060
|
+
* onPostAddedSubscription.unsubscribe()
|
|
1061
|
+
*/
|
|
1062
|
+
unsubscribe() {
|
|
1063
|
+
this.#abortController.abort();
|
|
1064
|
+
this.#emitter.removeAllListeners();
|
|
1065
|
+
/**
|
|
1066
|
+
* @note Complete this subscription instead of closing the server
|
|
1067
|
+
* connection. That connection is shared by every subscription of
|
|
1068
|
+
* this client, and closing it would terminate the unrelated ones.
|
|
1069
|
+
*/
|
|
1070
|
+
this.#server.send(createCompleteMessage({ id: this.#message.id }));
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
function logGraphQLFrame(args) {
|
|
1074
|
+
const timestamp = getTimestamp({ milliseconds: true });
|
|
1075
|
+
if (typeof args.payload === "undefined") {
|
|
1076
|
+
console.log(devUtils.formatMessage(`${timestamp} %c${args.label}%c`), `color:${args.color}`, "color:inherit");
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
console.groupCollapsed(devUtils.formatMessage(`${timestamp} %c${args.label}%c`), `color:${args.color}`, "color:inherit");
|
|
1080
|
+
console.log(args.payload);
|
|
1081
|
+
console.groupEnd();
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Attach a GraphQL-aware logger to the intercepted WebSocket connection.
|
|
1085
|
+
* Unlike the raw WebSocket logger, this logger prints parsed
|
|
1086
|
+
* `graphql-transport-ws` frames relevant to the subscription.
|
|
1087
|
+
*/
|
|
1088
|
+
function attachGraphQLSubscriptionLogger(connection) {
|
|
1089
|
+
const { client } = connection;
|
|
1090
|
+
const abortController = new AbortController();
|
|
1091
|
+
logGraphQLFrame({
|
|
1092
|
+
color: colors.system,
|
|
1093
|
+
label: `GraphQL subscription connection ${toPublicUrl(client.url)}`
|
|
1094
|
+
});
|
|
1095
|
+
client.addEventListener("message", (event) => {
|
|
1096
|
+
const message = parseGraphQLWebSocketMessage(event.data);
|
|
1097
|
+
if (!message) return;
|
|
1098
|
+
switch (message.type) {
|
|
1099
|
+
case "subscribe":
|
|
1100
|
+
logGraphQLFrame({
|
|
1101
|
+
color: colors.outgoing,
|
|
1102
|
+
label: `subscribe (id: ${message.id})`,
|
|
1103
|
+
payload: message.payload
|
|
1104
|
+
});
|
|
1105
|
+
break;
|
|
1106
|
+
case "complete": logGraphQLFrame({
|
|
1107
|
+
color: colors.outgoing,
|
|
1108
|
+
label: `complete (id: ${message.id})`
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
}, { signal: abortController.signal });
|
|
1112
|
+
const originalClientSend = client.send;
|
|
1113
|
+
client.send = new Proxy(client.send, { apply: (target, thisArg, args) => {
|
|
1114
|
+
const [data] = args;
|
|
1115
|
+
const message = parseGraphQLWebSocketMessage(data);
|
|
1116
|
+
if (message) switch (message.type) {
|
|
1117
|
+
case "next":
|
|
1118
|
+
logGraphQLFrame({
|
|
1119
|
+
color: colors.mocked,
|
|
1120
|
+
label: `next (id: ${message.id})`,
|
|
1121
|
+
payload: message.payload
|
|
1122
|
+
});
|
|
1123
|
+
break;
|
|
1124
|
+
case "error":
|
|
1125
|
+
logGraphQLFrame({
|
|
1126
|
+
color: colors.mocked,
|
|
1127
|
+
label: `error (id: ${message.id})`,
|
|
1128
|
+
payload: message.payload
|
|
1129
|
+
});
|
|
1130
|
+
break;
|
|
1131
|
+
case "complete": logGraphQLFrame({
|
|
1132
|
+
color: colors.mocked,
|
|
1133
|
+
label: `complete (id: ${message.id})`
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
return Reflect.apply(target, thisArg, args);
|
|
1137
|
+
} });
|
|
1138
|
+
return function detachLogger() {
|
|
1139
|
+
abortController.abort();
|
|
1140
|
+
client.send = originalClientSend;
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Create a `subscription()` handler factory bound to the given GraphQL
|
|
1145
|
+
* endpoint. All subscription handlers created by the factory share a single
|
|
1146
|
+
* subscription transport and a single WebSocket upgrade handler, both
|
|
1147
|
+
* attached to each handler as siblings.
|
|
1148
|
+
*
|
|
1149
|
+
* @example
|
|
1150
|
+
* const subscription = createGraphQLSubscriptionHandler('https://api.example.com/graphql')
|
|
1151
|
+
* subscription('OnPostAdded', ({ subscription }) => {
|
|
1152
|
+
* subscription.publish({ data: { postAdded: { id: 'abc-123' } } })
|
|
1153
|
+
* })
|
|
1154
|
+
*/
|
|
1155
|
+
function createGraphQLSubscriptionHandler(url) {
|
|
1156
|
+
const webSocketUrl = typeof url === "string" ? url.replace(/^http/, "ws") : url;
|
|
1157
|
+
const transport = new GraphQLSubscriptionTransportHandler(webSocketUrl);
|
|
1158
|
+
const upgradeHandler = http.get(({ request }) => {
|
|
1159
|
+
return request.headers.get("upgrade")?.toLowerCase() === "websocket" && includesGraphQLProtocol(request.headers.get("sec-websocket-protocol")) && matchRequestUrl(new URL(resolveWebSocketUrl(request.url)), webSocketUrl).matches;
|
|
1160
|
+
}, webSocketUpgrade);
|
|
1161
|
+
return (operationName, resolver, options) => {
|
|
1162
|
+
const handler = new GraphQLSubscriptionHandler({
|
|
1163
|
+
url: webSocketUrl,
|
|
1164
|
+
operationName,
|
|
1165
|
+
transport,
|
|
1166
|
+
resolver,
|
|
1167
|
+
options
|
|
1168
|
+
});
|
|
1169
|
+
return attachSiblingHandlers(handler, [transport, upgradeHandler]);
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
//#endregion
|
|
1173
|
+
//#region src/graphql/graphql.ts
|
|
1174
|
+
function createScopedGraphQLHandler(operationType, url) {
|
|
1175
|
+
return (predicate, resolver, options = {}) => {
|
|
1176
|
+
return new GraphQLHandler(operationType, predicate, url, resolver, options);
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
function createGraphQLOperationHandler(url, subscriptionFactory) {
|
|
1180
|
+
/**
|
|
1181
|
+
* @note An explicitly generic function so the subscription sibling
|
|
1182
|
+
* can be created with the same `Query`/`Variables` types as the
|
|
1183
|
+
* operation resolver, without casting its resolver info.
|
|
1184
|
+
*/
|
|
1185
|
+
return (resolver, options) => {
|
|
1186
|
+
const handler = new GraphQLHandler("all", /* @__PURE__ */ new RegExp(".*"), url, resolver, options);
|
|
1187
|
+
if (!subscriptionFactory) return handler;
|
|
1188
|
+
const subscriptionCatchAllHandler = subscriptionFactory(/* @__PURE__ */ new RegExp(".*"), ({ operationName, subscription, request, finalize }) => {
|
|
1189
|
+
/**
|
|
1190
|
+
* @note Subscriptions are resolved imperatively, so the return
|
|
1191
|
+
* value of the resolver is ignored. The request describes the
|
|
1192
|
+
* WebSocket connection this subscription is multiplexed over.
|
|
1193
|
+
*/
|
|
1194
|
+
resolver({
|
|
1195
|
+
operationName,
|
|
1196
|
+
query: subscription.query,
|
|
1197
|
+
variables: subscription.variables,
|
|
1198
|
+
cookies: getAllRequestCookies(request),
|
|
1199
|
+
request,
|
|
1200
|
+
requestId: createRequestId(),
|
|
1201
|
+
finalize
|
|
1202
|
+
});
|
|
1203
|
+
}, options);
|
|
1204
|
+
return attachSiblingHandlers(handler, [subscriptionCatchAllHandler]);
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* A namespace to intercept and mock GraphQL operations
|
|
1209
|
+
*
|
|
1210
|
+
* @example
|
|
1211
|
+
* const api = graphql.link('https://api.example.com/graphql')
|
|
1212
|
+
* api.query('GetUser', resolver)
|
|
1213
|
+
* api.mutation('DeletePost', resolver)
|
|
1214
|
+
*
|
|
1215
|
+
* @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}
|
|
1216
|
+
*/
|
|
1217
|
+
const graphql = {
|
|
1218
|
+
/**
|
|
1219
|
+
* Intercepts GraphQL operations scoped by the given URL.
|
|
1220
|
+
*
|
|
1221
|
+
* @example
|
|
1222
|
+
* const github = graphql.link('https://api.github.com/graphql')
|
|
1223
|
+
* github.query('GetRepo', resolver)
|
|
1224
|
+
*
|
|
1225
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
1226
|
+
*/
|
|
1227
|
+
link(url) {
|
|
1228
|
+
/**
|
|
1229
|
+
* @note Create the subscription handler factory once per link so
|
|
1230
|
+
* the `subscription()` and `operation()` handlers share the same
|
|
1231
|
+
* underlying subscription transport (deduped by reference).
|
|
1232
|
+
*/
|
|
1233
|
+
const subscription = createGraphQLSubscriptionHandler(url);
|
|
1234
|
+
return {
|
|
1235
|
+
operation: createGraphQLOperationHandler(url, subscription),
|
|
1236
|
+
query: createScopedGraphQLHandler("query", url),
|
|
1237
|
+
mutation: createScopedGraphQLHandler("mutation", url),
|
|
1238
|
+
subscription
|
|
1239
|
+
};
|
|
1240
|
+
} };
|
|
1241
|
+
//#endregion
|
|
1242
|
+
export { GraphQLHandler, GraphQLPassthroughSubscription, GraphQLSubscription, GraphQLSubscriptionHandler, createGraphQLSubscriptionHandler, graphql };
|
|
1243
|
+
|
|
1244
|
+
//# sourceMappingURL=index.js.map
|