@webiny/app 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9
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/App.d.ts +25 -0
- package/App.js +82 -0
- package/App.js.map +1 -0
- package/AppContainer.d.ts +23 -0
- package/AppContainer.js +6 -0
- package/AppContainer.js.map +1 -0
- package/README.md +7 -15
- package/apollo-client/InMemoryCache.d.ts +3 -2
- package/apollo-client/InMemoryCache.js +16 -77
- package/apollo-client/InMemoryCache.js.map +1 -1
- package/apollo-client/IntrospectionFragmentMatcher.d.ts +11 -0
- package/apollo-client/IntrospectionFragmentMatcher.js +33 -0
- package/apollo-client/IntrospectionFragmentMatcher.js.map +1 -0
- package/components/Image.d.ts +2 -3
- package/components/Image.js +15 -41
- package/components/Image.js.map +1 -1
- package/components/index.d.ts +1 -2
- package/components/index.js +1 -21
- package/config/RouterConfig/Route.d.ts +29 -0
- package/config/RouterConfig/Route.js +28 -0
- package/config/RouterConfig/Route.js.map +1 -0
- package/config/RouterConfig.d.ts +31 -0
- package/config/RouterConfig.js +19 -0
- package/config/RouterConfig.js.map +1 -0
- package/config.d.ts +1 -1
- package/config.js +20 -29
- package/config.js.map +1 -1
- package/contexts/Ui/index.d.ts +4 -8
- package/contexts/Ui/index.js +27 -89
- package/contexts/Ui/index.js.map +1 -1
- package/core/Plugin.d.ts +8 -0
- package/core/Plugin.js +12 -0
- package/core/Plugin.js.map +1 -0
- package/core/Plugins.d.ts +15 -0
- package/core/Plugins.js +21 -0
- package/core/Plugins.js.map +1 -0
- package/core/Provider.d.ts +8 -0
- package/core/Provider.js +10 -0
- package/core/Provider.js.map +1 -0
- package/core/createProvider.d.ts +10 -0
- package/core/createProvider.js +6 -0
- package/core/createProvider.js.map +1 -0
- package/core/createProviderPlugin.d.ts +8 -0
- package/core/createProviderPlugin.js +12 -0
- package/core/createProviderPlugin.js.map +1 -0
- package/errors/AuthenticationErrorEvent.d.ts +9 -0
- package/errors/AuthenticationErrorEvent.js +13 -0
- package/errors/AuthenticationErrorEvent.js.map +1 -0
- package/errors/NetworkErrorEvent.d.ts +15 -0
- package/errors/NetworkErrorEvent.js +13 -0
- package/errors/NetworkErrorEvent.js.map +1 -0
- package/errors/abstractions.d.ts +12 -0
- package/errors/abstractions.js +6 -0
- package/errors/abstractions.js.map +1 -0
- package/errors/index.d.ts +6 -0
- package/errors/index.js +3 -0
- package/exports/admin/env-config.d.ts +2 -0
- package/exports/admin/env-config.js +2 -0
- package/exports/admin/graphql-client.d.ts +1 -0
- package/exports/admin/graphql-client.js +1 -0
- package/exports/admin/local-storage.d.ts +2 -0
- package/exports/admin/local-storage.js +2 -0
- package/exports/admin/router.d.ts +5 -0
- package/exports/admin/router.js +5 -0
- package/exports/admin/security.d.ts +1 -0
- package/exports/admin/security.js +1 -0
- package/exports/admin.d.ts +7 -0
- package/exports/admin.js +7 -0
- package/features/envConfig/EnvConfig.d.ts +7 -0
- package/features/envConfig/EnvConfig.js +16 -0
- package/features/envConfig/EnvConfig.js.map +1 -0
- package/features/envConfig/abstractions.d.ts +28 -0
- package/features/envConfig/abstractions.js +5 -0
- package/features/envConfig/abstractions.js.map +1 -0
- package/features/envConfig/feature.d.ts +17 -0
- package/features/envConfig/feature.js +15 -0
- package/features/envConfig/feature.js.map +1 -0
- package/features/envConfig/index.d.ts +1 -0
- package/features/envConfig/index.js +1 -0
- package/features/eventPublisher/EventPublisher.d.ts +8 -0
- package/features/eventPublisher/EventPublisher.js +19 -0
- package/features/eventPublisher/EventPublisher.js.map +1 -0
- package/features/eventPublisher/abstractions.d.ts +18 -0
- package/features/eventPublisher/abstractions.js +12 -0
- package/features/eventPublisher/abstractions.js.map +1 -0
- package/features/eventPublisher/feature.d.ts +3 -0
- package/features/eventPublisher/feature.js +17 -0
- package/features/eventPublisher/feature.js.map +1 -0
- package/features/eventPublisher/index.d.ts +3 -0
- package/features/eventPublisher/index.js +2 -0
- package/features/graphqlClient/AuthenticationErrorPublishing.d.ts +13 -0
- package/features/graphqlClient/AuthenticationErrorPublishing.js +35 -0
- package/features/graphqlClient/AuthenticationErrorPublishing.js.map +1 -0
- package/features/graphqlClient/BatchingGraphQLClient.d.ts +16 -0
- package/features/graphqlClient/BatchingGraphQLClient.js +118 -0
- package/features/graphqlClient/BatchingGraphQLClient.js.map +1 -0
- package/features/graphqlClient/FetchGraphQLClient.d.ts +7 -0
- package/features/graphqlClient/FetchGraphQLClient.js +51 -0
- package/features/graphqlClient/FetchGraphQLClient.js.map +1 -0
- package/features/graphqlClient/NetworkErrorPublishing.d.ts +14 -0
- package/features/graphqlClient/NetworkErrorPublishing.js +48 -0
- package/features/graphqlClient/NetworkErrorPublishing.js.map +1 -0
- package/features/graphqlClient/RequestValue.d.ts +21 -0
- package/features/graphqlClient/RequestValue.js +46 -0
- package/features/graphqlClient/RequestValue.js.map +1 -0
- package/features/graphqlClient/RetryGraphQLClient.d.ts +18 -0
- package/features/graphqlClient/RetryGraphQLClient.js +45 -0
- package/features/graphqlClient/RetryGraphQLClient.js.map +1 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.d.ts +1 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.js +397 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.js.map +1 -0
- package/features/graphqlClient/abstractions.d.ts +18 -0
- package/features/graphqlClient/abstractions.js +5 -0
- package/features/graphqlClient/abstractions.js.map +1 -0
- package/features/graphqlClient/feature.d.ts +6 -0
- package/features/graphqlClient/feature.js +25 -0
- package/features/graphqlClient/feature.js.map +1 -0
- package/features/graphqlClient/index.d.ts +1 -0
- package/features/graphqlClient/index.js +1 -0
- package/features/graphqlClient/types.d.ts +5 -0
- package/features/graphqlClient/types.js +0 -0
- package/features/localStorage/BrowserLocalStorageGateway.d.ts +9 -0
- package/features/localStorage/BrowserLocalStorageGateway.js +61 -0
- package/features/localStorage/BrowserLocalStorageGateway.js.map +1 -0
- package/features/localStorage/LocalStorage.d.ts +12 -0
- package/features/localStorage/LocalStorage.js +34 -0
- package/features/localStorage/LocalStorage.js.map +1 -0
- package/features/localStorage/LocalStorageRepository.d.ts +20 -0
- package/features/localStorage/LocalStorageRepository.js +82 -0
- package/features/localStorage/LocalStorageRepository.js.map +1 -0
- package/features/localStorage/abstractions.d.ts +48 -0
- package/features/localStorage/abstractions.js +8 -0
- package/features/localStorage/abstractions.js.map +1 -0
- package/features/localStorage/feature.d.ts +12 -0
- package/features/localStorage/feature.js +23 -0
- package/features/localStorage/feature.js.map +1 -0
- package/features/localStorage/index.d.ts +1 -0
- package/features/localStorage/index.js +1 -0
- package/features/mainGraphQLClient/MainGraphQLClient.d.ts +11 -0
- package/features/mainGraphQLClient/MainGraphQLClient.js +27 -0
- package/features/mainGraphQLClient/MainGraphQLClient.js.map +1 -0
- package/features/mainGraphQLClient/abstractions.d.ts +17 -0
- package/features/mainGraphQLClient/abstractions.js +5 -0
- package/features/mainGraphQLClient/abstractions.js.map +1 -0
- package/features/mainGraphQLClient/feature.d.ts +3 -0
- package/features/mainGraphQLClient/feature.js +17 -0
- package/features/mainGraphQLClient/feature.js.map +1 -0
- package/features/mainGraphQLClient/index.d.ts +1 -0
- package/features/mainGraphQLClient/index.js +1 -0
- package/features/router/HistoryRouterGateway.d.ts +22 -0
- package/features/router/HistoryRouterGateway.js +88 -0
- package/features/router/HistoryRouterGateway.js.map +1 -0
- package/features/router/HistoryRouterGateway.test.d.ts +1 -0
- package/features/router/HistoryRouterGateway.test.js +195 -0
- package/features/router/HistoryRouterGateway.test.js.map +1 -0
- package/features/router/Route.d.ts +19 -0
- package/features/router/Route.js +43 -0
- package/features/router/Route.js.map +1 -0
- package/features/router/RouteUrl.d.ts +85 -0
- package/features/router/RouteUrl.js +99 -0
- package/features/router/RouteUrl.js.map +1 -0
- package/features/router/Router.d.ts +45 -0
- package/features/router/Router.js +72 -0
- package/features/router/Router.js.map +1 -0
- package/features/router/RouterPresenter.d.ts +21 -0
- package/features/router/RouterPresenter.js +52 -0
- package/features/router/RouterPresenter.js.map +1 -0
- package/features/router/RouterRepository.d.ts +30 -0
- package/features/router/RouterRepository.js +117 -0
- package/features/router/RouterRepository.js.map +1 -0
- package/features/router/RouterRepository.test.d.ts +1 -0
- package/features/router/RouterRepository.test.js +138 -0
- package/features/router/RouterRepository.test.js.map +1 -0
- package/features/router/abstractions.d.ts +81 -0
- package/features/router/abstractions.js +7 -0
- package/features/router/abstractions.js.map +1 -0
- package/features/router/feature.d.ts +4 -0
- package/features/router/feature.js +19 -0
- package/features/router/feature.js.map +1 -0
- package/features/router/index.d.ts +2 -0
- package/features/router/index.js +1 -0
- package/helpers/InterfaceGenerator/date.d.ts +15 -0
- package/helpers/InterfaceGenerator/date.js +0 -0
- package/helpers/InterfaceGenerator/id.d.ts +23 -0
- package/helpers/InterfaceGenerator/id.js +0 -0
- package/helpers/InterfaceGenerator/identity.d.ts +10 -0
- package/helpers/InterfaceGenerator/identity.js +0 -0
- package/helpers/InterfaceGenerator/index.d.ts +5 -0
- package/helpers/InterfaceGenerator/index.js +0 -0
- package/helpers/InterfaceGenerator/numeric.d.ts +12 -0
- package/helpers/InterfaceGenerator/numeric.js +0 -0
- package/helpers/InterfaceGenerator/truthful.d.ts +7 -0
- package/helpers/InterfaceGenerator/truthful.js +0 -0
- package/hooks/useAutocomplete/index.d.ts +1 -1
- package/hooks/useAutocomplete/index.js +1 -13
- package/hooks/useAutocomplete/useAutocomplete.d.ts +1 -1
- package/hooks/useAutocomplete/useAutocomplete.js +15 -36
- package/hooks/useAutocomplete/useAutocomplete.js.map +1 -1
- package/hooks/useDataList/functions/getData.js +4 -15
- package/hooks/useDataList/functions/getData.js.map +1 -1
- package/hooks/useDataList/functions/getError.js +4 -15
- package/hooks/useDataList/functions/getError.js.map +1 -1
- package/hooks/useDataList/functions/getMeta.js +4 -15
- package/hooks/useDataList/functions/getMeta.js.map +1 -1
- package/hooks/useDataList/functions/index.d.ts +3 -3
- package/hooks/useDataList/functions/index.js +3 -31
- package/hooks/useDataList/functions/searchDataByKey.js +10 -26
- package/hooks/useDataList/functions/searchDataByKey.js.map +1 -1
- package/hooks/useDataList/index.d.ts +1 -1
- package/hooks/useDataList/index.js +1 -13
- package/hooks/useDataList/useDataList.d.ts +2 -3
- package/hooks/useDataList/useDataList.js +139 -205
- package/hooks/useDataList/useDataList.js.map +1 -1
- package/hooks/useDataList/utils/index.d.ts +1 -2
- package/hooks/useDataList/utils/index.js +1 -23
- package/hooks/useDataList/utils/prepareLoadListParams.d.ts +1 -2
- package/hooks/useDataList/utils/prepareLoadListParams.js +26 -45
- package/hooks/useDataList/utils/prepareLoadListParams.js.map +1 -1
- package/hooks/useHandler.js +14 -19
- package/hooks/useHandler.js.map +1 -1
- package/hooks/useHandlers.d.ts +3 -3
- package/hooks/useHandlers.js +19 -28
- package/hooks/useHandlers.js.map +1 -1
- package/hooks/useRegisterLegacyPlugin.d.ts +2 -0
- package/hooks/useRegisterLegacyPlugin.js +12 -0
- package/hooks/useRegisterLegacyPlugin.js.map +1 -0
- package/hooks/useUi.d.ts +1 -1
- package/hooks/useUi.js +5 -15
- package/hooks/useUi.js.map +1 -1
- package/i18n/i18n.js +11 -21
- package/i18n/i18n.js.map +1 -1
- package/i18n/index.d.ts +1 -1
- package/i18n/index.js +1 -15
- package/index.d.ts +25 -4
- package/index.js +23 -37
- package/package.json +38 -38
- package/plugins/AddQuerySelectionPlugin.d.ts +10 -3
- package/plugins/AddQuerySelectionPlugin.js +43 -128
- package/plugins/AddQuerySelectionPlugin.js.map +1 -1
- package/plugins/ApolloCacheObjectIdPlugin.js +15 -51
- package/plugins/ApolloCacheObjectIdPlugin.js.map +1 -1
- package/plugins/ApolloDynamicLink.d.ts +3 -2
- package/plugins/ApolloDynamicLink.js +24 -78
- package/plugins/ApolloDynamicLink.js.map +1 -1
- package/plugins/ApolloLinkPlugin.d.ts +1 -1
- package/plugins/ApolloLinkPlugin.js +21 -61
- package/plugins/ApolloLinkPlugin.js.map +1 -1
- package/plugins/ConsoleLinkPlugin.d.ts +1 -1
- package/plugins/ConsoleLinkPlugin.js +20 -59
- package/plugins/ConsoleLinkPlugin.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.d.ts +8 -13
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +47 -95
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.d.ts +14 -0
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js +27 -0
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.d.ts +2 -0
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js +23 -0
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.d.ts +8 -5
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +68 -20
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/Typography.d.ts +8 -0
- package/plugins/NetworkErrorLinkPlugin/Typography.js +13 -0
- package/plugins/NetworkErrorLinkPlugin/Typography.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/assets/close_24px.js +19 -0
- package/plugins/NetworkErrorLinkPlugin/assets/close_24px.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.d.ts +3 -3
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +13 -36
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin.d.ts +4 -1
- package/plugins/NetworkErrorLinkPlugin.js +51 -63
- package/plugins/NetworkErrorLinkPlugin.js.map +1 -1
- package/plugins/OmitTypenameLinkPlugin.d.ts +1 -1
- package/plugins/OmitTypenameLinkPlugin.js +12 -51
- package/plugins/OmitTypenameLinkPlugin.js.map +1 -1
- package/plugins/TenantHeaderLinkPlugin.d.ts +3 -8
- package/plugins/TenantHeaderLinkPlugin.js +25 -82
- package/plugins/TenantHeaderLinkPlugin.js.map +1 -1
- package/plugins/components/Image.d.ts +6 -0
- package/plugins/components/Image.js +12 -0
- package/plugins/components/Image.js.map +1 -0
- package/plugins/image.d.ts +1 -1
- package/plugins/image.js +97 -175
- package/plugins/image.js.map +1 -1
- package/plugins/index.d.ts +5 -5
- package/plugins/index.js +38 -106
- package/plugins/index.js.map +1 -1
- package/presentation/envConfig/useEnvConfig.d.ts +6 -0
- package/presentation/envConfig/useEnvConfig.js +9 -0
- package/presentation/envConfig/useEnvConfig.js.map +1 -0
- package/presentation/localStorage/index.d.ts +3 -0
- package/presentation/localStorage/index.js +3 -0
- package/presentation/localStorage/useLocalStorage.d.ts +6 -0
- package/presentation/localStorage/useLocalStorage.js +15 -0
- package/presentation/localStorage/useLocalStorage.js.map +1 -0
- package/presentation/localStorage/useLocalStorageValue.d.ts +1 -0
- package/presentation/localStorage/useLocalStorageValue.js +22 -0
- package/presentation/localStorage/useLocalStorageValue.js.map +1 -0
- package/presentation/localStorage/useLocalStorageValues.d.ts +5 -0
- package/presentation/localStorage/useLocalStorageValues.js +32 -0
- package/presentation/localStorage/useLocalStorageValues.js.map +1 -0
- package/presentation/router/RouteElementRegistry.d.ts +14 -0
- package/presentation/router/RouteElementRegistry.js +29 -0
- package/presentation/router/RouteElementRegistry.js.map +1 -0
- package/presentation/router/abstractions.d.ts +13 -0
- package/presentation/router/abstractions.js +5 -0
- package/presentation/router/abstractions.js.map +1 -0
- package/presentation/router/components/Redirect.d.ts +14 -0
- package/presentation/router/components/Redirect.js +13 -0
- package/presentation/router/components/Redirect.js.map +1 -0
- package/presentation/router/components/RouteContent.d.ts +2 -0
- package/presentation/router/components/RouteContent.js +20 -0
- package/presentation/router/components/RouteContent.js.map +1 -0
- package/presentation/router/components/RouteLink.d.ts +50 -0
- package/presentation/router/components/RouteLink.js +17 -0
- package/presentation/router/components/RouteLink.js.map +1 -0
- package/presentation/router/components/SimpleLink.d.ts +44 -0
- package/presentation/router/components/SimpleLink.js +24 -0
- package/presentation/router/components/SimpleLink.js.map +1 -0
- package/presentation/router/hooks/useRoute.d.ts +6 -0
- package/presentation/router/hooks/useRoute.js +22 -0
- package/presentation/router/hooks/useRoute.js.map +1 -0
- package/presentation/router/hooks/useRouter.d.ts +11 -0
- package/presentation/router/hooks/useRouter.js +29 -0
- package/presentation/router/hooks/useRouter.js.map +1 -0
- package/presentation/router/index.d.ts +4 -0
- package/presentation/router/index.js +3 -0
- package/presentation/router/types.d.ts +5 -0
- package/presentation/router/types.js +0 -0
- package/renderApp.d.ts +2 -0
- package/renderApp.js +10 -0
- package/renderApp.js.map +1 -0
- package/router.d.ts +5 -0
- package/router.js +5 -0
- package/rslib-runtime.js +14 -0
- package/rslib-runtime.js.map +1 -0
- package/shared/di/DiContainerProvider.d.ts +8 -0
- package/shared/di/DiContainerProvider.js +13 -0
- package/shared/di/DiContainerProvider.js.map +1 -0
- package/shared/di/createFeature.d.ts +11 -0
- package/shared/di/createFeature.js +10 -0
- package/shared/di/createFeature.js.map +1 -0
- package/shared/di/useFeature.d.ts +2 -0
- package/shared/di/useFeature.js +12 -0
- package/shared/di/useFeature.js.map +1 -0
- package/static/svg/close_24px.33adaadc.svg +1 -0
- package/types.d.ts +30 -30
- package/types.js +0 -13
- package/utils/createGenericContext.d.ts +13 -0
- package/utils/createGenericContext.js +21 -0
- package/utils/createGenericContext.js.map +1 -0
- package/utils/createHashing.d.ts +2 -0
- package/utils/createHashing.js +15 -0
- package/utils/createHashing.js.map +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +2 -0
- package/utils/legacyPluginToReactComponent.d.ts +7 -0
- package/utils/legacyPluginToReactComponent.js +15 -0
- package/utils/legacyPluginToReactComponent.js.map +1 -0
- package/components/Routes.d.ts +0 -2
- package/components/Routes.js +0 -49
- package/components/Routes.js.map +0 -1
- package/components/View.d.ts +0 -8
- package/components/View.js +0 -41
- package/components/View.js.map +0 -1
- package/components/index.js.map +0 -1
- package/hooks/useAutocomplete/index.js.map +0 -1
- package/hooks/useDataList/functions/index.js.map +0 -1
- package/hooks/useDataList/index.js.map +0 -1
- package/hooks/useDataList/utils/index.js.map +0 -1
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.d.ts +0 -14
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js +0 -31
- package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js.map +0 -1
- package/hooks/useDataList/utils/types.d.ts +0 -34
- package/hooks/useDataList/utils/types.js +0 -5
- package/hooks/useDataList/utils/types.js.map +0 -1
- package/i18n/index.js.map +0 -1
- package/index.js.map +0 -1
- package/plugins/LocaleHeaderLinkPlugin.d.ts +0 -15
- package/plugins/LocaleHeaderLinkPlugin.js +0 -77
- package/plugins/LocaleHeaderLinkPlugin.js.map +0 -1
- package/plugins/RoutePlugin.d.ts +0 -12
- package/plugins/RoutePlugin.js +0 -53
- package/plugins/RoutePlugin.js.map +0 -1
- package/plugins/ViewPlugin.d.ts +0 -14
- package/plugins/ViewPlugin.js +0 -58
- package/plugins/ViewPlugin.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { GraphQLClient } from "./abstractions.js";
|
|
2
|
+
import { EnvConfig } from "../envConfig/index.js";
|
|
3
|
+
class RetryGraphQLClientImpl {
|
|
4
|
+
constructor(envConfig, decoratee){
|
|
5
|
+
this.decoratee = decoratee;
|
|
6
|
+
const gqlClientConfig = envConfig.get("graphqlClient");
|
|
7
|
+
this.maxRetries = gqlClientConfig?.retries.maxRetries ?? 3;
|
|
8
|
+
this.baseDelayMs = gqlClientConfig?.retries.delayInMillis ?? 100;
|
|
9
|
+
}
|
|
10
|
+
async execute(params) {
|
|
11
|
+
let lastError;
|
|
12
|
+
for(let attempt = 0; attempt <= this.maxRetries; attempt++)try {
|
|
13
|
+
return await this.decoratee.execute(params);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
lastError = error;
|
|
16
|
+
if (this.isGraphQLError(error) || this.isAuthenticationError(error) || this.isMaintenanceError(error)) throw error;
|
|
17
|
+
if (attempt < this.maxRetries) await this.delay(this.calculateBackoff(attempt));
|
|
18
|
+
}
|
|
19
|
+
throw lastError;
|
|
20
|
+
}
|
|
21
|
+
isGraphQLError(error) {
|
|
22
|
+
return error.message.includes("GraphQL");
|
|
23
|
+
}
|
|
24
|
+
isAuthenticationError(error) {
|
|
25
|
+
return error.code?.includes("Authentication/");
|
|
26
|
+
}
|
|
27
|
+
isMaintenanceError(error) {
|
|
28
|
+
return error.code?.includes("Tenancy/");
|
|
29
|
+
}
|
|
30
|
+
calculateBackoff(attempt) {
|
|
31
|
+
return Math.pow(2, attempt) * this.baseDelayMs;
|
|
32
|
+
}
|
|
33
|
+
delay(ms) {
|
|
34
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const RetryGraphQLClient = GraphQLClient.createDecorator({
|
|
38
|
+
decorator: RetryGraphQLClientImpl,
|
|
39
|
+
dependencies: [
|
|
40
|
+
EnvConfig
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
export { RetryGraphQLClient };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=RetryGraphQLClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/graphqlClient/RetryGraphQLClient.js","sources":["../../../src/features/graphqlClient/RetryGraphQLClient.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/admin\";\nimport { GraphQLClient } from \"./abstractions.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\n\nclass RetryGraphQLClientImpl implements GraphQLClient.Interface {\n private readonly maxRetries: number;\n private readonly baseDelayMs: number;\n\n constructor(\n envConfig: EnvConfig.Interface,\n private decoratee: GraphQLClient.Interface\n ) {\n const gqlClientConfig = envConfig.get(\"graphqlClient\");\n\n this.maxRetries = gqlClientConfig?.retries.maxRetries ?? 3;\n this.baseDelayMs = gqlClientConfig?.retries.delayInMillis ?? 100;\n }\n\n async execute<TResult = any, TVariables = any>(\n params: GraphQLClient.Request<TVariables>\n ): Promise<TResult> {\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt <= this.maxRetries; attempt++) {\n try {\n return await this.decoratee.execute(params);\n } catch (error) {\n lastError = error as Error;\n\n // Don't retry GraphQL errors (business logic errors)\n // Only retry network/infrastructure errors\n if (\n this.isGraphQLError(error as Error) ||\n this.isAuthenticationError(error as BaseError) ||\n this.isMaintenanceError(error as BaseError)\n ) {\n throw error;\n }\n\n // Don't delay after the last attempt\n if (attempt < this.maxRetries) {\n await this.delay(this.calculateBackoff(attempt));\n }\n }\n }\n\n throw lastError!;\n }\n\n private isGraphQLError(error: Error): boolean {\n return error.message.includes(\"GraphQL\");\n }\n\n private isAuthenticationError(error: BaseError): boolean {\n return error.code?.includes(\"Authentication/\");\n }\n\n private isMaintenanceError(error: BaseError): boolean {\n return error.code?.includes(\"Tenancy/\");\n }\n\n private calculateBackoff(attempt: number): number {\n // Exponential backoff: 100ms, 200ms, 400ms, etc.\n return Math.pow(2, attempt) * this.baseDelayMs;\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n}\n\nexport const RetryGraphQLClient = GraphQLClient.createDecorator({\n decorator: RetryGraphQLClientImpl,\n dependencies: [EnvConfig]\n});\n"],"names":["RetryGraphQLClientImpl","envConfig","decoratee","gqlClientConfig","params","lastError","attempt","error","Math","ms","Promise","resolve","setTimeout","RetryGraphQLClient","GraphQLClient","EnvConfig"],"mappings":";;AAIA,MAAMA;IAIF,YACIC,SAA8B,EACtBC,SAAkC,CAC5C;aADUA,SAAS,GAATA;QAER,MAAMC,kBAAkBF,UAAU,GAAG,CAAC;QAEtC,IAAI,CAAC,UAAU,GAAGE,iBAAiB,QAAQ,cAAc;QACzD,IAAI,CAAC,WAAW,GAAGA,iBAAiB,QAAQ,iBAAiB;IACjE;IAEA,MAAM,QACFC,MAAyC,EACzB;QAChB,IAAIC;QAEJ,IAAK,IAAIC,UAAU,GAAGA,WAAW,IAAI,CAAC,UAAU,EAAEA,UAC9C,IAAI;YACA,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACF;QACxC,EAAE,OAAOG,OAAO;YACZF,YAAYE;YAIZ,IACI,IAAI,CAAC,cAAc,CAACA,UACpB,IAAI,CAAC,qBAAqB,CAACA,UAC3B,IAAI,CAAC,kBAAkB,CAACA,QAExB,MAAMA;YAIV,IAAID,UAAU,IAAI,CAAC,UAAU,EACzB,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAACA;QAE/C;QAGJ,MAAMD;IACV;IAEQ,eAAeE,KAAY,EAAW;QAC1C,OAAOA,MAAM,OAAO,CAAC,QAAQ,CAAC;IAClC;IAEQ,sBAAsBA,KAAgB,EAAW;QACrD,OAAOA,MAAM,IAAI,EAAE,SAAS;IAChC;IAEQ,mBAAmBA,KAAgB,EAAW;QAClD,OAAOA,MAAM,IAAI,EAAE,SAAS;IAChC;IAEQ,iBAAiBD,OAAe,EAAU;QAE9C,OAAOE,KAAK,GAAG,CAAC,GAAGF,WAAW,IAAI,CAAC,WAAW;IAClD;IAEQ,MAAMG,EAAU,EAAiB;QACrC,OAAO,IAAIC,QAAQC,CAAAA,UAAWC,WAAWD,SAASF;IACtD;AACJ;AAEO,MAAMI,qBAAqBC,cAAc,eAAe,CAAC;IAC5D,WAAWd;IACX,cAAc;QAACe;KAAU;AAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { Container } from "@webiny/di";
|
|
3
|
+
import { GraphQLClient } from "../abstractions.js";
|
|
4
|
+
import { FetchGraphQLClient } from "../FetchGraphQLClient.js";
|
|
5
|
+
import { BatchingGraphQLClient } from "../BatchingGraphQLClient.js";
|
|
6
|
+
import { RetryGraphQLClient } from "../RetryGraphQLClient.js";
|
|
7
|
+
import { EnvConfig } from "../../envConfig/index.js";
|
|
8
|
+
import { __webpack_require__ } from "../../../rslib-runtime.js";
|
|
9
|
+
describe("GraphQLClient Feature", ()=>{
|
|
10
|
+
let container;
|
|
11
|
+
let mockEnvConfig;
|
|
12
|
+
beforeEach(()=>{
|
|
13
|
+
container = new Container();
|
|
14
|
+
mockEnvConfig = {
|
|
15
|
+
get: vi.fn((key)=>{
|
|
16
|
+
if ("graphqlApiUrl" === key) return "https://api.example.com/graphql";
|
|
17
|
+
})
|
|
18
|
+
};
|
|
19
|
+
container.registerInstance(EnvConfig, mockEnvConfig);
|
|
20
|
+
});
|
|
21
|
+
describe("FetchGraphQLClient", ()=>{
|
|
22
|
+
beforeEach(()=>{
|
|
23
|
+
container.register(FetchGraphQLClient).inSingletonScope();
|
|
24
|
+
});
|
|
25
|
+
it("should execute a query successfully", async ()=>{
|
|
26
|
+
const mockResponse = {
|
|
27
|
+
data: {
|
|
28
|
+
user: {
|
|
29
|
+
id: "1",
|
|
30
|
+
name: "John"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
__webpack_require__.g.fetch = vi.fn().mockResolvedValue({
|
|
35
|
+
status: 200,
|
|
36
|
+
json: async ()=>mockResponse
|
|
37
|
+
});
|
|
38
|
+
const client = container.resolve(GraphQLClient);
|
|
39
|
+
const result = await client.execute({
|
|
40
|
+
endpoint: "https://api.example.com/graphql",
|
|
41
|
+
query: "query GetUser { user { id name } }"
|
|
42
|
+
});
|
|
43
|
+
expect(result).toEqual(mockResponse.data);
|
|
44
|
+
expect(__webpack_require__.g.fetch).toHaveBeenCalledWith("https://api.example.com/graphql", expect.objectContaining({
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": "application/json"
|
|
48
|
+
}
|
|
49
|
+
}));
|
|
50
|
+
});
|
|
51
|
+
it("should execute a mutation successfully", async ()=>{
|
|
52
|
+
const mockResponse = {
|
|
53
|
+
data: {
|
|
54
|
+
createUser: {
|
|
55
|
+
id: "2",
|
|
56
|
+
name: "Jane"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
__webpack_require__.g.fetch = vi.fn().mockResolvedValue({
|
|
61
|
+
status: 200,
|
|
62
|
+
json: async ()=>mockResponse
|
|
63
|
+
});
|
|
64
|
+
const client = container.resolve(GraphQLClient);
|
|
65
|
+
const result = await client.execute({
|
|
66
|
+
endpoint: "https://api.example.com/graphql",
|
|
67
|
+
query: "mutation CreateUser($name: String!) { createUser(name: $name) { id name } }",
|
|
68
|
+
variables: {
|
|
69
|
+
name: "Jane"
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
expect(result).toEqual(mockResponse.data);
|
|
73
|
+
});
|
|
74
|
+
it("should include custom headers", async ()=>{
|
|
75
|
+
const mockResponse = {
|
|
76
|
+
data: {
|
|
77
|
+
user: {
|
|
78
|
+
id: "1"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
__webpack_require__.g.fetch = vi.fn().mockResolvedValue({
|
|
83
|
+
status: 200,
|
|
84
|
+
json: async ()=>mockResponse
|
|
85
|
+
});
|
|
86
|
+
const client = container.resolve(GraphQLClient);
|
|
87
|
+
await client.execute({
|
|
88
|
+
endpoint: "https://api.example.com/graphql",
|
|
89
|
+
query: "query GetUser { user { id } }",
|
|
90
|
+
headers: {
|
|
91
|
+
"x-tenant": "root",
|
|
92
|
+
Authorization: "Bearer token"
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
expect(__webpack_require__.g.fetch).toHaveBeenCalledWith("https://api.example.com/graphql", expect.objectContaining({
|
|
96
|
+
headers: {
|
|
97
|
+
"Content-Type": "application/json",
|
|
98
|
+
"x-tenant": "root",
|
|
99
|
+
Authorization: "Bearer token"
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
});
|
|
103
|
+
it("should throw on network error", async ()=>{
|
|
104
|
+
__webpack_require__.g.fetch = vi.fn().mockRejectedValue(new Error("Network failure"));
|
|
105
|
+
const client = container.resolve(GraphQLClient);
|
|
106
|
+
await expect(client.execute({
|
|
107
|
+
endpoint: "https://api.example.com/graphql",
|
|
108
|
+
query: "query { user { id } }"
|
|
109
|
+
})).rejects.toThrow("Network error: Network failure");
|
|
110
|
+
});
|
|
111
|
+
it("should throw on GraphQL errors", async ()=>{
|
|
112
|
+
const mockResponse = {
|
|
113
|
+
errors: [
|
|
114
|
+
{
|
|
115
|
+
message: "User not found"
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
data: null
|
|
119
|
+
};
|
|
120
|
+
__webpack_require__.g.fetch = vi.fn().mockResolvedValue({
|
|
121
|
+
status: 200,
|
|
122
|
+
json: async ()=>mockResponse
|
|
123
|
+
});
|
|
124
|
+
const client = container.resolve(GraphQLClient);
|
|
125
|
+
await expect(client.execute({
|
|
126
|
+
endpoint: "https://api.example.com/graphql",
|
|
127
|
+
query: "query { user { id } }"
|
|
128
|
+
})).rejects.toThrow("GraphQL errors");
|
|
129
|
+
});
|
|
130
|
+
it("should throw on invalid JSON response", async ()=>{
|
|
131
|
+
__webpack_require__.g.fetch = vi.fn().mockResolvedValue({
|
|
132
|
+
json: async ()=>{
|
|
133
|
+
throw new Error("Invalid JSON");
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const client = container.resolve(GraphQLClient);
|
|
137
|
+
await expect(client.execute({
|
|
138
|
+
endpoint: "https://api.example.com/graphql",
|
|
139
|
+
query: "query { user { id } }"
|
|
140
|
+
})).rejects.toThrow("Failed to parse GraphQL response as JSON");
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
describe("BatchingGraphQLClient", ()=>{
|
|
144
|
+
beforeEach(()=>{
|
|
145
|
+
container.register(FetchGraphQLClient).inSingletonScope();
|
|
146
|
+
container.registerDecorator(BatchingGraphQLClient);
|
|
147
|
+
});
|
|
148
|
+
it("should batch multiple requests within the batch window", async ()=>{
|
|
149
|
+
const mockResponse = [
|
|
150
|
+
{
|
|
151
|
+
data: {
|
|
152
|
+
user: {
|
|
153
|
+
id: "1",
|
|
154
|
+
name: "John"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
data: {
|
|
160
|
+
post: {
|
|
161
|
+
id: "2",
|
|
162
|
+
title: "Hello"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
];
|
|
167
|
+
__webpack_require__.g.fetch = vi.fn().mockResolvedValue({
|
|
168
|
+
json: async ()=>mockResponse
|
|
169
|
+
});
|
|
170
|
+
const client = container.resolve(GraphQLClient);
|
|
171
|
+
const [result1, result2] = await Promise.all([
|
|
172
|
+
client.execute({
|
|
173
|
+
endpoint: "https://api.example.com/graphql",
|
|
174
|
+
query: "query GetUser { user { id name } }"
|
|
175
|
+
}),
|
|
176
|
+
client.execute({
|
|
177
|
+
endpoint: "https://api.example.com/graphql",
|
|
178
|
+
query: "query GetPost { post { id title } }"
|
|
179
|
+
})
|
|
180
|
+
]);
|
|
181
|
+
expect(result1).toEqual(mockResponse[0].data);
|
|
182
|
+
expect(result2).toEqual(mockResponse[1].data);
|
|
183
|
+
expect(__webpack_require__.g.fetch).toHaveBeenCalledTimes(1);
|
|
184
|
+
const callBody = JSON.parse(__webpack_require__.g.fetch.mock.calls[0][1].body);
|
|
185
|
+
expect(callBody).toHaveLength(2);
|
|
186
|
+
});
|
|
187
|
+
it("should execute single request without batching", async ()=>{
|
|
188
|
+
const mockResponse = {
|
|
189
|
+
data: {
|
|
190
|
+
user: {
|
|
191
|
+
id: "1",
|
|
192
|
+
name: "John"
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
__webpack_require__.g.fetch = vi.fn().mockResolvedValue({
|
|
197
|
+
status: 200,
|
|
198
|
+
json: async ()=>mockResponse
|
|
199
|
+
});
|
|
200
|
+
const client = container.resolve(GraphQLClient);
|
|
201
|
+
const result = await client.execute({
|
|
202
|
+
endpoint: "https://api.example.com/graphql",
|
|
203
|
+
query: "query GetUser { user { id name } }"
|
|
204
|
+
});
|
|
205
|
+
expect(result).toEqual(mockResponse.data);
|
|
206
|
+
const callBody = JSON.parse(__webpack_require__.g.fetch.mock.calls[0][1].body);
|
|
207
|
+
expect(callBody).toHaveProperty("query");
|
|
208
|
+
expect(callBody).not.toBeInstanceOf(Array);
|
|
209
|
+
});
|
|
210
|
+
it("should handle mixed queries and mutations in batch", async ()=>{
|
|
211
|
+
const mockResponse = [
|
|
212
|
+
{
|
|
213
|
+
data: {
|
|
214
|
+
user: {
|
|
215
|
+
id: "1"
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
data: {
|
|
221
|
+
createPost: {
|
|
222
|
+
id: "2"
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
];
|
|
227
|
+
__webpack_require__.g.fetch = vi.fn().mockResolvedValue({
|
|
228
|
+
status: 200,
|
|
229
|
+
json: async ()=>mockResponse
|
|
230
|
+
});
|
|
231
|
+
const client = container.resolve(GraphQLClient);
|
|
232
|
+
await Promise.all([
|
|
233
|
+
client.execute({
|
|
234
|
+
endpoint: "https://api.example.com/graphql",
|
|
235
|
+
query: "query { user { id } }"
|
|
236
|
+
}),
|
|
237
|
+
client.execute({
|
|
238
|
+
endpoint: "https://api.example.com/graphql",
|
|
239
|
+
query: "mutation { createPost { id } }"
|
|
240
|
+
})
|
|
241
|
+
]);
|
|
242
|
+
expect(__webpack_require__.g.fetch).toHaveBeenCalledTimes(1);
|
|
243
|
+
const callBody = JSON.parse(__webpack_require__.g.fetch.mock.calls[0][1].body);
|
|
244
|
+
expect(callBody[0]).toHaveProperty("query");
|
|
245
|
+
expect(callBody[1]).toHaveProperty("query");
|
|
246
|
+
});
|
|
247
|
+
it("should reject all requests if batch fails", async ()=>{
|
|
248
|
+
__webpack_require__.g.fetch = vi.fn().mockRejectedValue(new Error("Network error"));
|
|
249
|
+
const client = container.resolve(GraphQLClient);
|
|
250
|
+
const promises = [
|
|
251
|
+
client.execute({
|
|
252
|
+
endpoint: "https://api.example.com/graphql",
|
|
253
|
+
query: "query { user { id } }"
|
|
254
|
+
}),
|
|
255
|
+
client.execute({
|
|
256
|
+
endpoint: "https://api.example.com/graphql",
|
|
257
|
+
query: "query { post { id } }"
|
|
258
|
+
})
|
|
259
|
+
];
|
|
260
|
+
await expect(Promise.all(promises)).rejects.toThrow("Network error");
|
|
261
|
+
});
|
|
262
|
+
it("should handle GraphQL errors in batched operations", async ()=>{
|
|
263
|
+
const mockResponse = [
|
|
264
|
+
{
|
|
265
|
+
data: {
|
|
266
|
+
user: {
|
|
267
|
+
id: "1"
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
errors: [
|
|
273
|
+
{
|
|
274
|
+
message: "Post not found"
|
|
275
|
+
}
|
|
276
|
+
],
|
|
277
|
+
data: null
|
|
278
|
+
}
|
|
279
|
+
];
|
|
280
|
+
__webpack_require__.g.fetch = vi.fn().mockResolvedValue({
|
|
281
|
+
json: async ()=>mockResponse
|
|
282
|
+
});
|
|
283
|
+
const client = container.resolve(GraphQLClient);
|
|
284
|
+
const promises = [
|
|
285
|
+
client.execute({
|
|
286
|
+
endpoint: "https://api.example.com/graphql",
|
|
287
|
+
query: "query { user { id } }"
|
|
288
|
+
}),
|
|
289
|
+
client.execute({
|
|
290
|
+
endpoint: "https://api.example.com/graphql",
|
|
291
|
+
query: "query { post { id } }"
|
|
292
|
+
})
|
|
293
|
+
];
|
|
294
|
+
await expect(Promise.all(promises)).rejects.toThrow("GraphQL errors in operation 1");
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
describe("RetryGraphQLClient", ()=>{
|
|
298
|
+
beforeEach(()=>{
|
|
299
|
+
container.register(FetchGraphQLClient).inSingletonScope();
|
|
300
|
+
container.registerDecorator(RetryGraphQLClient);
|
|
301
|
+
});
|
|
302
|
+
it("should retry on network errors", async ()=>{
|
|
303
|
+
const mockResponse = {
|
|
304
|
+
data: {
|
|
305
|
+
user: {
|
|
306
|
+
id: "1"
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
__webpack_require__.g.fetch = vi.fn().mockRejectedValueOnce(new Error("Network timeout")).mockRejectedValueOnce(new Error("Network timeout")).mockResolvedValueOnce({
|
|
311
|
+
status: 200,
|
|
312
|
+
json: async ()=>mockResponse
|
|
313
|
+
});
|
|
314
|
+
const client = container.resolve(GraphQLClient);
|
|
315
|
+
const result = await client.execute({
|
|
316
|
+
endpoint: "https://api.example.com/graphql",
|
|
317
|
+
query: "query { user { id } }"
|
|
318
|
+
});
|
|
319
|
+
expect(result).toEqual(mockResponse.data);
|
|
320
|
+
expect(__webpack_require__.g.fetch).toHaveBeenCalledTimes(3);
|
|
321
|
+
});
|
|
322
|
+
it("should not retry on GraphQL errors", async ()=>{
|
|
323
|
+
const mockResponse = {
|
|
324
|
+
errors: [
|
|
325
|
+
{
|
|
326
|
+
message: "Unauthorized"
|
|
327
|
+
}
|
|
328
|
+
],
|
|
329
|
+
data: null
|
|
330
|
+
};
|
|
331
|
+
__webpack_require__.g.fetch = vi.fn().mockResolvedValue({
|
|
332
|
+
status: 200,
|
|
333
|
+
json: async ()=>mockResponse
|
|
334
|
+
});
|
|
335
|
+
const client = container.resolve(GraphQLClient);
|
|
336
|
+
await expect(client.execute({
|
|
337
|
+
endpoint: "https://api.example.com/graphql",
|
|
338
|
+
query: "query { user { id } }"
|
|
339
|
+
})).rejects.toThrow("GraphQL errors");
|
|
340
|
+
expect(__webpack_require__.g.fetch).toHaveBeenCalledTimes(1);
|
|
341
|
+
});
|
|
342
|
+
it("should give up after max retries", async ()=>{
|
|
343
|
+
__webpack_require__.g.fetch = vi.fn().mockRejectedValue(new Error("Network error"));
|
|
344
|
+
const client = container.resolve(GraphQLClient);
|
|
345
|
+
await expect(client.execute({
|
|
346
|
+
endpoint: "https://api.example.com/graphql",
|
|
347
|
+
query: "query { user { id } }"
|
|
348
|
+
})).rejects.toThrow("Network error");
|
|
349
|
+
expect(__webpack_require__.g.fetch).toHaveBeenCalledTimes(4);
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
describe("Combined decorators (Retry + Batching)", ()=>{
|
|
353
|
+
beforeEach(()=>{
|
|
354
|
+
container.register(FetchGraphQLClient).inSingletonScope();
|
|
355
|
+
container.registerDecorator(BatchingGraphQLClient);
|
|
356
|
+
container.registerDecorator(RetryGraphQLClient);
|
|
357
|
+
});
|
|
358
|
+
it("should retry batched requests on failure", async ()=>{
|
|
359
|
+
const mockResponse = [
|
|
360
|
+
{
|
|
361
|
+
data: {
|
|
362
|
+
user: {
|
|
363
|
+
id: "1"
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
data: {
|
|
369
|
+
post: {
|
|
370
|
+
id: "2"
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
];
|
|
375
|
+
__webpack_require__.g.fetch = vi.fn().mockRejectedValueOnce(new Error("Network error")).mockResolvedValueOnce({
|
|
376
|
+
status: 200,
|
|
377
|
+
json: async ()=>mockResponse
|
|
378
|
+
});
|
|
379
|
+
const client = container.resolve(GraphQLClient);
|
|
380
|
+
const [result1, result2] = await Promise.all([
|
|
381
|
+
client.execute({
|
|
382
|
+
endpoint: "https://api.example.com/graphql",
|
|
383
|
+
query: "query { user { id } }"
|
|
384
|
+
}),
|
|
385
|
+
client.execute({
|
|
386
|
+
endpoint: "https://api.example.com/graphql",
|
|
387
|
+
query: "query { post { id } }"
|
|
388
|
+
})
|
|
389
|
+
]);
|
|
390
|
+
expect(result1).toEqual(mockResponse[0].data);
|
|
391
|
+
expect(result2).toEqual(mockResponse[1].data);
|
|
392
|
+
expect(__webpack_require__.g.fetch).toHaveBeenCalledTimes(2);
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
//# sourceMappingURL=GraphQLClient.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/graphqlClient/__tests__/GraphQLClient.test.js","sources":["../../../../src/features/graphqlClient/__tests__/GraphQLClient.test.ts"],"sourcesContent":["import { describe, it, expect, vi, beforeEach } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { GraphQLClient } from \"../abstractions.js\";\nimport { FetchGraphQLClient } from \"../FetchGraphQLClient.js\";\nimport { BatchingGraphQLClient } from \"../BatchingGraphQLClient.js\";\nimport { RetryGraphQLClient } from \"../RetryGraphQLClient.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\n\ndescribe(\"GraphQLClient Feature\", () => {\n let container: Container;\n let mockEnvConfig: EnvConfig.Interface;\n\n beforeEach(() => {\n container = new Container();\n\n mockEnvConfig = {\n get: vi.fn((key: string) => {\n if (key === \"graphqlApiUrl\") {\n return \"https://api.example.com/graphql\";\n }\n return undefined;\n })\n } as any;\n\n container.registerInstance(EnvConfig, mockEnvConfig);\n });\n\n describe(\"FetchGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n });\n\n it(\"should execute a query successfully\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" }\n })\n );\n });\n\n it(\"should execute a mutation successfully\", async () => {\n const mockResponse = {\n data: { createUser: { id: \"2\", name: \"Jane\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"mutation CreateUser($name: String!) { createUser(name: $name) { id name } }\",\n variables: { name: \"Jane\" }\n });\n\n expect(result).toEqual(mockResponse.data);\n });\n\n it(\"should include custom headers\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id } }\",\n headers: { \"x-tenant\": \"root\", Authorization: \"Bearer token\" }\n });\n\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-tenant\": \"root\",\n Authorization: \"Bearer token\"\n }\n })\n );\n });\n\n it(\"should throw on network error\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network failure\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Network error: Network failure\");\n });\n\n it(\"should throw on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"User not found\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"GraphQL errors\");\n });\n\n it(\"should throw on invalid JSON response\", async () => {\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => {\n throw new Error(\"Invalid JSON\");\n }\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Failed to parse GraphQL response as JSON\");\n });\n });\n\n describe(\"BatchingGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n });\n\n it(\"should batch multiple requests within the batch window\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\", name: \"John\" } } },\n { data: { post: { id: \"2\", title: \"Hello\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetPost { post { id title } }\"\n })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(1);\n\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveLength(2);\n });\n\n it(\"should execute single request without batching\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n\n // Should use decoratee directly for single request\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveProperty(\"query\");\n expect(callBody).not.toBeInstanceOf(Array);\n });\n\n it(\"should handle mixed queries and mutations in batch\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { data: { createPost: { id: \"2\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"mutation { createPost { id } }\"\n })\n ]);\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody[0]).toHaveProperty(\"query\");\n expect(callBody[1]).toHaveProperty(\"query\");\n });\n\n it(\"should reject all requests if batch fails\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"Network error\");\n });\n\n it(\"should handle GraphQL errors in batched operations\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { errors: [{ message: \"Post not found\" }], data: null }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"GraphQL errors in operation 1\");\n });\n });\n\n describe(\"RetryGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry on network errors\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledTimes(3);\n });\n\n it(\"should not retry on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"Unauthorized\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"GraphQL errors\");\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n });\n\n it(\"should give up after max retries\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Network error\");\n\n // Should try 4 times: initial + 3 retries\n expect(global.fetch).toHaveBeenCalledTimes(4);\n });\n });\n\n describe(\"Combined decorators (Retry + Batching)\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry batched requests on failure\", async () => {\n const mockResponse = [{ data: { user: { id: \"1\" } } }, { data: { post: { id: \"2\" } } }];\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network error\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(2);\n });\n });\n});\n"],"names":["describe","container","mockEnvConfig","beforeEach","Container","vi","key","EnvConfig","FetchGraphQLClient","it","mockResponse","global","client","GraphQLClient","result","expect","Error","BatchingGraphQLClient","result1","result2","Promise","callBody","JSON","Array","promises","RetryGraphQLClient"],"mappings":";;;;;;;;AAQAA,SAAS,yBAAyB;IAC9B,IAAIC;IACJ,IAAIC;IAEJC,WAAW;QACPF,YAAY,IAAIG;QAEhBF,gBAAgB;YACZ,KAAKG,GAAG,EAAE,CAAC,CAACC;gBACR,IAAIA,AAAQ,oBAARA,KACA,OAAO;YAGf;QACJ;QAEAL,UAAU,gBAAgB,CAACM,WAAWL;IAC1C;IAEAF,SAAS,sBAAsB;QAC3BG,WAAW;YACPF,UAAU,QAAQ,CAACO,oBAAoB,gBAAgB;QAC3D;QAEAC,GAAG,uCAAuC;YACtC,MAAMC,eAAe;gBACjB,MAAM;oBAAE,MAAM;wBAAE,IAAI;wBAAK,MAAM;oBAAO;gBAAE;YAC5C;YAEAC,oBAAAA,CAAMA,CAAC,KAAK,GAAGN,GAAG,EAAE,GAAG,iBAAiB,CAAC;gBACrC,QAAQ;gBACR,MAAM,UAAYK;YACtB;YAEA,MAAME,SAASX,UAAU,OAAO,CAACY;YACjC,MAAMC,SAAS,MAAMF,OAAO,OAAO,CAAC;gBAChC,UAAU;gBACV,OAAO;YACX;YAEAG,OAAOD,QAAQ,OAAO,CAACJ,aAAa,IAAI;YACxCK,OAAOJ,oBAAAA,CAAMA,CAAC,KAAK,EAAE,oBAAoB,CACrC,mCACAI,OAAO,gBAAgB,CAAC;gBACpB,QAAQ;gBACR,SAAS;oBAAE,gBAAgB;gBAAmB;YAClD;QAER;QAEAN,GAAG,0CAA0C;YACzC,MAAMC,eAAe;gBACjB,MAAM;oBAAE,YAAY;wBAAE,IAAI;wBAAK,MAAM;oBAAO;gBAAE;Y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ode } from "graphql";
|
|
2
|
+
type IHeaders = Record<string, string | number | undefined>;
|
|
3
|
+
type GraphQLRequest<TVariables = any> = {
|
|
4
|
+
endpoint: string;
|
|
5
|
+
query: DocumentNode | string;
|
|
6
|
+
variables?: TVariables;
|
|
7
|
+
headers?: IHeaders;
|
|
8
|
+
};
|
|
9
|
+
export interface IGraphQLClient {
|
|
10
|
+
execute<TResult = any, TVariables = any>(params: GraphQLRequest<TVariables>): Promise<TResult>;
|
|
11
|
+
}
|
|
12
|
+
export declare const GraphQLClient: import("@webiny/di").Abstraction<IGraphQLClient>;
|
|
13
|
+
export declare namespace GraphQLClient {
|
|
14
|
+
type Headers = IHeaders;
|
|
15
|
+
type Interface = IGraphQLClient;
|
|
16
|
+
type Request<TVariables = any> = GraphQLRequest<TVariables>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/graphqlClient/abstractions.js","sources":["../../../src/features/graphqlClient/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { DocumentNode } from \"graphql\";\n\ntype IHeaders = Record<string, string | number | undefined>;\n\ntype GraphQLRequest<TVariables = any> = {\n endpoint: string;\n query: DocumentNode | string;\n variables?: TVariables;\n headers?: IHeaders;\n};\n\nexport interface IGraphQLClient {\n execute<TResult = any, TVariables = any>(params: GraphQLRequest<TVariables>): Promise<TResult>;\n}\nexport const GraphQLClient = createAbstraction<IGraphQLClient>(\"GraphQLClient\");\n\nexport namespace GraphQLClient {\n export type Headers = IHeaders;\n export type Interface = IGraphQLClient;\n export type Request<TVariables = any> = GraphQLRequest<TVariables>;\n}\n"],"names":["GraphQLClient","createAbstraction"],"mappings":";AAeO,MAAMA,gBAAgBC,kBAAkC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GraphQLClient } from "./abstractions.js";
|
|
2
|
+
import { BatchingGraphQLClient } from "./BatchingGraphQLClient.js";
|
|
3
|
+
import { FetchGraphQLClient } from "./FetchGraphQLClient.js";
|
|
4
|
+
import { createFeature } from "../../shared/di/createFeature.js";
|
|
5
|
+
import { RetryGraphQLClient } from "./RetryGraphQLClient.js";
|
|
6
|
+
import { NetworkErrorPublishing } from "./NetworkErrorPublishing.js";
|
|
7
|
+
import { AuthenticationErrorPublishing } from "./AuthenticationErrorPublishing.js";
|
|
8
|
+
const GraphQLClientFeature = createFeature({
|
|
9
|
+
name: "GraphQLClient",
|
|
10
|
+
register (container, options) {
|
|
11
|
+
container.register(FetchGraphQLClient).inSingletonScope();
|
|
12
|
+
if (options.batching) container.registerDecorator(BatchingGraphQLClient);
|
|
13
|
+
if (options.retry) container.registerDecorator(RetryGraphQLClient);
|
|
14
|
+
container.registerDecorator(NetworkErrorPublishing);
|
|
15
|
+
container.registerDecorator(AuthenticationErrorPublishing);
|
|
16
|
+
},
|
|
17
|
+
resolve (container) {
|
|
18
|
+
return {
|
|
19
|
+
client: container.resolve(GraphQLClient)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
export { GraphQLClientFeature };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/graphqlClient/feature.js","sources":["../../../src/features/graphqlClient/feature.ts"],"sourcesContent":["import { GraphQLClient } from \"./abstractions.js\";\nimport { BatchingGraphQLClient } from \"./BatchingGraphQLClient.js\";\nimport { FetchGraphQLClient } from \"./FetchGraphQLClient.js\";\nimport { createFeature } from \"~/shared/di/createFeature.js\";\nimport { RetryGraphQLClient } from \"./RetryGraphQLClient.js\";\nimport { NetworkErrorPublishing } from \"./NetworkErrorPublishing.js\";\nimport { AuthenticationErrorPublishing } from \"./AuthenticationErrorPublishing.js\";\n\nexport const GraphQLClientFeature = createFeature({\n name: \"GraphQLClient\",\n register(\n container,\n options: {\n batching: boolean;\n retry: boolean;\n }\n ) {\n // Base implementation\n container.register(FetchGraphQLClient).inSingletonScope();\n\n // Optional decorators (order matters: retry wraps batching)\n if (options.batching) {\n container.registerDecorator(BatchingGraphQLClient);\n }\n\n if (options.retry) {\n container.registerDecorator(RetryGraphQLClient);\n }\n\n container.registerDecorator(NetworkErrorPublishing);\n container.registerDecorator(AuthenticationErrorPublishing);\n },\n resolve(container) {\n return {\n client: container.resolve(GraphQLClient)\n };\n }\n});\n"],"names":["GraphQLClientFeature","createFeature","container","options","FetchGraphQLClient","BatchingGraphQLClient","RetryGraphQLClient","NetworkErrorPublishing","AuthenticationErrorPublishing","GraphQLClient"],"mappings":";;;;;;;AAQO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UACIC,SAAS,EACTC,OAGC;QAGDD,UAAU,QAAQ,CAACE,oBAAoB,gBAAgB;QAGvD,IAAID,QAAQ,QAAQ,EAChBD,UAAU,iBAAiB,CAACG;QAGhC,IAAIF,QAAQ,KAAK,EACbD,UAAU,iBAAiB,CAACI;QAGhCJ,UAAU,iBAAiB,CAACK;QAC5BL,UAAU,iBAAiB,CAACM;IAChC;IACA,SAAQN,SAAS;QACb,OAAO;YACH,QAAQA,UAAU,OAAO,CAACO;QAC9B;IACJ;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GraphQLClient } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GraphQLClient } from "./abstractions.js";
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ILocalStorageGateway } from "./abstractions.js";
|
|
2
|
+
export declare class BrowserLocalStorageGateway implements ILocalStorageGateway {
|
|
3
|
+
get<T = string>(key: string): T | null;
|
|
4
|
+
set<T = string>(key: string, value: T): void;
|
|
5
|
+
remove(key: string): void;
|
|
6
|
+
clear(): void;
|
|
7
|
+
getAll(): Record<string, unknown>;
|
|
8
|
+
subscribe(listener: (event: StorageEvent | CustomEvent) => void): () => void;
|
|
9
|
+
}
|