question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query/Mutation receives args object with a null prototype

See original GitHub issue

This 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

https://stackoverflow.com/questions/53983315/is-there-a-way-to-get-rid-of-object-null-prototype-in-graphql

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:closed
  • Created 4 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
glassercommented, May 5, 2022

FWIW, I’m pretty sure this is a feature. It means that you can have args with names like toString and constructor and such without them being treated specially.

1reaction
quinten1333commented, May 4, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found