From 0b5b42dbdb35468b6f89e22559486deca45b7174 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Sun, 25 Nov 2018 18:16:36 +0100 Subject: [PATCH 1/3] Retain synchronicity of resolvers Introspection queries should always resolve synchronously, and this wrapper causes them to be async. This causes problems when used in conjunction with Apollo. --- lib/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 8823650..dbcd016 100755 --- a/lib/index.js +++ b/lib/index.js @@ -63,10 +63,13 @@ function maskField(field, fn) { } field[Processed] = true; - field.resolve = async function (...args) { + field.resolve = function (...args) { try { const out = resolveFn.call(this, ...args); - return await Promise.resolve(out); + if (typeof out.then === 'function') { + out = out.then(undefined, e => fn(e, args)); + } + return out; } catch (e) { throw fn(e, args); } From 352e2b1fc401cd985b772c7717edf68fbd980aba Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Wed, 28 Nov 2018 11:39:32 +0100 Subject: [PATCH 2/3] =?UTF-8?q?guard=20=F0=9F=99=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index dbcd016..2bf9d4e 100755 --- a/lib/index.js +++ b/lib/index.js @@ -66,7 +66,7 @@ function maskField(field, fn) { field.resolve = function (...args) { try { const out = resolveFn.call(this, ...args); - if (typeof out.then === 'function') { + if (out && typeof out.then === 'function') { out = out.then(undefined, e => fn(e, args)); } return out; From 03c11a1d1194a17b12660aa32fb308e2d0c7b0e7 Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Thu, 29 Nov 2018 06:19:45 +0100 Subject: [PATCH 3/3] Should be let --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 2bf9d4e..d4becdd 100755 --- a/lib/index.js +++ b/lib/index.js @@ -65,7 +65,7 @@ function maskField(field, fn) { field[Processed] = true; field.resolve = function (...args) { try { - const out = resolveFn.call(this, ...args); + let out = resolveFn.call(this, ...args); if (out && typeof out.then === 'function') { out = out.then(undefined, e => fn(e, args)); }