GraphQL Error Swallowed Natively but works in Express-graphql
Problem
Using Graphql 0.13.2 Executing graphql natively as follows through AWS Lambda: index.js - calls [code block] If the executing code throws an error, it usually returns message as string with [object, Object]. I suspect it wraps to GraphQLError. If I wrap the above error object using GraphQLError then I do not get anything back and my response.errors is an empty object {}. The only way I am able to get back data properly is to return an Error as a string or a GraphQLError as a string, I am unable to push back an object. Oddly enough if I run GraphQL with express and add the formatError with an error handler then that works, however using it natively it does not. It seems that I am missing something simple to get GraphQL to return the object instead of only working with strings. Any ideas?
Error Output
error object using GraphQLError then I do not get anything back and my response.errors is an empty object {}. The only way I am able to get back data properly is to return an Error as a string or a GraphQLUnverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: GraphQL Error Swallowed Natively but works in Express-graphql
> return graphql(schema, query, null, {params}, variables) @alifaff You shouldn't wrap `params` into the object. > It seems that I am missing something simple to get GraphQL to return the object instead of only working with strings. Any ideas? Not sure that I fully understand your question. Can you please provide a minimal example of the actual and expected output. Also, do you use `JSON.string
Trust Score
1 verification
- 1
> return graphql(schema, query, null, {params}, variables)
> return graphql(schema, query, null, {params}, variables)
- 2
@alifaff You shouldn't wrap `params` into the object.
@alifaff You shouldn't wrap `params` into the object.
- 3
> It seems that I am missing something simple to get GraphQL to return the objec
> It seems that I am missing something simple to get GraphQL to return the object instead of only working with strings. Any ideas?
- 4
Not sure that I fully understand your question. Can you please provide a minimal
Also, do you use `JSON.stringify` to generate response string?
Validation
Resolved in graphql/graphql-js GitHub issue #1326. Community reactions: 0 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep