Odoo GraphQL Subscription using Node, Express JS for Sample
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1 lines
6.9 KiB

{"version":3,"file":"mutation-hoc.js","sourceRoot":"","sources":["../../../src/react/hoc/mutation-hoc.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAGjC,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAO5C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EACL,wBAAwB,EACxB,cAAc,EACd,2BAA2B,EAC3B,WAAW,GACZ,MAAM,gBAAgB,CAAC;AAIxB;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAQ1B,QAAsB,EACtB,gBAKM;IALN,iCAAA,EAAA,qBAKM;IAEN,6EAA6E;IAC7E,IAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,kBAAkB;IAEV,IAAA,KACN,gBAAgB,QADwB,EAAlC,OAAO,mBAAG,wBAAwB,KAAA,EAAE,KAC1C,gBAAgB,MAD0C,EAAhB,KAAK,mBAAG,QAAQ,KAAA,CACzC;IAEnB,IAAI,iBAAiB,GAAG,OAE4C,CAAC;IACrE,IAAI,OAAO,iBAAiB,KAAK,UAAU;QACzC,iBAAiB,GAAG;YAClB,OAAA,OAKC;QALD,CAKC,CAAC;IAEN,OAAO,UACL,gBAAgE;QAEhE,IAAM,kBAAkB,GAAG,UAAG,KAAK,cAAI,cAAc,CAAC,gBAAgB,CAAC,MAAG,CAAC;QAC3E;YAAsB,2BAAgC;YAAtD;;YA2DA,CAAC;YAxDC,wBAAM,GAAN;gBACE,IAAI,KAAK,GAAG,IAAI,CAAC,KAAe,CAAC;gBACjC,IAAM,IAAI,GAAG,iBAAiB,CAAC,KAAK,CAKnC,CAAC;gBAEF,IAAI,gBAAgB,CAAC,OAAO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AC;oBACxD,CAAC;oBAED,OAAO,oBAAC,gBAAgB,eAAK,KAAK,EAAM,UAAU,EAAI,CAAC;gBACzD,CAAC,CACQ,CACZ,CAAC;YACJ,CAAC;YAzDM,mBAAW,GAAG,kBAAkB,CAAC;YACjC,wBAAgB,GAAG,gBAAgB,CAAC;YAyD7C,cAAC;SAAA,AA3DD,CAAsB,WAAW,GA2DhC;QAED,sEAAsE;QACtE,OAAO,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,EAAE,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 { DefaultContext, OperationVariables } from \"../../core/types.js\";\nimport type {\n BaseMutationOptions,\n MutationFunction,\n MutationResult,\n} from \"../types/types.js\";\nimport { Mutation } from \"../components/index.js\";\n\nimport {\n defaultMapPropsToOptions,\n getDisplayName,\n calculateVariablesFromProps,\n GraphQLBase,\n} from \"./hoc-utils.js\";\nimport type { OperationOption, OptionProps, MutateProps } from \"./types.js\";\nimport type { ApolloCache } from \"../../core/index.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 withMutation<\n TProps extends TGraphQLVariables | {} = {},\n TData extends Record<string, any> = {},\n TGraphQLVariables extends OperationVariables = {},\n TChildProps = MutateProps<TData, TGraphQLVariables>,\n TContext extends Record<string, any> = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\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\n const { options = defaultMapPropsToOptions, alias = \"Apollo\" } =\n operationOptions;\n\n let mapPropsToOptions = options as (\n props: any\n ) => BaseMutationOptions<TData, TGraphQLVariables, TContext, TCache>;\n if (typeof mapPropsToOptions !== \"function\")\n mapPropsToOptions = () =>\n options as BaseMutationOptions<\n TData,\n TGraphQLVariables,\n TContext,\n TCache\n >;\n\n return (\n WrappedComponent: ReactTypes.ComponentType<TProps & TChildProps>\n ): ReactTypes.ComponentClass<TProps> => {\n const graphQLDisplayName = `${alias}(${getDisplayName(WrappedComponent)})`;\n class GraphQL extends GraphQLBase<TProps, TChildProps> {\n static displayName = graphQLDisplayName;\n static WrappedComponent = WrappedComponent;\n render() {\n let props = this.props as TProps;\n const opts = mapPropsToOptions(props) as BaseMutationOptions<\n TData,\n TGraphQLVariables,\n TContext,\n TCache\n >;\n\n if (operationOptions.withRef) {\n this.withRef = true;\n props = Object.assign({}, props, {\n ref: this.setWrappedInstance,\n });\n }\n if (!opts.variables && operation.variables.length > 0) {\n opts.variables = calculateVariablesFromProps(\n operation,\n props\n ) as TGraphQLVariables;\n }\n\n return (\n <Mutation ignoreResults {...opts} mutation={document}>\n {/* @ts-expect-error */}\n {(\n mutate: MutationFunction<TData, TGraphQLVariables>,\n { data, ...r }: MutationResult<TData>\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 Mutation component's shape here to replicate that\n // this matches the query HoC\n const result = Object.assign(r, data || {});\n const name = operationOptions.name || \"mutate\";\n const resultName =\n operationOptions.name ? `${name}Result` : \"result\";\n let childProps = {\n [name]: mutate,\n [resultName]: result,\n } as any as TChildProps;\n if (operationOptions.props) {\n const newResult: OptionProps<TProps, TData, TGraphQLVariables> =\n {\n [name]: mutate,\n [resultName]: result,\n ownProps: props,\n };\n childProps = operationOptions.props(newResult) as any;\n }\n\n return <WrappedComponent {...props} {...childProps} />;\n }}\n </Mutation>\n );\n }\n }\n\n // Make sure we preserve any custom statics on the original component.\n return hoistNonReactStatics(GraphQL, WrappedComponent, {});\n };\n}\n"]}