Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

For an Amplify Datastore setup, is there a way to turn off AWS AppSync to just work locally?

I'm using Amplify Datastore with AppSync enabled. Data syncing is working between local and cloud, but having to execute amplify push to update cloud during development can suck up a lot of time.

How can I turn off AWS AppSync?

question from:https://stackoverflow.com/questions/65896953/for-an-amplify-datastore-setup-is-there-a-way-to-turn-off-aws-appsync-to-just-w

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes! DataStore can be used with or without any cloud synchronization.

Android

Cloud sync is enabled when you add an API plugin. To disable cloud sync, don't add AWSApiPlugin():

Amplify.addPlugin(AWSDataStorePlugin())

// Comment out this line:
// Amplify.addPlugin(AWSApiPlugin())

Amplify.configure(applicationContext)

iOS

Sync is enabled when there is an API plugin present. To disable sync, do not add AWSAPIPlugin():

let dataStorePlugin =
    AWSDataStorePlugin(modelRegistration: AmplifyModels())
try Amplify.add(plugin: dataStorePlugin)

// Comment out this line:
// try Amplify.add(plugin: AWSAPIPlugin())

try Amplify.configure()

JavaScript

The approach is slightly different. Look for any API configurations in the aws-exports.js file, and remove them. Specifically, you should remove any config entries with aws_appsync_* in the prefix:

const awsmobile = {
    // ...
    "aws_appsync_graphqlEndpoint": "https://yourid.appsync-api.us-east-1.amazonaws.com/graphql",
    "aws_appsync_region": "us-east-1",
    "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
    // ...
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...