1

考虑以下对 apollo 的订阅:

 entityCreated: {
      subscribe: withFilter(
        () => pubsub.asyncIterator(["ENTITY_CREATED"]),
        async (payload, variables, context) => {
          let result = await firebaseApi.userHasEntity(
            context.user,
            payload.entityCreated
          );
          // Prints true 
          console.log(result);
          return result;
        }
      ),
    },

我正在使用 codegen 侦听器来侦听此事件,但它仅在此函数如下时触发:

  entityCreated: {
    subscribe: withFilter(
      () => pubsub.asyncIterator(["ENTITY_CREATED"]),
      async (payload, variables, context) => {
        return true;
      }
    ),
  },

第二个效果很好。为什么?似乎第一个变体不等待异步调用完成?

4

0 回答 0