Comments (7)
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.
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.
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.
Okay thanks 😄
from gqlparser.
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.
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.
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 returnerror
.
from gqlparser.
Related Issues (20)
- Github Actions for code linting / testing of PRs? HOT 2
- proposal: Add benchmark
- Unexpected Name "directive"
- Add `Is(err error) bool` to gqlerror to work with `errors.Is` HOT 2
- Can I use this library to generate a graphql response payload?
- Can I parse the type of a field from query and schema?
- Columns are negative for fields with multi-line comments HOT 1
- Can I get the value of a directive on the schema?
- FormatSchemaDocument and FormatQueryDocument support to print comments HOT 2
- Could you please publish a new tag? HOT 2
- Error parsing @join__type directive on supergraph HOT 6
- `errors.As` usage is broken as of v2.5.9
- Bug in gqlerror.List.As()
- Question: can I set a limit to the maximum number of tokens allowed in a request? HOT 1
- [Trivial] Formatter - Descriptions with a double quotes fail to produce correct graphql code.
- Empty argument lists () should be disallowed HOT 2
- call with empty parameter list is considered a parse error HOT 2
- possible denial of service attack due to unlimited errors HOT 7
- New maxTokenLimit default causing breaking change in large schemas HOT 2
- Disallowing empty parens (introduced in v.2.5.12) is a breaking change HOT 1
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 gqlparser.