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 24, 2016
1 parent a725499 commit b64a5f8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 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)
);
});
});
14 changes: 7 additions & 7 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function buildExecutionContext(
): ExecutionContext {
const errors: Array<GraphQLError> = [];
let operation: ?OperationDefinition;
const fragments: {[name: string]: FragmentDefinition} = Object.create(null);
const fragments: {[name: string]: FragmentDefinition} = Object.create({});
documentAST.definitions.forEach(definition => {
switch (definition.kind) {
case Kind.OPERATION_DEFINITION:
Expand Down Expand Up @@ -243,8 +243,8 @@ function executeOperation(
exeContext,
type,
operation.selectionSet,
Object.create(null),
Object.create(null)
Object.create({}),
Object.create({})
);

const path = [];
Expand Down Expand Up @@ -362,7 +362,7 @@ function executeFields(
}
return results;
},
Object.create(null)
Object.create({})
);

// 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))
}, Object.create({}))
);
}

Expand Down Expand Up @@ -957,8 +957,8 @@ function completeObjectValue(
}

// Collect sub-fields to execute to complete this value.
let subFieldASTs = Object.create(null);
const visitedFragmentNames = Object.create(null);
let subFieldASTs = Object.create({});
const visitedFragmentNames = Object.create({});
for (let i = 0; i < fieldASTs.length; i++) {
const selectionSet = fieldASTs[i].selectionSet;
if (selectionSet) {
Expand Down

0 comments on commit b64a5f8

Please sign in to comment.