Query/Mutation receives args object with a null prototype
See original GitHub issueThis bug report should include:
- A short, but descriptive title. The title doesn’t need “Apollo” in it.
- The package name and version of Apollo showing the problem.
- [O] If applicable, the last version of Apollo where the problem did not occur.
- The expected behavior.
- The actual behavior.
- A simple, runnable reproduction!
Version: latest apollo-server-core (2.8.1)
Related SO
Actual behavior
This has been discussed on SO, but the solution is less than ideal. Serializing things through json is silly overhead. If anything it is confusing and undefined/undocumented behavior. I’m filing this as a bug since a mutation should get an object passed in with a prototype. A query receives an args
object with a prototype. This behavior should at least be made consistent and ideally an object with a prototype.
Example code:
Mutation: {
create: async (_, args, context, info) => {
console.log(args.thing);
},
},
Output:
[Object: null prototype] {
id: '00112233445566'
}
Expected behavior
{
id: '00112233445566'
}
Current workaround
console.log(JSON.parse(JSON.stringify(args.thing)))
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (4 by maintainers)
Top Results From Across the Web
Is there a way to get rid of [Object: null prototype] in GraphQL
Try destructuring assignment with the args parameter. Your problem happens because args is an object that holds the mutation arguments.
Read more >type-graphql/Lobby - Gitter
@Favna [Object: null prototype] means that the object was created by using ... I can't get the master branch to build: tsc --build...
Read more >JavaScript and object with null prototype - LinkedIn
When application receives the request - it will use request headers (key-value properties) and request body to handle the request. But both ...
Read more >Getting Started – GraphQL Yoga
To get data from a GraphQL schema, you need to write a GraphQL operation (often referred ... You can ignore the [Object: null...
Read more >Untitled
undefined"){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return G(t,arguments,Q(this).constructor)}r.prototype=Object.create(t.prototype ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FWIW, I’m pretty sure this is a feature. It means that you can have args with names like
toString
andconstructor
and such without them being treated specially.I made a simple library to fix this. The library is faster than going to json and back because it works in place. Link: https://www.npmjs.com/package/normalize-object-inheritance