我正在为我的项目使用 AWS AppSync。当使用突变将数据推送到服务器时,它工作正常。但我有订阅问题。
OnEventCreated onEventCreated = OnEventCreated.builder().build();
subscriptionWatcher = ClientFactory.getInstance(this).subscribe(onEventCreated); // giving error
subscribe
函数接受实现订阅的输入。但是当我构建我的项目时,生成的代码实现了查询。
生成的类
@Generated("Apollo GraphQL")
public final class OnEventCreated implements Query<OnEventCreated.Data, OnEventCreated.Data, Operation.Variables> {
public static final String OPERATION_DEFINITION = "subscription OnEventCreated {\n"
+ " onEventCreated {\n"
+ " __typename\n"
+ " id\n"
+ " description\n"
+ " name\n"
+ " when\n"
+ " where\n"
+ " }\n"
+ "}";
public static final String QUERY_DOCUMENT = OPERATION_DEFINITION;
}...
GraphQL 文件中订阅的具体代码是..
subscription OnEventCreated {
onEventCreated {
id
description
name
when
where
}
} ...
Schema.json 文件
type Subscription {
subscribeToEventComments(eventId: String!): Comment
@aws_subscribe(mutations: ["commentOnEvent"])
onEventCreated: Event
@aws_subscribe(mutations: ["createEvent"])
}...
构建文件包含...
compile 'com.amazonaws:aws-android-sdk-appsync:2.6.16'
compile 'com.amazonaws:aws-android-sdk-appsync-compiler:2.6.16'
compile 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.6.16'
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
我能做些什么呢。当我构建时,生成的 OnEventCreated 类实现了 Subscription 接口而不是 Query 接口