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

fix directives return nil handling #838

Merged
merged 2 commits into from
Aug 19, 2019
Merged

fix directives return nil handling #838

merged 2 commits into from
Aug 19, 2019

Conversation

vvakame
Copy link
Collaborator

@vvakame vvakame commented Aug 17, 2019

Describe your PR and link to any relevant issues.
related #799 and #819 🤔 ??

.TypeReference.IsNilable provides Go side type information.
directives.gotpl, args.gotpl and input.gotpl use it.
so, I think usage is split to 2 ways.

  1. The value bind to Go field (or variable). ( args.gotpl and input.gotpl )
  2. The value map to graphql.Marshaler. ( directives.gotpl )

I think #2 pattern should use .TypeReference.GQL.NonNull instead of .TypeReference.IsNilable.

My change returns nil, and if it is invalid. caught by here →

if resTmp == nil {
{{- if $field.TypeReference.GQL.NonNull }}
if !ec.HasError(rctx) {
ec.Errorf(ctx, "must not be null")
}
{{- end }}
return graphql.Null
}

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

@vvakame vvakame requested a review from vektah August 17, 2019 04:58
@@ -104,14 +104,12 @@
if err != nil {
return nil, err
}
if tmp == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔
Right, because directives always use interface{} they can always be nil, and we don't care what the datatype is. Unlike everywhere else where we cant compare a string to nil without getting a compile-time error.

👍

@coveralls
Copy link

Coverage Status

Coverage remained the same at 61.817% when pulling f33e09e on fix-directive-nil into 8590ede on master.

@vektah vektah merged commit 7e643fd into master Aug 19, 2019
@vektah vektah deleted the fix-directive-nil branch August 19, 2019 03:25
cgxxv pushed a commit to cgxxv/gqlgen that referenced this pull request Mar 25, 2022
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