-
-
Notifications
You must be signed in to change notification settings - Fork 816
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
Mocking Missing Object Prototype #127
Comments
@sebastienbarre could this be related to #115? |
@helfer I'm on the road for some time but if you can come up with a failing test I'll sure look at it... |
@patotoma Could you make a PR with a failing test? That will help us fix the bug faster. |
@helfer I did. Hope it helps. |
hi @helfer , @sebastienbarre it('GraphQL inherits', () => {
const Thread = new GraphQLObjectType({
name: 'Thread',
fields: {
id: {
type: GraphQLString,
resolve(thread, args, ctx) {
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',
},
};
return graphql(jsSchema, testQuery).then((res) => {
expect(Object.getPrototypeOf(res.data.thread)).to.deep.equal(
Object.getPrototypeOf(expected)
);
});
}); and as i thought, it yields the same result:
Then i tried to think why other people did not come up with this, and found out that so, the bug itself is on graphql-js constructing code, |
@patotoma , note that you can use the JSON.parse(JSON.stringify(res)) workaround in the meantime. |
@DxCx oh, interesting. Thanks for getting to the bottom of this! This is somewhat unexpected, so I think it's worth filing on graphql-js and keep this issue here open in the meantime. |
@helfer, done - graphql/graphql-js#484 |
i had to dig the code there for something else and spotted the bug.. |
Please reopen this issue. |
When I tried this mocking example there was a problem with missing prototype on Object types.
Wrapper data object is okay but none of the child objects have its prototype attached. See picture below:
Objects like user and list items in lists array does not contain proto object.
Arrays are okay with its prototypes.
This is causing errors like:
Uncaught TypeError: Cannot convert object to primitive value
for example when I try to console.log() user object.
The text was updated successfully, but these errors were encountered: