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,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type * as ReactTypes from \"react\";\nimport type { DocumentNode } from \"graphql\";\nimport hoistNonReactStatics from \"hoist-non-react-statics\";\n\nimport { parser } from \"../parser/index.js\";\nimport type { BaseQueryOptions } from \"../types/types.js\";\nimport { Subscription } from \"../components/index.js\";\nimport {\n getDisplayName,\n GraphQLBase,\n calculateVariablesFromProps,\n defaultMapPropsToOptions,\n defaultMapPropsToSkip,\n} from \"./hoc-utils.js\";\nimport type { OperationOption, OptionProps, DataProps } from \"./types.js\";\n\n/**\n * @deprecated\n * Official support for React Apollo higher order components ended in March 2020.\n * This library is still included in the `@apollo/client` package, but it no longer receives feature updates or bug fixes.\n */\nexport function withSubscription<\n TProps extends TGraphQLVariables | {} = {},\n TData extends object = {},\n TGraphQLVariables extends object = {},\n TChildProps extends object = DataProps,\n>(\n document: DocumentNode,\n operationOptions: OperationOption<\n TProps,\n TData,\n TGraphQLVariables,\n TChildProps\n > = {}\n) {\n // this is memoized so if coming from `graphql` there is nearly no extra cost\n const operation = parser(document);\n // extract options\n const {\n options = defaultMapPropsToOptions,\n skip = defaultMapPropsToSkip,\n alias = \"Apollo\",\n shouldResubscribe,\n } = operationOptions;\n\n let mapPropsToOptions = options as (props: any) => BaseQueryOptions;\n if (typeof mapPropsToOptions !== \"function\")\n mapPropsToOptions = () => options as BaseQueryOptions;\n\n let mapPropsToSkip = skip as (props: any) => boolean;\n if (typeof mapPropsToSkip !== \"function\") mapPropsToSkip = () => skip as any;\n\n // allow for advanced referential equality checks\n let lastResultProps: TChildProps | void;\n return (\n WrappedComponent: ReactTypes.ComponentType\n ): ReactTypes.ComponentClass => {\n const graphQLDisplayName = `${alias}(${getDisplayName(WrappedComponent)})`;\n class GraphQL extends GraphQLBase<\n TProps,\n TChildProps,\n { resubscribe: boolean }\n > {\n static displayName = graphQLDisplayName;\n static WrappedComponent = WrappedComponent;\n constructor(props: TProps) {\n super(props);\n this.state = { resubscribe: false };\n }\n\n updateResubscribe(resubscribe: boolean) {\n this.setState({ resubscribe });\n }\n\n componentDidUpdate(prevProps: TProps) {\n const resubscribe = !!(\n shouldResubscribe && shouldResubscribe(prevProps, this.props)\n );\n if (this.state.resubscribe !== resubscribe) {\n this.updateResubscribe(resubscribe);\n }\n }\n\n render() {\n let props = this.props;\n const shouldSkip = mapPropsToSkip(props);\n const opts =\n shouldSkip ? Object.create(null) : mapPropsToOptions(props);\n\n if (!shouldSkip && !opts.variables && operation.variables.length > 0) {\n opts.variables = calculateVariablesFromProps(operation, props);\n }\n return (\n \n {({ data, ...r }: any) => {\n if (operationOptions.withRef) {\n this.withRef = true;\n props = Object.assign({}, props, {\n ref: this.setWrappedInstance,\n });\n }\n // if we have skipped, no reason to manage any reshaping\n if (shouldSkip) {\n return (\n \n );\n }\n\n // the HOC's historically hoisted the data from the execution result\n // up onto the result since it was passed as a nested prop\n // we massage the Query components shape here to replicate that\n const result = Object.assign(r, data || {});\n const name = operationOptions.name || \"data\";\n let childProps = { [name]: result };\n if (operationOptions.props) {\n const newResult: OptionProps =\n {\n [name]: result,\n ownProps: props as TProps,\n };\n lastResultProps = operationOptions.props(\n newResult,\n lastResultProps\n );\n childProps = lastResultProps;\n }\n\n return (\n \n );\n }}\n \n );\n }\n }\n\n // Make sure we preserve any custom statics on the original component.\n return hoistNonReactStatics(GraphQL, WrappedComponent, {});\n };\n}\n"]}