From 087d4954da7a518514ad6ba711831faea22a2358 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 17 Oct 2016 16:26:21 +1300 Subject: [PATCH] Added rootValue execution. Fixes #15 --- src/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 6668ea8..592fa67 100644 --- a/src/index.js +++ b/src/index.js @@ -186,12 +186,23 @@ const createResult = async ({ } } + // Execute rootValue functions if present + const executedRootValue = Object.keys(rootValue).reduce((accumulator, rootValueKey) => { + const rootValueValue = rootValue[rootValueKey]; + if (typeof rootValueValue === 'function') { + accumulator[rootValueKey] = rootValueValue({}, request); + } else { + accumulator[rootValueKey] = rootValueValue; + } + return accumulator; + }, {}); + // Perform the execution, reporting any errors creating the context. try { return await execute( schema, documentAST, - rootValue, + executedRootValue, context, variables, operationName