android应用程序中使用的AWS Appsync突变功能无法将数据插入DynamoDB

时间:2019-11-27 14:05:29

标签: android aws-amplify aws-appsync

我创建了一个旨在通过以下指定链接与AWS Amplify库一起使用的android应用程序, https://aws.amazon.com/blogs/mobile/building-an-android-app-with-aws-amplify-part-1/https://aws-amplify.github.io/docs/js/api#delta-sync。 通过遵循文档,我能够正确地创建项目,并且通过使用AWS Amplify CLI,我能够设置Auth Cognito,API,Storage和Lambda函数。我还使用AWS Amplify Web控制台确认已为该项目创建了DynamoDB,Lambda函数(和index.js文件)和API。

问题: 当我尝试通过变异将数据以编程方式写入数据库时​​,没有数据插入到dynamodb中。(aws appsync功能)。

以下是我用来完成任务的代码。

 private void save() {
        final String name = ((EditText) findViewById(R.id.editTxt_name)).getText().toString();
        final String description = ((EditText) findViewById(R.id.editText_description)).getText().toString();

        Toast.makeText(AddPetActivity.this, "inside save()", Toast.LENGTH_SHORT).show();

        CreatePetInput input = CreatePetInput.builder()
                .name(name)
                .description(description)
                .build();

        CreatePetMutation addPetMutation = CreatePetMutation.builder()
                .input(input)
                .build();
        ClientFactory.appSyncClient().mutate(addPetMutation).enqueue(mutateCallback);
    }

    // Mutation callback code
    private GraphQLCall.Callback<CreatePetMutation.Data> mutateCallback = new GraphQLCall.Callback<CreatePetMutation.Data>() {
        @Override
        public void onResponse(@Nonnull final Response<CreatePetMutation.Data> response) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Log.d(TAG, "Successful in AddPetMutation");
                    Toast.makeText(AddPetActivity.this, "Added pet", Toast.LENGTH_SHORT).show();
                    AddPetActivity.this.finish();
                }
            });
        }

在运行应用程序并执行保存功能时,我得到以下日志(主要是库日志):

2019-11-27 19:04:40.559 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:04:40.560 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:04:40.560 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to process next mutation if one exists.
2019-11-27 19:04:40.562 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[12047]:Persistent mutations queue is EMPTY!. Will check inMemory Queue next
2019-11-27 19:04:40.562 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[12047]: In Memory mutations queue was EMPTY!. Nothing to process, exiting
2019-11-27 19:04:45.151 16532-16532/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[2]: Processing mutation.
2019-11-27 19:04:45.151 16532-16532/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[2]: First, checking if it is a retry of mutation that encountered a conflict.
2019-11-27 19:04:45.151 16532-16532/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[2]:Nope, hasn't encountered  conflict
2019-11-27 19:04:45.157 16532-16532/gadgeon.pro4tech.com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[2]:  Added mutation[1cb07050-1166-49e9-9297-cf84f411b64e] to inMemory Queue
2019-11-27 19:04:45.157 16532-16532/com.awsamplifypoc3 V/S3ObjectManagerImplementation: Thread:[2]: Looking at Key [input] of type [CreatePetInput]
2019-11-27 19:04:45.167 16532-16532/com.awsamplifypoc3 V/PersistentOfflineMutationManager: Thread:[2]:addPersistentMutationObject: Adding mutation[1cb07050-1166-49e9-9297-cf84f411b64e]: CreatePetMutation 
    {"query":"mutation CreatePet($input: CreatePetInput!) {  createPet(input: $input) {    __typename    id    name    description  }}","variables":{"input":{"name":"dog","description":"nice dog"}}}
2019-11-27 19:04:45.185 16532-16532/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[2]: Added mutation[1cb07050-1166-49e9-9297-cf84f411b64e] to Persistent Queue. No S3 Objects found
2019-11-27 19:04:45.185 16532-16532/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[2]: Created both in-memory and persistent records. Now going to signal queue handler.
2019-11-27 19:04:45.185 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:04:45.185 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to process next mutation if one exists.
2019-11-27 19:04:45.187 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[12047]:Persistent mutations queue is EMPTY!. Will check inMemory Queue next
2019-11-27 19:04:45.187 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Setting mutationInProgress as true.
2019-11-27 19:04:45.187 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[12047]: Processing next from in Memory queue
2019-11-27 19:04:45.187 16532-16652/com.awsamplifypoc3 V/InMemoryOfflineMutationManager: Thread:[12047]:Executing mutation [1cb07050-1166-49e9-9297-cf84f411b64e]
2019-11-27 19:04:45.187 16532-16652/com.awsamplifypoc3 V/InMemoryOfflineMutationObject: Thread:[12047]: Executing mutation by proceeding with the chain.
2019-11-27 19:04:45.187 16532-16652/com.awsamplifypoc3 V/S3ObjectManagerImplementation: Thread:[12047]: Looking at Key [input] of type [CreatePetInput]
2019-11-27 19:04:45.188 16532-16652/com.awsamplifypoc3 V/AppSyncComplexObjectsInterceptor: Thread:[12047]: No s3 Objects found. Proceeding with the chain
2019-11-27 19:04:45.199 16532-21832/com.awsamplifypoc3 V/InterceptorCallback: Thread:[12081]: onFetch()
2019-11-27 19:04:50.567 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:04:50.568 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:05:00.576 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:05:00.577 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:05:10.587 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:05:10.588 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:05:20.596 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:05:20.596 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:05:30.598 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:05:30.598 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:05:40.608 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:05:40.608 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:05:50.616 16532-16652/awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:05:50.616 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:06:00.627 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:06:00.627 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:06:10.636 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:06:10.637 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:06:20.642 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:06:20.643 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:06:30.645 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:06:30.646 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:06:40.653 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:06:40.653 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:06:50.662 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:06:50.663 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:07:00.666 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:07:00.666 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:07:10.670 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:07:10.670 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:07:20.679 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:07:20.680 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:07:30.691 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:07:30.691 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:07:40.699 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:07:40.700 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:07:50.711 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:07:50.711 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:08:00.719 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:08:00.719 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:08:10.723 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:08:10.724 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:08:20.734 16532-16652/gadgeon.pro4tech.com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:08:20.735 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:08:30.742 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:08:30.742 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:08:40.753 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:08:40.754 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:08:50.763 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:08:50.763 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:09:00.774 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:09:00.774 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:09:10.784 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:09:10.784 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:09:20.799 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:09:20.799 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:09:30.809 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:09:30.810 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:09:40.820 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:09:40.821 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:09:50.829 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:09:50.830 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:09:50.830 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Dispose called
2019-11-27 19:09:50.831 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: Dispose called for mutation [com.amazonaws.amplify.generated.graphql.CreatePetMutation@e3b6457].
2019-11-27 19:09:50.831 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[12047]: Handling cancellation for mutation [com.amazonaws.amplify.generated.graphql.CreatePetMutation@e3b6457]
2019-11-27 19:09:50.831 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[12047]: Mutation being canceled is the one currently in progress. Handling it 
2019-11-27 19:09:50.831 16532-16652/com.awsamplifypoc3 V/PersistentOfflineMutationManager: Thread:[12047]:Removing mutation [1cb07050-1166-49e9-9297-cf84f411b64e] from persistent store
2019-11-27 19:09:50.858 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Setting mutationInProgress as false.
2019-11-27 19:09:50.859 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:09:50.859 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to process next mutation if one exists.
2019-11-27 19:09:50.861 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[12047]:Persistent mutations queue is EMPTY!. Will check inMemory Queue next
2019-11-27 19:09:50.861 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[12047]: In Memory mutations queue was EMPTY!. Nothing to process, exiting
2019-11-27 19:10:00.840 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationInterceptor: Thread:[12047]: processing Mutations
2019-11-27 19:10:00.840 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to take action on the mutation queue.
2019-11-27 19:10:00.840 16532-16652/com.awsamplifypoc3 V/QueueUpdateHandler: Thread:[12047]: Got message to process next mutation if one exists.
2019-11-27 19:10:00.841 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[12047]:Persistent mutations queue is EMPTY!. Will check inMemory Queue next
2019-11-27 19:10:00.841 16532-16652/com.awsamplifypoc3 V/AppSyncOfflineMutationManager: Thread:[12047]: In Memory mutations queue was EMPTY!. Nothing to process, exiting
从日志中

很明显,该库接收了我们的数据并创建了内存记录和持久性记录,但后来自己调用了Dispose并取消了该突变并将其删除,并且从不击中该突变回调,并且该应用程序在那一点。

仅供参考: 在graphQL.schema文件中添加了以下架构

类型宠物@模型{   ID:ID!   名称:字符串!   描述:字符串 }

项目的 build.gradle中,我添加了以下依赖项。

classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:2.9.+'

,并且在应用的 build.gradle中,我添加了一个插件:

apply plugin: 'com.amazonaws.appsync'

以及以下依赖项:

implementation 'com.amazonaws:aws-android-sdk-appsync:2.8.+'

请帮助我了解如何解决此问题。

我们将不胜感激任何帮助。

0 个答案:

没有答案