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

Schema fields with underscore #357

Closed
rodrigo-brito opened this issue Sep 28, 2018 · 4 comments
Closed

Schema fields with underscore #357

rodrigo-brito opened this issue Sep 28, 2018 · 4 comments
Labels
bug Something isn't working

Comments

@rodrigo-brito
Copy link
Contributor

When we generate a schema with underscore within field names, the gqlgen is including it as resolver.

Expected Behaviour

Generate a field in User model with name MyNumber and type *int`.

Actual Behavior

type userResolver struct{ *Resolver }

func (r *userResolver) MyNumber(ctx context.Context, obj *User) (*int, error) {
	panic("not implemented")
}

Minimal graphql.schema and models to reproduce

type Query {
	user(): User
}

type User {
	my_number: Int
}
@rodrigo-brito
Copy link
Contributor Author

rodrigo-brito commented Sep 28, 2018

I inspect the generator code and check some outputs. I notice that the field GoFieldName is empty on final step, maybe it was lost during the validation process, I don't found where it happened.

codegen.(*Field).ShortResolverDeclaration

GQLName: "my_number",
GoFieldType:    0,
GoReceiverName: "",
GoFieldName:    "",

@mathewbyrne
Copy link
Contributor

@rodrigo-brito thanks for the report. Can I ask, did you let gqlgen generate you a model, or did you provide your own User struct? It looks like regardless, the generated resolver does remove the underscores from the method name, so we should at least make an attempt to match to a user struct.

@mathewbyrne mathewbyrne added the bug Something isn't working label Oct 1, 2018
@rodrigo-brito
Copy link
Contributor Author

rodrigo-brito commented Oct 1, 2018

No, I used this simple example in the unit test of generator. The GQLGen example doesn't has a target model. But it happens in both of cases.

@rodrigo-brito
Copy link
Contributor Author

@mathewbyrne I tried to debug it yesterday, but I don't found where it was checked. I will try to open a PR today, do you have some suspect about the issue?

I notice that fields settings on gqlgen.yml solves the problem when the name was informed directly. Ex:

User:
    model: github.com/foo/bar/models.User
    fields:
      my_number:
        fieldName: MyNumber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants