Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for Objects creation #504

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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