shurcooL / githubv4

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

Can't pass multiple mutation inputs in variables #70

Open haines opened 4 years ago

haines commented 4 years ago

To do multiple mutations in a single request, it seems like you have to arbitrarily choose one of them to receive $input, and pass that input in the input argument to Mutate, while the other mutations have their inputs in variables.

I attempted to put both inputs in variables leaving input as nil, but this segfaults:

var mutation struct {
    MarkPullRequestReadyForReview struct {
        ClientMutationID string
    } `graphql:"markPullRequestReadyForReview(input: $markPullRequestReadyForReviewInput)"`
    AddAssigneesToAssignable struct {
        ClientMutationID string
    } `graphql:"addAssigneesToAssignable(input: $addAssigneesToAssignableInput)"`
}

variables := map[string]interface{}{
    "markPullRequestReadyForReviewInput": githubv4.MarkPullRequestReadyForReviewInput{
        PullRequestID: pullRequestID,
    },
    "addAssigneesToAssignableInput": githubv4.AddAssigneesToAssignableInput{
        AssignableID: pullRequestID,
        AssigneeIDs:  []githubv4.ID{assigneeID},
    },
}

err := c.githubv4.Mutate(context.Background(), &mutation, nil, variables)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x98 pc=0x7f4126]

goroutine 21 [running]:
github.com/shurcooL/graphql.writeArgumentType(0xd38800, 0xc00048e4b0, 0x0, 0x0, 0xc00013e001)
  /go/pkg/mod/github.com/shurcoo!l/graphql@v0.0.0-20181231061246-d48a9a75455f/query.go:58 +0x26
github.com/shurcooL/graphql.queryArguments(0xc00048e3f0, 0xc0005ae500, 0xc000632000)
  /go/pkg/mod/github.com/shurcoo!l/graphql@v0.0.0-20181231061246-d48a9a75455f/query.go:46 +0x368
github.com/shurcooL/graphql.constructMutation(0xa23fa0, 0xc0005ae500, 0xc00048e3f0, 0x7f93d5f3cfe8, 0x0)
  /go/pkg/mod/github.com/shurcoo!l/graphql@v0.0.0-20181231061246-d48a9a75455f/query.go:24 +0x76
github.com/shurcooL/graphql.(*Client).do(0xc0000a4b80, 0xd44980, 0xc000126010, 0x1, 0xa23fa0, 0xc0005ae500, 0xc00048e3f0, 0x0, 0x0)
  /go/pkg/mod/github.com/shurcoo!l/graphql@v0.0.0-20181231061246-d48a9a75455f/graphql.go:54 +0x696
github.com/shurcooL/graphql.(*Client).Mutate(...)
  /go/pkg/mod/github.com/shurcoo!l/graphql@v0.0.0-20181231061246-d48a9a75455f/graphql.go:44
github.com/shurcooL/githubv4.(*Client).Mutate(0xc0000a8110, 0xd44980, 0xc000126010, 0xa23fa0, 0xc0005ae500, 0x0, 0x0, 0xc00048e3f0, 0x0, 0x0)
  /go/pkg/mod/github.com/shurcoo!l/githubv4@v0.0.0-20200627185320-e003124d66e4/githubv4.go:55 +0xcc

I think it'd make sense to allow input to be nil if variables is given.

vpanta commented 1 year ago

I dunno if it is a good enough fix, but looking at that prospective PR it seems pretty simple. Any chance it can get escalated?