Description
This concerns the token limit config option added last year: #3136
I was testing it and noticed that it doesn't send the correct error to the client because this part of the gqlgen codebase does not correctly interpret the token limit error as a parsing error because it is not returned from the parser as a *gqlerror.Error
, and rather is an errors.errorString
created with fmt.Errorf
:
doc, err := parser.ParseQueryWithTokenLimit(&ast.Source{Input: query}, e.parserTokenLimit)
if err != nil {
gqlErr, ok := err.(*gqlerror.Error)
if ok {
errcode.Set(gqlErr, errcode.ParseFailed)
return nil, gqlerror.List{gqlErr}
}
}
For reference, here is the change in gqlparser that added the new error.
Is there a deeper reason why this function isn't designed to return all errors out of ParseQueryWithTokenLimit
and is instead only checking for *gqlerror.Error
?
I am unsure why they didn't create a gqlerror
over in the parser, but I suspect that's the right place to fix this. That being said, let me know if you'd accept a PR returning all errors, not just gqlerror
, from ParseQueryWithTokenLimit
and I'll submit it.