From a2035d076aa03d80f753f3f66419b22aee67b4a9 Mon Sep 17 00:00:00 2001 From: Mark Lawlor Date: Sat, 12 Jan 2019 04:58:25 +1000 Subject: [PATCH 01/14] fix(subscriptions): Guard against errors: null response in subscription handshake (#337) --- packages/aws-appsync/src/link/subscription-handshake-link.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-appsync/src/link/subscription-handshake-link.ts b/packages/aws-appsync/src/link/subscription-handshake-link.ts index 31a2d439..b64e6529 100644 --- a/packages/aws-appsync/src/link/subscription-handshake-link.ts +++ b/packages/aws-appsync/src/link/subscription-handshake-link.ts @@ -72,7 +72,7 @@ export class SubscriptionHandshakeLink extends ApolloLink { errors: any[] } = subsInfo; - if (errors.length) { + if (errors && errors.length) { return new Observable(observer => { observer.error(new ApolloError({ errorMessage: 'Error during subscription handshake', From 42ac50a141b83746f6134c02a7bb8e6975a93d5b Mon Sep 17 00:00:00 2001 From: elorzafe Date: Fri, 11 Jan 2019 13:06:09 -0800 Subject: [PATCH 02/14] fix(offline-helpers): Offline helpers types and fix issue with different options (#329) --- packages/aws-appsync/src/helpers/offline.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/aws-appsync/src/helpers/offline.ts b/packages/aws-appsync/src/helpers/offline.ts index 60d1be98..5f0b2c80 100644 --- a/packages/aws-appsync/src/helpers/offline.ts +++ b/packages/aws-appsync/src/helpers/offline.ts @@ -87,9 +87,9 @@ export type CacheUpdateQuery = QueryWithVariables | DocumentNode; export type CacheUpdatesDefinitions = { [key in CacheOperationTypes]?: CacheUpdateQuery | CacheUpdateQuery[] -}; +} | CacheUpdateQuery | CacheUpdateQuery[]; -export type CacheUpdatesOptions = (variables?: object) => CacheUpdatesDefinitions | CacheUpdatesDefinitions; +export type CacheUpdatesOptions = ((variables?: object) => CacheUpdatesDefinitions) | CacheUpdatesDefinitions; /** * Builds a SubscribeToMoreOptions object ready to be used by Apollo's subscribeToMore() to automatically update the query result in the @@ -171,9 +171,14 @@ const getOpTypeQueriesMap = (cacheUpdateQuery: CacheUpdatesOptions, variables): const cacheUpdateQueryVal = typeof cacheUpdateQuery === 'function' ? cacheUpdateQuery(variables) : cacheUpdateQuery || {}; - const opTypeQueriesMap = isDocument(cacheUpdateQueryVal) ? - { [CacheOperationTypes.AUTO]: [].concat(cacheUpdateQueryVal) } as CacheUpdatesDefinitions : - cacheUpdateQueryVal; + + let opTypeQueriesMap = cacheUpdateQueryVal; + + if (isDocument(cacheUpdateQueryVal) || + isDocument((cacheUpdateQueryVal as QueryWithVariables).query) || + Array.isArray(cacheUpdateQuery)) { + opTypeQueriesMap = { [CacheOperationTypes.AUTO]: [].concat(cacheUpdateQueryVal) } as CacheUpdatesDefinitions; + } return opTypeQueriesMap; }; From 8dbe01dd7ee734df81b3549482a141179e77a71f Mon Sep 17 00:00:00 2001 From: Manuel Iglesias Date: Fri, 11 Jan 2019 13:06:32 -0800 Subject: [PATCH 03/14] fix(deltasync): Fix error when baseQuery is not specified (#320) --- packages/aws-appsync/src/deltaSync.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-appsync/src/deltaSync.ts b/packages/aws-appsync/src/deltaSync.ts index 8cf6703b..10e0f53f 100644 --- a/packages/aws-appsync/src/deltaSync.ts +++ b/packages/aws-appsync/src/deltaSync.ts @@ -318,7 +318,7 @@ const effect = async ( } //#endregion - const { baseRefreshIntervalInSeconds } = baseQuery; + const { baseRefreshIntervalInSeconds } = baseQuery || { baseRefreshIntervalInSeconds: undefined }; upperBoundTimeMS = baseRefreshIntervalInSeconds ? baseRefreshIntervalInSeconds * 1000 : DEFAULT_UPPER_BOUND_TIME_MS; const skipBaseQuery = !(baseQuery && baseQuery.query) || (baseLastSyncTimestamp From b933379125e0cb1238020a31f4276b56ae8b233e Mon Sep 17 00:00:00 2001 From: Manuel Iglesias Date: Fri, 11 Jan 2019 13:06:55 -0800 Subject: [PATCH 04/14] fix(subscriptions): Do not retry mqtt disconnections (#319) - If auto-reconnect when coming back online is needed, users should use `client.sync` (deltaSync) instead. --- packages/aws-appsync/src/link/retry-link.ts | 6 ++++++ .../src/link/subscription-handshake-link.ts | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/aws-appsync/src/link/retry-link.ts b/packages/aws-appsync/src/link/retry-link.ts index a08bfeb8..159b7e26 100644 --- a/packages/aws-appsync/src/link/retry-link.ts +++ b/packages/aws-appsync/src/link/retry-link.ts @@ -18,6 +18,7 @@ const MAX_DELAY_MS = 5 * 60 * 1000; const getDelay = count => ((2 ** count) * BASE_TIME_MS) + (JITTER_FACTOR * Math.random()); export const SKIP_RETRY_KEY = '@@skipRetry'; +export const PERMANENT_ERROR_KEY = typeof Symbol !== 'undefined' ? Symbol('permanentError') : '@@permanentError'; export const getEffectDelay = (_action: OfflineAction, retries: number) => { const delay = getDelay(retries); @@ -30,8 +31,13 @@ export const createRetryLink = (origLink: ApolloLink) => { const retryLink = new RetryLink({ attempts: (count, operation, error) => { + const { [PERMANENT_ERROR_KEY]: permanent = false } = error; const { [SKIP_RETRY_KEY]: skipRetry = false } = operation.variables; + if (permanent) { + return false; + } + if (error.statusCode >= 400 && error.statusCode < 500) { return false; } diff --git a/packages/aws-appsync/src/link/subscription-handshake-link.ts b/packages/aws-appsync/src/link/subscription-handshake-link.ts index b64e6529..64e04ff3 100644 --- a/packages/aws-appsync/src/link/subscription-handshake-link.ts +++ b/packages/aws-appsync/src/link/subscription-handshake-link.ts @@ -13,6 +13,7 @@ import * as Paho from '../vendor/paho-mqtt'; import { ApolloError } from "apollo-client"; import { FieldNode } from "graphql"; import { getMainDefinition } from "apollo-utilities"; +import { PERMANENT_ERROR_KEY } from "./retry-link"; const logger = rootLogger.extend('subscriptions'); const mqttLogger = logger.extend('mqtt'); @@ -66,11 +67,11 @@ export class SubscriptionHandshakeLink extends ApolloLink { } = { subscription: { newSubscriptions: {}, mqttConnections: [] } }, errors = [], }: { - extensions?: { - subscription: SubscriptionExtension - }, - errors: any[] - } = subsInfo; + extensions?: { + subscription: SubscriptionExtension + }, + errors: any[] + } = subsInfo; if (errors && errors.length) { return new Observable(observer => { @@ -170,7 +171,7 @@ export class SubscriptionHandshakeLink extends ApolloLink { if (errorCode !== 0) { topics.forEach(t => { if (this.topicObservers.has(t)) { - this.topicObservers.get(t).forEach(observer => observer.error(args)); + this.topicObservers.get(t).forEach(observer => observer.error({ ...args, [PERMANENT_ERROR_KEY]: true })); } }); } From c990f7c4f206feae2628cd951fe52e8c7d894375 Mon Sep 17 00:00:00 2001 From: Manuel Iglesias Date: Fri, 11 Jan 2019 14:43:11 -0800 Subject: [PATCH 05/14] chore(release): Publish [ci skip] - aws-appsync-react@1.2.6 - aws-appsync@1.7.1 --- packages/aws-appsync-react/CHANGELOG.md | 8 ++++++++ packages/aws-appsync-react/package.json | 4 ++-- packages/aws-appsync/CHANGELOG.md | 15 +++++++++++++++ packages/aws-appsync/package.json | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/aws-appsync-react/CHANGELOG.md b/packages/aws-appsync-react/CHANGELOG.md index bbe75086..8e30d33f 100644 --- a/packages/aws-appsync-react/CHANGELOG.md +++ b/packages/aws-appsync-react/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.2.6](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-react@1.2.5...aws-appsync-react@1.2.6) (2019-01-11) + + + + +**Note:** Version bump only for package aws-appsync-react + ## [1.2.5](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-react@1.2.4...aws-appsync-react@1.2.5) (2018-12-12) diff --git a/packages/aws-appsync-react/package.json b/packages/aws-appsync-react/package.json index 05e6c692..408a17eb 100644 --- a/packages/aws-appsync-react/package.json +++ b/packages/aws-appsync-react/package.json @@ -1,6 +1,6 @@ { "name": "aws-appsync-react", - "version": "1.2.5", + "version": "1.2.6", "main": "lib/index.js", "license": "SEE LICENSE IN LICENSE", "description": "AWS Mobile AppSync SDK for JavaScript - React and React Native components", @@ -27,7 +27,7 @@ "devDependencies": { "@types/graphql": "0.12.4", "@types/react": "^16.0.25", - "aws-appsync": "^1.7.0", + "aws-appsync": "^1.7.1", "react": "^16.1.1", "react-apollo": "^2.1.9", "react-native": "^0.50.3", diff --git a/packages/aws-appsync/CHANGELOG.md b/packages/aws-appsync/CHANGELOG.md index c065129d..9d9f8a98 100644 --- a/packages/aws-appsync/CHANGELOG.md +++ b/packages/aws-appsync/CHANGELOG.md @@ -3,6 +3,21 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.7.1](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync@1.7.0...aws-appsync@1.7.1) (2019-01-11) + + +### Bug Fixes + +* **deltasync:** Fix error when baseQuery is not specified ([#320](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/320)) ([8dbe01d](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/8dbe01d)) +* **offline-helpers:** Offline helpers types and fix issue with different options ([#329](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/329)) ([42ac50a](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/42ac50a)) +* **offline-helpers:** Preserve order of elements in update cache operation type ([#325](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/325)) ([5b49946](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/5b49946)) +* **subscriptions:** Do not retry mqtt disconnections ([#319](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/319)) ([b933379](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/b933379)) +* **subscriptions:** Guard against errors: null response in subscription handshake ([#337](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/337)) ([a2035d0](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/a2035d0)) + + + + # [1.7.0](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync@1.6.0...aws-appsync@1.7.0) (2018-12-12) diff --git a/packages/aws-appsync/package.json b/packages/aws-appsync/package.json index b3c8306e..235888c3 100644 --- a/packages/aws-appsync/package.json +++ b/packages/aws-appsync/package.json @@ -1,6 +1,6 @@ { "name": "aws-appsync", - "version": "1.7.0", + "version": "1.7.1", "main": "lib/index.js", "license": "SEE LICENSE IN LICENSE", "description": "AWS Mobile AppSync SDK for JavaScript", From d81af3896efef9166cd70f6ac29e21ea860d9f88 Mon Sep 17 00:00:00 2001 From: Hisham A Date: Thu, 24 Jan 2019 18:03:05 -0700 Subject: [PATCH 06/14] fix(typescript) add promise types for CredentialsGetter (#305) add promised version as valid types for CredentialsGetter - see https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/264 --- packages/aws-appsync/src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-appsync/src/client.ts b/packages/aws-appsync/src/client.ts index e7caf648..a0edd81c 100644 --- a/packages/aws-appsync/src/client.ts +++ b/packages/aws-appsync/src/client.ts @@ -124,7 +124,7 @@ const createLinkWithStore = (createLinkFunc = (store: Store) = }); } -type CredentialsGetter = () => (Credentials | CredentialsOptions | null) | Credentials | CredentialsOptions | null; +type CredentialsGetter = () => (Credentials | CredentialsOptions | Promise | Promise | null) | Credentials | CredentialsOptions | Promise | Promise | null; export interface AWSAppSyncClientOptions { url: string, From 2278942104ca96aead029075461ae554dc4a0408 Mon Sep 17 00:00:00 2001 From: elorzafe Date: Thu, 24 Jan 2019 17:08:56 -0800 Subject: [PATCH 07/14] Update package.json (#333) Parity with @aws-amplify/api on graphql package dependency --- packages/aws-appsync/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-appsync/package.json b/packages/aws-appsync/package.json index 235888c3..42d94ebb 100644 --- a/packages/aws-appsync/package.json +++ b/packages/aws-appsync/package.json @@ -28,7 +28,7 @@ "apollo-link-retry": "2.2.5", "aws-sdk": "2.329.0", "debug": "2.6.9", - "graphql": "^0.11.7", + "graphql": "0.13.0", "redux": "^3.7.2", "redux-thunk": "^2.2.0", "setimmediate": "^1.0.5", From 920b47dac4efb8f41ab8f0ec6a7ef69299b6085c Mon Sep 17 00:00:00 2001 From: Andreas Greimel Date: Tue, 19 Feb 2019 23:04:31 +0100 Subject: [PATCH 08/14] fix(auth): Remove temporary variables (starting with '@@') before signing (#347) Fixes #354 This fixes an InvalidSignatureExceptions that occurs when using iamBasedAuthentication and the '@@controlEvents' variable in subscriptions --- packages/aws-appsync/src/link/auth-link.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/aws-appsync/src/link/auth-link.ts b/packages/aws-appsync/src/link/auth-link.ts index a4beb560..a4562137 100644 --- a/packages/aws-appsync/src/link/auth-link.ts +++ b/packages/aws-appsync/src/link/auth-link.ts @@ -36,7 +36,7 @@ export class AuthLink extends ApolloLink { private link: ApolloLink; /** - * + * * @param {*} options */ constructor(options) { @@ -167,7 +167,7 @@ export const authLink = ({ url, region, auth: { type = AUTH_TYPE.NONE, credentia const formatAsRequest = ({ operationName, variables, query }, options) => { const body = { operationName, - variables, + variables: removeTemporaryVariables(variables), query: print(query) }; @@ -182,3 +182,15 @@ const formatAsRequest = ({ operationName, variables, query }, options) => { }, }; } + +/** + * Removes all temporary variables (starting with '@@') so that the signature matches the final request. + */ +const removeTemporaryVariables = (variables: any) => + Object.keys(variables) + .filter(key => !key.startsWith("@@")) + .reduce((acc, key) => { + acc[key] = variables[key]; + return acc; + }, {}); + From 13a2dec2788963a73debe1df61a7ac6ed5f6ad35 Mon Sep 17 00:00:00 2001 From: elorzafe Date: Mon, 11 Mar 2019 18:08:43 -0700 Subject: [PATCH 09/14] fix(deltaSync): Make sure query manager is initialized Related to this issue https://forums.aws.amazon.com/thread.jspa?messageID=893237󚄵 --- packages/aws-appsync/src/deltaSync.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/aws-appsync/src/deltaSync.ts b/packages/aws-appsync/src/deltaSync.ts index 10e0f53f..f835f8da 100644 --- a/packages/aws-appsync/src/deltaSync.ts +++ b/packages/aws-appsync/src/deltaSync.ts @@ -417,6 +417,7 @@ const effect = async ( boundSaveSnapshot(store, client.cache); + client.initQueryManager(); const dataStore = client.queryManager.dataStore; const enqueuedActionsFilter = [mutationsConfig.enqueueAction]; enquededMutations From a97c3b5e72243d4574011f25828287da8c25c657 Mon Sep 17 00:00:00 2001 From: Rodriguez Elorza Date: Tue, 12 Mar 2019 11:00:30 -0700 Subject: [PATCH 10/14] add npmrc to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 986e468a..ba28bbba 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules lib *.tgz lerna-debug.log +.npmrc From b3f6fde315b036f84019434d393931cbf5a95130 Mon Sep 17 00:00:00 2001 From: Rodriguez Elorza Date: Tue, 12 Mar 2019 11:12:50 -0700 Subject: [PATCH 11/14] chore(release): Publish [ci skip] - aws-appsync-react@1.2.7 - aws-appsync@1.7.2 --- packages/aws-appsync-react/CHANGELOG.md | 8 ++++++++ packages/aws-appsync-react/package.json | 4 ++-- packages/aws-appsync/CHANGELOG.md | 12 ++++++++++++ packages/aws-appsync/package.json | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/aws-appsync-react/CHANGELOG.md b/packages/aws-appsync-react/CHANGELOG.md index 8e30d33f..c954fd21 100644 --- a/packages/aws-appsync-react/CHANGELOG.md +++ b/packages/aws-appsync-react/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.2.7](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-react@1.2.6...aws-appsync-react@1.2.7) (2019-03-12) + + + + +**Note:** Version bump only for package aws-appsync-react + ## [1.2.6](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-react@1.2.5...aws-appsync-react@1.2.6) (2019-01-11) diff --git a/packages/aws-appsync-react/package.json b/packages/aws-appsync-react/package.json index 408a17eb..d01d10d8 100644 --- a/packages/aws-appsync-react/package.json +++ b/packages/aws-appsync-react/package.json @@ -1,6 +1,6 @@ { "name": "aws-appsync-react", - "version": "1.2.6", + "version": "1.2.7", "main": "lib/index.js", "license": "SEE LICENSE IN LICENSE", "description": "AWS Mobile AppSync SDK for JavaScript - React and React Native components", @@ -27,7 +27,7 @@ "devDependencies": { "@types/graphql": "0.12.4", "@types/react": "^16.0.25", - "aws-appsync": "^1.7.1", + "aws-appsync": "^1.7.2", "react": "^16.1.1", "react-apollo": "^2.1.9", "react-native": "^0.50.3", diff --git a/packages/aws-appsync/CHANGELOG.md b/packages/aws-appsync/CHANGELOG.md index 9d9f8a98..76409409 100644 --- a/packages/aws-appsync/CHANGELOG.md +++ b/packages/aws-appsync/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.7.2](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync@1.7.1...aws-appsync@1.7.2) (2019-03-12) + + +### Bug Fixes + +* **auth:** Remove temporary variables (starting with '@@') before signing ([#347](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/347)) ([920b47d](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/920b47d)), closes [#354](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/354) +* **deltaSync:** Make sure query manager is initialized ([13a2dec](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/13a2dec)), closes [#893237](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/893237) + + + + ## [1.7.1](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync@1.7.0...aws-appsync@1.7.1) (2019-01-11) diff --git a/packages/aws-appsync/package.json b/packages/aws-appsync/package.json index 42d94ebb..6acc5437 100644 --- a/packages/aws-appsync/package.json +++ b/packages/aws-appsync/package.json @@ -1,6 +1,6 @@ { "name": "aws-appsync", - "version": "1.7.1", + "version": "1.7.2", "main": "lib/index.js", "license": "SEE LICENSE IN LICENSE", "description": "AWS Mobile AppSync SDK for JavaScript", From af84d3e3d9323a534b64af46e6830e0e7c7e572f Mon Sep 17 00:00:00 2001 From: Nate Bell Date: Wed, 20 Mar 2019 12:43:03 -0400 Subject: [PATCH 12/14] fix(readme) switch AppSync.js to aws-exports.js (#373) I can't find anywhere in the console that I can download a file named AppSync.js... but I have aws-exports.js. The docs are still very confusing when new to all of these libraries that can be mixed and matched. I can get the Amplify CLI to work out of the box, but as soon as you try to add AWSAppSyncClient instead and use the Apollo client things get very confusing to me. --- tutorials/react-offline-realtime-todos/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tutorials/react-offline-realtime-todos/README.md b/tutorials/react-offline-realtime-todos/README.md index 7ec96e04..90220814 100644 --- a/tutorials/react-offline-realtime-todos/README.md +++ b/tutorials/react-offline-realtime-todos/README.md @@ -52,7 +52,7 @@ input UpdateTodoInput { } ``` -**Save** the schema again. On the navigation bar in the left of the console, click on ``, scroll down and select the **Web** section then click **Download** and save the `AppSync.js` file somewhere for later. +**Save** the schema again. On the navigation bar in the left of the console, click on ``, scroll down and select the **Web** section then click **Download Config** and save the `aws-exports.js` file somewhere for later. ## Imports and configuration @@ -65,13 +65,13 @@ create-react-app todos && cd ./todos yarn add aws-appsync aws-appsync-react graphql-tag react-apollo ``` -Copy the `AppSync.js` file that you downloaded from the console into the `./todos/src` directory. Next add the following imports towards the top of the `App.js` file: +Copy the `aws-exports.js` file that you downloaded from the console into the `./todos/src` directory. Next add the following imports towards the top of the `App.js` file: ```javascript import AWSAppSyncClient, { buildSubscription } from 'aws-appsync'; import { Rehydrated, graphqlMutation } from 'aws-appsync-react'; -import AppSyncConfig from './AppSync'; +import awsmobile from './aws-exports'; import { ApolloProvider } from 'react-apollo'; ``` @@ -79,11 +79,11 @@ Replace everything __after__ the definition of the `` component with the ```jsx const client = new AWSAppSyncClient({ - url: AppSyncConfig.graphqlEndpoint, - region: AppSyncConfig.region, + url: awsmobile.graphqlEndpoint, + region: awsmobile.region, auth: { - type: AppSyncConfig.authenticationType, - apiKey: AppSyncConfig.apiKey + type: awsmobile.authenticationType, + apiKey: awsmobile.apiKey } }) From 997e3d8a958ee2e2d9ffd00fd1eaf20e11343c98 Mon Sep 17 00:00:00 2001 From: lukasf98 Date: Wed, 20 Mar 2019 17:55:51 +0100 Subject: [PATCH 13/14] fix(deltaSync) (#368) --- packages/aws-appsync/src/deltaSync.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-appsync/src/deltaSync.ts b/packages/aws-appsync/src/deltaSync.ts index f835f8da..91f8fbf1 100644 --- a/packages/aws-appsync/src/deltaSync.ts +++ b/packages/aws-appsync/src/deltaSync.ts @@ -336,7 +336,7 @@ const effect = async ( query, variables, }); - cacheProxy.writeQuery({ query, data: result.data }); + cacheProxy.writeQuery({ query, variables, data: result.data }); if (typeof update === 'function') { tryFunctionOrLogError(() => { From 2fe09c09d0bd71981ef3e795ca74e17f8d0cdfbf Mon Sep 17 00:00:00 2001 From: Mickael Lecoq Date: Fri, 5 Apr 2019 19:17:06 +0200 Subject: [PATCH 14/14] Make effect delay and network detection configurables --- packages/aws-appsync/src/client.ts | 16 ++++++++++++---- packages/aws-appsync/src/link/retry-link.ts | 6 +++--- packages/aws-appsync/src/store.ts | 6 ++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/aws-appsync/src/client.ts b/packages/aws-appsync/src/client.ts index a0edd81c..fcb169fe 100644 --- a/packages/aws-appsync/src/client.ts +++ b/packages/aws-appsync/src/client.ts @@ -24,7 +24,7 @@ import { ComplexObjectLink, AUTH_TYPE } from './link'; -import { createStore } from './store'; +import { createStore, OfflineStatusChangeCallbackCreator } from './store'; import { ApolloCache } from 'apollo-cache'; import { AuthOptions } from './link/auth-link'; import { Credentials, CredentialsOptions } from 'aws-sdk/lib/credentials'; @@ -77,6 +77,7 @@ export const createAppSyncLink = ({ complexObjectsCredentials, resultsFetcherLink = createHttpLink({ uri: url }), conflictResolver, + getDelay }: { url: string, region: string, @@ -84,6 +85,7 @@ export const createAppSyncLink = ({ complexObjectsCredentials: CredentialsGetter, resultsFetcherLink?: ApolloLink, conflictResolver?: ConflictResolver, + getDelay?: (retries: number)=> number }) => { const link = ApolloLink.from([ createLinkWithStore((store) => new OfflineLink(store)), @@ -92,7 +94,7 @@ export const createAppSyncLink = ({ createRetryLink(ApolloLink.from([ createAuthLink({ url, region, auth }), createSubscriptionHandshakeLink(url, resultsFetcherLink) - ])) + ]), getDelay) ].filter(Boolean)); return link; @@ -141,6 +143,8 @@ export interface OfflineConfig { storage?: any, callback?: OfflineCallback, storeCacheRootMutation?: boolean, + detectNetwork?: OfflineStatusChangeCallbackCreator, + getDelay?: (retries:number)=>number }; // TODO: type defs @@ -180,6 +184,8 @@ class AWSAppSyncClient extends Apollo storage = undefined, callback = () => { }, storeCacheRootMutation = false, + detectNetwork = undefined, + getDelay=undefined } = {}, }: AWSAppSyncClientOptions, options?: Partial>) { const { cache: customCache = undefined, link: customLink = undefined } = options || {}; @@ -197,7 +203,9 @@ class AWSAppSyncClient extends Apollo () => this, () => { resolveClient(this); }, dataIdFromObject, storage, - callback + callback, + detectNetwork, + getDelay ); const cache: ApolloCache = disableOffline ? (customCache || new InMemoryCache(cacheOptions)) @@ -218,7 +226,7 @@ class AWSAppSyncClient extends Apollo }; }); }); - const link = waitForRehydrationLink.concat(customLink || createAppSyncLink({ url, region, auth, complexObjectsCredentials, conflictResolver })); + const link = waitForRehydrationLink.concat(customLink || createAppSyncLink({ url, region, auth, complexObjectsCredentials, conflictResolver, getDelay })); const newOptions = { ...options, diff --git a/packages/aws-appsync/src/link/retry-link.ts b/packages/aws-appsync/src/link/retry-link.ts index 159b7e26..cbf874da 100644 --- a/packages/aws-appsync/src/link/retry-link.ts +++ b/packages/aws-appsync/src/link/retry-link.ts @@ -15,18 +15,18 @@ const BASE_TIME_MS = 100; const JITTER_FACTOR = 100; const MAX_DELAY_MS = 5 * 60 * 1000; -const getDelay = count => ((2 ** count) * BASE_TIME_MS) + (JITTER_FACTOR * Math.random()); +const getDefaultDelay = count => ((2 ** count) * BASE_TIME_MS) + (JITTER_FACTOR * Math.random()); export const SKIP_RETRY_KEY = '@@skipRetry'; export const PERMANENT_ERROR_KEY = typeof Symbol !== 'undefined' ? Symbol('permanentError') : '@@permanentError'; -export const getEffectDelay = (_action: OfflineAction, retries: number) => { +export const getEffectDelay = (getDelay:(retries:number) => number=getDefaultDelay) => (_action: OfflineAction, retries: number) => { const delay = getDelay(retries); return delay <= MAX_DELAY_MS ? delay : null; }; -export const createRetryLink = (origLink: ApolloLink) => { +export const createRetryLink = (origLink: ApolloLink, getDelay:(retries:number) => number=getDefaultDelay) => { let delay; const retryLink = new RetryLink({ diff --git a/packages/aws-appsync/src/store.ts b/packages/aws-appsync/src/store.ts index 72817f01..e6a42a8c 100644 --- a/packages/aws-appsync/src/store.ts +++ b/packages/aws-appsync/src/store.ts @@ -22,7 +22,7 @@ import { OfflineAction, NetInfo, NetworkCallback } from '@redux-offline/redux-of import { offlineEffectConfig as deltaSyncConfig } from "./deltaSync"; import { Observable } from 'apollo-link'; -const { detectNetwork } = defaultOfflineConfig; +const { detectNetwork : defaultDetectNetwork } = defaultOfflineConfig; const logger = rootLogger.extend('store'); @@ -32,6 +32,8 @@ const newStore = ( dataIdFromObject: (obj) => string | null, storage: any, callback: OfflineCallback = () => { }, + detectNetwork: OfflineStatusChangeCallbackCreator = defaultDetectNetwork, + getDelay?: (retries:number) => number ): Store => { logger('Creating store'); @@ -53,7 +55,7 @@ const newStore = ( applyMiddleware(thunk), offline({ ...defaultOfflineConfig, - retry: getEffectDelay, + retry: getEffectDelay(getDelay), persistCallback: () => { logger('Storage ready');