【发布时间】:2020-01-19 08:21:59
【问题描述】:
我正在开发一个使用 Apollo 客户端支持在 Android 中实现 Graphql 的应用程序。我有一个在 Android Activity 中成功运行的 Graphql 突变,但是当在 Android 片段中实现相同的突变时,它根本不会被调用。我的意思是控件永远不会返回到入队调用的 onResponse 或 onFailure 方法。 在 Fragment 的 onActivityCreated 方法中调用。
我是否遗漏了一些明显的东西?
这里是突变。
UserSignIn userSignIn = UserSignIn.builder()
.email("itxxxxd@gmail.com")
.password("xxxxx")
.build();
SignInMutation signInMutation = SignInMutation.builder().input(userSignIn).build();
ApiClient.getMyApolloClient().mutate(signInMutation).enqueue(new ApolloCall.Callback<SignInMutation.Data>() {
@Override
public void onResponse(@NotNull Response<SignInMutation.Data> response) {
if (response.data() != null) {
Timber.w("SignIn Data onResponse: %s", response.data().signIn().token);
}
if (!response.errors().isEmpty()) {
Timber.w("SignIn Error onResponse: %s", response.errors().get(0).message());
}
}
@Override
public void onFailure(@NotNull ApolloException e) {
Timber.w("SignIn Error onFailure: %s", e.toString());
}
});
谢谢。
【问题讨论】:
-
这不是片段或活动的问题。只是我的 Fragment 在控件返回到 onResponse 或 onFailure 方法之前以异常结束。这是我错过的显而易见的事情。谢谢。
标签: android android-fragments apollo-client graphql-java