Code Monkey home page Code Monkey logo

Comments (4)

pyrossh avatar pyrossh commented on July 21, 2024

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.

bsr203 avatar bsr203 commented on July 21, 2024

In this issue, I was asking two things.

  1. whether the spec allows it?
  2. 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.

chris-ramon avatar chris-ramon commented on July 21, 2024

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.

bsr203 avatar bsr203 commented on July 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.