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

Generate fails when building a mutation that takes enum as input. #194

Closed
DAlperin opened this issue May 12, 2022 · 2 comments · Fixed by #195
Closed

Generate fails when building a mutation that takes enum as input. #194

DAlperin opened this issue May 12, 2022 · 2 comments · Fixed by #195
Labels
bug Something isn't working

Comments

@DAlperin
Copy link

Describe the bug
Generate fails when building a mutation that takes enum as input.

To Reproduce
The following fails to generate:

# Schema snippet
enum IPAddressType {
  v4
  v6
}
# Query snippet
mutation AllocateIpAddress($app: ID!, $region: String, $type: IPAddressType) {
    allocateIpAddress(input: {
        appId: $app,
        region: $region,
        type: $type
    }) {
        app {
            name
        }
    }
}
genqlient internal error: failed to gofmt code:
	680:5: expected 'IDENT', found 'type' (and 8 more errors)
	680:5: expected 'IDENT', found 'type' (and 8 more errors)
	680:5: expected 'IDENT', found 'type' (and 8 more errors)
	680:5: expected 'IDENT', found 'type' (and 8 more errors)
	680:5: expected 'IDENT', found 'type' (and 8 more errors)
	680:5: expected 'IDENT', found 'type' (and 8 more errors)
	680:5: expected 'IDENT', found 'type' (and 8 more errors)
	680:5: expected 'IDENT', found 'type' (and 8 more errors)
	680:5: expected 'IDENT', found 'type' (and 8 more errors)---source code---

The following slight change generates without issue:

mutation AllocateIpAddress($app: ID!, $region: String) {
    allocateIpAddress(input: {
        appId: $app,
        region: $region,
        type: v4
    }) {
        app {
            name
        }
    }
}

Expected behavior
The generator should successfully complete.

genqlient version
0.4.0

@DAlperin DAlperin added the bug Something isn't working label May 12, 2022
@benjaminjkraft
Copy link
Collaborator

Thanks for the report. I think the problem here is actually that the variable name type is reserved in Go! I'll leave this bug open to remind us to add a better error message (or munge it*) but the best thing to do is just to change the variable name in the mutation.

*in principle munging it would be nicer, especially since the argument name in Go is really just for the documentation, the user doesn't have to write it. But I'm not sure if that could cause worse collisions, possibly ones that won't get caught at type check. So an error may be easier to think about.

@DAlperin
Copy link
Author

Ah! That makes sense, can't believe I didn't catch that. Thank you for the quick response!

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

Successfully merging a pull request may close this issue.

2 participants