shurcooL / githubv4

Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql).
MIT License
1.12k stars 89 forks source link

Variable input of type MergePullRequestInput! was provided invalid value #48

Open ryboe opened 5 years ago

ryboe commented 5 years ago
var m struct {
    MergePullRequest struct {
        PullRequest struct {
            ID githubv4.ID
        }
    } `graphql:"mergePullRequest(input:$input)"`
}
squash := githubv4.PullRequestMergeMethodSquash
input := githubv4.MergePullRequestInput{
    PullRequestID: githubv4.ID(prID),
    MergeMethod:   &squash, // <<<<<<<<<<<<<<<
}

...

err := c.client.Mutate(ctx, &m, input, nil)
fmt.Println(err)
Variable input of type MergePullRequestInput! was provided invalid value

MergeMethod is a *PullRequestMergeMethod. The values for PullRequestMergeMethod are all constants. I passed githubv4.PullRequestMergeMethodSquash the only way I know how, by copying the constant to a variable and then passing a pointer to the variable, but I got the error you see above. Am I doing something wrong?

I double-checked the GitHub settings for this repo and they do allow squash merging.

dmitshur commented 5 years ago

I don't see anything wrong in that snippet. Having to create a local variable when optional fields have constant enum values is unfortunate (and maybe should be improved, in a separate issue), but the way you've done it is fine and should produce expected results.

The problem may be elsewhere. Was there any more detail included in the error message?