Comments (4)
I guess attaching the error to the result and sending it would be able to give you more information as to what part of the query or mutation caused the error but that could still be ambigious.
And shouldn't we remove the panic'king or is it better this way (since we get stack traces)
from graphql.
In this issue, I was asking two things.
- whether the spec allows it?
- then should we support it.
I don't think it is the responsibility of a library to capture the stack trace during development , and should never expose it to the end user. I use https://github.com/facebookgo/stackerr to wrap my resolvers and logs them. I think currently we are using defer/panic for easy exit from error case then explicitly passing it through the hierarchy as I never seen the stack logged.
from graphql.
Thanks for bringing this up @bsr203 👍
According the specification I think we should include the execution errors along with the result data.
If the data entry in the response is not null, the errors entry in the response may contain any errors that occurred during execution. If errors occurred during execution, it should contain those errors.
To confirm it, I've wrote a small example using the reference implementation - graphql-js
, which does include execution errors and result data:
import {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString
} from 'graphql';
var schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
bar: {
type: GraphQLString,
resolve() {
return 'bar';
}
},
foo: {
type: GraphQLString,
resolve() {
throw new Error('foo error');
}
}
}
})
});
var query = '{ bar foo }';
graphql(schema, query).then(result => {
console.log(result);
});
$ babel-node index.js
{ data: { bar: 'bar', foo: null },
errors: [ { [Error: foo error] message: 'foo error' } ] }
I guess attaching the error to the result and sending it would be able to give you more information as to what part of the query or mutation caused the error but that could still be ambiguous.
And shouldn't we remove the panic'king or is it better this way (since we get stack traces)
Thanks for the insights @pyros2097, yes very valid to think it looks ambiguous, but you might want to consider it that it would be very helpful to know the execution errors and that other fields were resolved correctly, so for debugging purposes it's great - also having partial data available might be useful for some clients that indeed would like to implement some strategies when execution error occur but still have access the resolved partial data.
from graphql.
thanks chris for testing out and confirming the behavior. I too agree with @pyros2097 , but was saying this library shouldn't be capturing stack trace to aid debugging and it is trivial to wrap the resolver in a typical defer/panic/recover mechanism. thanks again for quick response from both of you. cheers.
from graphql.
Related Issues (20)
- Cannot parse GitHub public schema v4
- Create graphql schema from string HOT 3
- The code generator does not take into account naming conflicts HOT 1
- How to take metro in graphql out of the solve?
- Is this project still mantained? HOT 2
- New release?
- Potential goroutine leak in TestContextDeadline HOT 1
- Enums with trailing white space cause error.
- Playground
- make union input type ? it just have output union type
- With fiber HOT 1
- Printing GraphQL documents is slow HOT 1
- Bug with underscore and same name in keys from json response
- MongoDB _id field
- Printer returns invalid SDL if Block String comment contains double-quote
- When using custom scalar types, it's crucial to provide error feedback to users when issues arise with their submitted data. However, triggering exceptions within the ParseValue and ParseLiteral methods can lead to program crashes when using the graphql.Do method. This prevents the necessary error messages from being delivered to users.
- String type no longer recongised HOT 1
- Is it possible to go from `*graphql.Schema` to an ast node? HOT 1
- Error handling HOT 1
- Disabling Field Suggestions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql.