Search in sources :

Example 1 with CreatePostInput

use of type.CreatePostInput in project aws-mobile-appsync-sdk-android by awslabs.

the class AddPostActivity method save.

private void save() {
    final AddPostActivity display = this;
    String title = ((EditText) findViewById(R.id.updateTitle)).getText().toString();
    String author = ((EditText) findViewById(R.id.updateAuthor)).getText().toString();
    String url = ((EditText) findViewById(R.id.updateUrl)).getText().toString();
    String content = ((EditText) findViewById(R.id.updateContent)).getText().toString();
    final AWSAppSyncClient client = ClientFactory.getInstance(this.getApplicationContext());
    CreatePostMutation.Data expected = new CreatePostMutation.Data(null);
    CreatePostInput createPostInput = CreatePostInput.builder().title(title).author(author).content(content).url(url).ups(0).downs(0).build();
    CreatePostMutation addPostMutation = CreatePostMutation.builder().input(createPostInput).build();
    client.mutate(addPostMutation, expected).enqueue(new GraphQLCall.Callback<CreatePostMutation.Data>() {

        @Override
        public void onResponse(@Nonnull final Response<CreatePostMutation.Data> response) {
            Log.d(TAG, "Post added");
            // Add To Delta Table
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(display, "Added!", Toast.LENGTH_SHORT).show();
                    display.finish();
                }
            });
        }

        @Override
        public void onFailure(@Nonnull ApolloException e) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(display, "Failed to add post!", Toast.LENGTH_SHORT).show();
                    display.finish();
                }
            });
            Log.d(TAG, "Post add failed with [" + e.getLocalizedMessage() + "]");
            e.printStackTrace();
        }
    });
}
Also used : GraphQLCall(com.apollographql.apollo.GraphQLCall) CreatePostInput(type.CreatePostInput) CreatePostMutation(com.amazonaws.amplify.generated.graphql.CreatePostMutation) AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) ApolloException(com.apollographql.apollo.exception.ApolloException)

Aggregations

CreatePostMutation (com.amazonaws.amplify.generated.graphql.CreatePostMutation)1 AWSAppSyncClient (com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient)1 GraphQLCall (com.apollographql.apollo.GraphQLCall)1 ApolloException (com.apollographql.apollo.exception.ApolloException)1 CreatePostInput (type.CreatePostInput)1