diff --git a/src/execution/__tests__/executor-test.js b/src/execution/__tests__/executor-test.js index 017cb333b1..f0446848d5 100644 --- a/src/execution/__tests__/executor-test.js +++ b/src/execution/__tests__/executor-test.js @@ -843,4 +843,58 @@ describe('Execute: Handles basic execution tasks', () => { }); }); + it('returns proper Javascript Objects', async () => { + const Thread = new GraphQLObjectType({ + name: 'Thread', + fields: { + id: { + type: GraphQLString, + resolve(thread) { + return thread.id; + }, + }, + name: { + type: GraphQLString, + resolve() { + return 'Lorem Lipsum'; + }, + }, + }, + }); + const Query = new GraphQLObjectType({ + name: 'Query', + fields: { + thread: { + type: Thread, + args: { + id: { + type: GraphQLString, + }, + }, + resolve(root, args) { + return {id: args.id}; + } + }, + }, + }); + const jsSchema = new GraphQLSchema({ + query: Query, + }); + const testQuery = `query abc{ + thread(id: "67"){ + id + name + } + }`; + const expected = { + thread: { + id: '67', + name: 'Lorem Ipsum', + }, + }; + const res = await execute(jsSchema, parse(testQuery)); + expect(Object.getPrototypeOf(res.data.thread)).to.deep.equal( + Object.getPrototypeOf(expected) + ); + }); }); diff --git a/src/execution/execute.js b/src/execution/execute.js index 1875a3bc28..d32f40c193 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -362,7 +362,7 @@ function executeFields( } return results; }, - Object.create(null) + {} ); // If there are no promises, we can just return the object @@ -523,7 +523,7 @@ function promiseForObject( values => values.reduce((resolvedObject, value, i) => { resolvedObject[keys[i]] = value; return resolvedObject; - }, Object.create(null)) + }, {}) ); }