Giter Site home page Giter Site logo

Comments (7)

vektah avatar vektah commented on August 15, 2024 3

you can add something like this at the end of the go.mod

replace github.com/vektah/gqlparser => /home/you/projects/gqlparser

and you're done!

One of the best go modules features

from gqlparser.

vektah avatar vektah commented on August 15, 2024 2

Yeah this is an disappointing gotcha in go. I wish it would get fixed.

Returning error is fine, but its really only returning one type of error and gqlgen is going to reach into it on the other side. This results in interface overhead and type assertion spaghetti.

All that said, would be open to a pr if you want to do the conversion in gqlgen too.

from gqlparser.

robojones avatar robojones commented on August 15, 2024

I've opened a PR for gqlparser but I'm having trouble adding the conversions you mentioned to gqlgen.
How do I make my gqlgen fork use my gqlparser fork?
If this doesn't work, how will I be able to test my changes?

from gqlparser.

robojones avatar robojones commented on August 15, 2024

Okay thanks 😄

from gqlparser.

AndrewWPhillips avatar AndrewWPhillips commented on August 15, 2024

I wasted a lot of time trying to work out why ParseQuery was always returning an error (it wasn't).

func Do(schema *ast.Schema, s string) (r string, err error) {
	var query *ast.QueryDocument
	query, err = parser.ParseQuery(&ast.Source{Name: "query", Input: s})
	if err != nil {
		return // err is not nil even when nil is returned for error from ParseQuery
	}
	...
}

Please just change all error return types to error.

from gqlparser.

JohnStarich avatar JohnStarich commented on August 15, 2024

I hit the same issue when I first picked this up, too. It's definitely a surprising behavior, compared to most (if not all) Go libraries I've worked with over the years.

Returning error is fine, but its really only returning one type of error and gqlgen is going to reach into it on the other side. This results in interface overhead and type assertion spaghetti.

@vektah As an idea, I think most potential type assertions in gqlgen could be handled using the built-in errors package. For example:

err := gqlparser.LoadSchema(files...)
var gqlErr *gqlerror.Error
if !errors.As(err, &gqlErr) {
    return err
}
// do gqlparser-specific error handling here
gqlErr.Message

At the very least, the spaghetti could be cleaner spaghetti 😉

from gqlparser.

fredzqm avatar fredzqm commented on August 15, 2024

I have a counter-argument.

It looks like the parsing library never return errors other than *gqlerror.Error. It would be nice to capture this characteristics and avoid seemingly unsafe conversion from error back to *gqlerror.Error.

Can I propose a pure additive change?

  • For all private methods, return *gqlerror.Error.
  • For some public methods, add a version that returns *gqlerror.Error and make the current method wraps it and return error.

from gqlparser.

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.