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 Embedded Pointer #358

Merged
merged 2 commits into from
Oct 2, 2018
Merged

Fix Embedded Pointer #358

merged 2 commits into from
Oct 2, 2018

Conversation

mathewbyrne
Copy link
Contributor

Fixes the first part of #356

codegen.findField was not accounting for anonymous pointer types and was generating a redundant resolver. This change fixes this so that these pointers are unwrapped and the element type is considered recursively as a match for the field.

fieldType := field.Type()

if ptr, ok := fieldType.(*types.Pointer); ok {
fieldType = ptr.Elem()
Copy link
Collaborator

Choose a reason for hiding this comment

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

what happens when the embedded pointer is null? Worth adding a test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, good question, nothing will happen here. But I would expect a runtime panic. What do you think we should do?

Copy link
Collaborator

Choose a reason for hiding this comment

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

can it return null and do the normal error bubbling dance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah ok, I'll come up with a test. Might involve slightly more messing around here since we'd need to know if it was a pointer that we matched to in template.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, after reviewing this a bit I think this is going to be a bigger change. Embeds can be pathological when they are more than a single embed deep with a mix of pointers thrown in.

I think for now we merge this and maybe log that as a separate issue.

Copy link
Collaborator

@vektah vektah left a comment

Choose a reason for hiding this comment

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

LGTM

@mathewbyrne mathewbyrne merged commit b836a97 into master Oct 2, 2018
@vektah vektah deleted the fix-embedded-pointer branch October 2, 2018 03:11
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.

2 participants