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.

[object Object] is returned from a binding when resolver throws an error

See original GitHub issue

I’ve noticed that when a query/mutation is executed via a graphql binding an [Object object] error is returned. This behaviour is observed when an error is thrown in resolver as a part of a business logic.

const resolvers = {
  Query: {
    test: async (parent, args, context) => {
      // some random _id that is passed as a query arg 
      const _id = '507f1f77bcf86cd799439011';
      const binding = await context.bindings.organisations.query.organisation({ _id }, '{ _id }', { context: { foo: 'foo' } });
      return 'foo';
    }
  }
};

organisation query throws an Apollo error when organisation is not found by id.

screenshot 2018-11-06 at 23 20 29

Funny enough the cause is an old version of graphql-tools and the PR for it was already made: https://github.com/graphql-binding/graphql-binding/pull/161

When will it be merged?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Pajkcommented, Dec 11, 2018

I found a workaround at https://github.com/apollographql/graphql-tools/issues/480#issuecomment-444318754.

For anyone interested:

import { onError } from 'apollo-link-error'
import { createHttpLink } from 'apollo-link-http'

// ...

const errorLink = onError(args => {
	if (args.graphQLErrors && args.graphQLErrors.length === 1) {
		args.response.errors = args.graphQLErrors.concat(new GraphQLError(''))
	}
})

class XXXBinding extends Binding {
	constructor(uri: string) {
		const schema = makeRemoteExecutableSchema({
			schema: fs.readFileSync(schemaPath, 'utf-8'),
			link: errorLink.concat(
				createPersistedQueryLink().concat(createHttpLink({ uri, fetch }))
			),
		})
		super({ schema })
	}
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to return both error and data in a graphql resolver? - Help
GraphQL works with both object & field-level resolvers. Partial errors works as long as they're in different fields.
Read more >
Can Spring MVC catch an exception and return a ...
So I have two questions about how to do this: 1) Can I manually create the BindingResult object out of a list of...
Read more >
A Definitive Guide to Handling Errors in JavaScript - Kinsta
Errors in JavaScript are objects shown whenever a programming error occurs. ... An exception is an error object that has been thrown.
Read more >
A mostly complete guide to error handling in JavaScript.
Learn how to deal with errors and exceptions in synchronous and asynchronous JavaScript code.
Read more >
DataBinder (Spring Framework 6.0.3 API)
public class DataBinder extends Object implements PropertyEditorRegistry, TypeConverter ... Return the strategy for processing binding errors. BindingResult.
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