Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always call resolveFieldFinishFn even if an error occurs in resolve. #526

Merged
merged 1 commit into from
Feb 5, 2020

Conversation

purple4reina
Copy link
Contributor

Hello! We at New Relic are currently working to create an Extension for tracing GraphQL calls using this package.

One thing that I have noticed is that if your resolve field function returns an error, the graphql.ResolveFieldFinishFunc for that field is never called. This means that users will not see any metrics or data about this error or this work done despite it clearly having happened.

"erred": &graphql.Field{
    Type: graphql.String,
    Resolve: func(p graphql.ResolveParams) (interface{}, error) {
        // because an error is returned here, the graphql.ResolveFieldFinishFunc
        // is never called and no segments or metrics are created for this work
        return "", errors.New("ooops")
    },
},

The fix is pretty simple, just call the finish func before panicking the error. This is similar to what is done for the other Extension methods (parse, validate, and execute) which all call their finish functions even if an error occurs.

Please let me know what you think. I'm happy to make any changes you request.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.344% when pulling 0c12f38 on purple4reina:resolve-errors into 2e2b648 on graphql-go:master.

@chris-ramon
Copy link
Member

Thanks a lot @purple4reina –– neat to know that you are using the lib and working on a tracing extension.

It looks good to me since ResolveFieldFinishFunc is mean to return the resolve function error if is the case:

graphql/extensions.go

Lines 26 to 27 in bed865f

// ResolveFieldFinishFunc is called with the result of the ResolveFn and the error it returned
ResolveFieldFinishFunc func(interface{}, error)

@Fontinalis could you give a look to this PR when you get a chance please ?

Copy link
Member

@chris-ramon chris-ramon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 –– Neat fix @purple4reina 💯 🚢

@chris-ramon chris-ramon merged commit d925012 into graphql-go:master Feb 5, 2020
@purple4reina purple4reina deleted the resolve-errors branch February 5, 2020 17:23
@purple4reina
Copy link
Contributor Author

Thanks a ton @chris-ramon! This change makes our lives so much easier and we really appreciate it! Any chance you know about when you'll be putting out another release?

@chris-ramon
Copy link
Member

good call @purple4reina, I've released a new version: https://github.com/graphql-go/graphql/releases/tag/v0.7.9, which includes this PR, thanks a lot again 👍 cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants