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AAC;qBACH;oBAED,OAAO,QAAQ,CAAC,KAAK,CACnB,IAAI,WAAW,CAAC;wBACd,aAAa,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;qBAChD,CAAC,CACH,CAAC;gBACJ,CAAC;aACF,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACH,oBAAC;AAAD,CAAC,AApCD,CAAmC,UAAU,GAoC5C","sourcesContent":["// This file is adapted from the graphql-ws npm package:\n// https://github.com/enisdenjo/graphql-ws\n//\n// Most of the file comes from that package's README; some other parts (such as\n// isLikeCloseEvent) come from its source.\n//\n// Here's the license of the original code:\n//\n// The MIT License (MIT)\n//\n// Copyright (c) 2020-2021 Denis Badurina\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n\nimport { print } from \"graphql\";\nimport type { Client } from \"graphql-ws\";\n\nimport { ApolloLink, Operation, FetchResult } from \"../core\";\nimport { isNonNullObject, Observable } from \"../../utilities\";\nimport { ApolloError } from \"../../errors\";\n\ninterface LikeCloseEvent {\n /** Returns the WebSocket connection close code provided by the server. */\n readonly code: number;\n /** Returns the WebSocket connection close reason provided by the server. */\n readonly reason: string;\n}\n\nfunction isLikeCloseEvent(val: unknown): val is LikeCloseEvent {\n return isNonNullObject(val) && 'code' in val && 'reason' in val;\n}\n\n\nexport class GraphQLWsLink extends ApolloLink {\n constructor(public readonly client: Client) {\n super();\n }\n\n public request(operation: Operation): Observable<FetchResult> {\n return new Observable((observer) => {\n return this.client.subscribe<FetchResult>(\n { ...operation, query: print(operation.query) },\n {\n next: observer.next.bind(observer),\n complete: observer.complete.bind(observer),\n error: (err) => {\n if (err instanceof Error) {\n return observer.error(err);\n }\n\n if (isLikeCloseEvent(err)) {\n return observer.error(\n // reason will be available on clean closes\n new Error(\n `Socket closed with event ${err.code} ${err.reason || \"\"}`\n )\n );\n }\n\n return observer.error(\n new ApolloError({\n graphQLErrors: Array.isArray(err) ? err : [err],\n })\n );\n },\n }\n );\n });\n }\n}\n"]}
\No newline at end of file