Code Monkey home page Code Monkey logo

Comments (5)

bbuck avatar bbuck commented on July 21, 2024

I've noticed a similar issue with errors when passing nil as the value for a types.GraphQLNonNull(...) which should throw an error.

from graphql.

sogko avatar sogko commented on July 21, 2024

Hi guys,

Currently user functions (such as ParseLiteral, ResolveFn etc) that are passed into configs and executed by the executor. Any panics are caught/recovered by the executor and then be returned as Errors in GraphQLResult struct.

type GraphQLResult struct {
    Data   interface{}                           `json:"data"`
    Errors []graphqlerrors.GraphQLFormattedError `json:"errors,omitempty"`
}

As to why the current executor implementation uses panic instead of returning a more idiomatic error value, I chose to defer from making that decision, instead made a straight port from graphql-js which throws error everywhere and anywhere, and wait to hear from the community :)

Personally I would love to see a move to a more go-idiomatic library as the project shapes itself, so I would vote for (interface{}, error) return signature for user functions as well.

@bbuck That's interesting. Could you share the JSON response from the query? (If this is off-topic, maybe in a separate issue)

Thanks guys!

from graphql.

bbuck avatar bbuck commented on July 21, 2024

I definitely think a move to a more idiomatic approach would be better. As far as I understood the graphql-js implementation was that it was only created to server as an example of how you could implement it. I'm pretty sure making the necessary alterations to bring a GraphQL server library to Go would make sense to apply Go processes to it.

There is some merit in keeping similarities, I'm not necessarily encouraging rebuilding everything, but where it makes sense I definitely think that's the best. And this is one place I think it does make sense. When I work in Go, I've very accustomed to , err assignments as well as returning an error from my own functions so it wouldn't be something I wouldn't already expect to do. However, writing a panic line in production (so to speak) code would be something I'd be uncomfortable doing.

Also, @sogko, in regards to my last comment. Disregard. After running again to get your requested information I see the problem is with my previously posted issue on GraphQLInt ignoring other integer types. If I return a value, everything gives me 0, which is definitely wrong. I feel like it should have been throwing nil to begin with. But if I return nil directly the proper errors are reported.

from graphql.

pyrossh avatar pyrossh commented on July 21, 2024

There seems to be another issue also if I panic in the ParseValue function it causes the process to crash. I think you are recovering only in the ParseLiteral function I will inspect more on this

types.NewGraphQLScalarType(types.GraphQLScalarTypeConfig{
        Name: name,
        Serialize: func(value interface{}) interface{} {
            return value
        },
        ParseValue: func(value interface{}) interface{} {
                       panic("Not String Type")
        return value
        },
        ParseLiteral: func(valueAst ast.Value) interface{} {
                      return valueAst
        },

from graphql.

sogko avatar sogko commented on July 21, 2024

Cleaning up the issues tracker. Closing this issue since the original issue brought up by @pyros2097 regarding return signature (i.e. (interface{}, error) has been bought up in #44. Consider continuing the discussion there.

Regarding the panic in ParseValue(), please consider creating another issue. If I have the time, I'll try to verify it and will open the issue for you.

Thanks and cheers guys!

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.