From 71a722a874342465d0f0a3e54be8a1a4efadf4d8 Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Tue, 22 Oct 2024 17:29:53 -0700 Subject: [PATCH] [smart-subscriptions] handle subscribe method being async --- .changeset/slow-kings-stare.md | 5 +++++ .../plugin-smart-subscriptions/src/resolve-with-cache.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/slow-kings-stare.md diff --git a/.changeset/slow-kings-stare.md b/.changeset/slow-kings-stare.md new file mode 100644 index 000000000..13d434103 --- /dev/null +++ b/.changeset/slow-kings-stare.md @@ -0,0 +1,5 @@ +--- +"@pothos/plugin-smart-subscriptions": patch +--- + +Handle async subsdcribe methods diff --git a/packages/plugin-smart-subscriptions/src/resolve-with-cache.ts b/packages/plugin-smart-subscriptions/src/resolve-with-cache.ts index 17b6eb827..9656ff919 100644 --- a/packages/plugin-smart-subscriptions/src/resolve-with-cache.ts +++ b/packages/plugin-smart-subscriptions/src/resolve-with-cache.ts @@ -36,7 +36,11 @@ export default function resolveWithCache( function cacheResult(result: unknown) { const cacheNode = cache.add(info, key, canRefetch, result); - subscribe?.(cacheNode.managerForField(), parent, args, context, info); + const sub = subscribe?.(cacheNode.managerForField(), parent, args, context, info); + + if (isThenable(sub)) { + return sub.then(() => result); + } return result; }