GraphQL订阅后为空响应

时间:2018-08-04 02:52:53

标签: rx-java graphql reactive-streams graphql-java

在此示例之后,

我实现了自己的发布商

Publisher<VendorCostInfo> vendorCostInfo(VendorCostInfoFilter filter) {
    return vendorCostInfoPublisher.getPublisher(vendorCostInfoFilter);
}

并使用以下发射器逻辑进行订阅

private void emitVendorCostInfo(
  ObservableEmitter<VendorCostInfo> emitter,
  List<VendorCostInfo> vendorCostInfoList
) {
  for (VendorCostInfo info: vendorCostInfoList) {
    try {
      emitter.onNext(info);
    } catch (RuntimeException e) {
      log.error("cannot send vendor cost info", e);
    }
}

}

以及构造函数逻辑

public VendorCostInfoPublisher(VendorCostInfoService service) {
    this.vendorCostInfoService = service;
    Observable<VendorCostInfo> vendorCostInfoObservable = Observable.create(emitter -> {

      ScheduledExecutorService executorService = 
Executors.newScheduledThreadPool(2);
      executorService.scheduleAtFixedRate(
          newVendorCostInfo(emitter),
          0,
          2,
          TimeUnit.SECONDS
      );
    });

    ConnectableObservable<VendorCostInfo> connectableObservable =
        vendorCostInfoObservable.share().publish();

    connectableObservable.connect();

    publisher = connectableObservable.toFlowable(BackpressureStrategy.BUFFER);
  }

我已经确认数据存在,但是在尝试订阅后

subscription {
  vendorCostInfo(filter:{}) {
    service
  }
}

响应为

{ 
"data": {} 
}

为什么会这样?完整代码here

0 个答案:

没有答案