Shopify / mobile-buy-sdk-android

Shopify’s Mobile Buy SDK makes it simple to sell physical products inside your mobile app. With a few lines of code, you can connect your app with the Shopify platform and let your users buy your products using their credit card.
MIT License
212 stars 136 forks source link

How use call API with new library version 7.0.0 #682

Open developerGM opened 3 years ago

developerGM commented 3 years ago

I am using this library version 7.0.0 and I am developing in java,

Cannot use this code because not exists this enqueue:

client.mutateGraph(mutationQuery).enqueue(new GraphCall.Callback<Storefront.Mutation>() {

  @Override public void onResponse(@NonNull final GraphResponse<Storefront.Mutation> response) {
    if (response.data().getCustomerReset().getUserErrors().isEmpty()) {
      String firstName = response.data().getCustomerReset().getCustomer().getFirstName();
      String lastName = response.data().getCustomerReset().getCustomer().getLastName();
    } else {
      Log.e(TAG, "Failed to reset customer");
    }
  }

  @Override public void onFailure(@NonNull final GraphError error) {
    Log.e(TAG, "Failed to execute query", error);
  }
});

I need to change to

client.mutateGraph(mutationQuery).enqueue(new Function1<GraphCallResult<? extends Storefront.Mutation>, Unit>() {
                @Override
                public Unit invoke(GraphCallResult<? extends Storefront.Mutation> graphCallResult) {

                    // here I need GraphResponse

                    return null;
                }
            });

how can I read results??

developerGM commented 3 years ago

Can be a solution in Java?

            client.mutateGraph(mutationQuery).enqueue(graphCallResult -> {
                if (graphCallResult instanceof GraphCallResult.Success) {
                    GraphResponse<Storefront.Mutation> res = ((GraphCallResult.Success<Storefront.Mutation>) graphCallResult).getResponse();
                    String token = res.getData().getCustomerAccessTokenCreate().getCustomerAccessToken().getAccessToken();
                } else {
                    String error = "";
                }
                return Unit.INSTANCE;
            });