Right now, the various update mutations have the following comment near their Input
type:
You may omit any fields to leave them unchanged
This isn't very easy to use from a client PoV, because the GQL query string needs to change depending on the fields to update.
(Maybe @skip
can be (ab)used to workaround this.)
I wonder if you can use variables to achieve this.
For example, you could use the following mutation:
mutation UpdateRepository($id: Int!, $input: RepoInput!) { updateRepository(id: $id, input: $input) { id } }
And then define a custom RepoInput struct:
type RepoInput struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` // and any other fields you want to support }Then you could set only the fields you want to mutate, marshal the struct to JSON, and then pass it as a variable to GraphQL.
Does GraphQL support using complex types as variables?
Does GraphQL support using complex types as variables?
Yes, this should work.
I've demonstrated this approach in my recent patch to gitsrht-update-hook. It is used to conditionally update the repo description and visibility on push.
Not sure how gqlclientgen can be adapted to work with this approach, needs more investigation.