Skip to content

Commit

Permalink
fix for Objects creation
Browse files Browse the repository at this point in the history
Closes #484
  • Loading branch information
DxCx committed Sep 29, 2016
1 parent a725499 commit a64bb53
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
54 changes: 54 additions & 0 deletions src/execution/__tests__/executor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
});
});
4 changes: 2 additions & 2 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function executeFields(
}
return results;
},
Object.create(null)
{}
);

// If there are no promises, we can just return the object
Expand Down Expand Up @@ -523,7 +523,7 @@ function promiseForObject<T>(
values => values.reduce((resolvedObject, value, i) => {
resolvedObject[keys[i]] = value;
return resolvedObject;
}, Object.create(null))
}, {})
);
}

Expand Down

0 comments on commit a64bb53

Please sign in to comment.