~sircmpwn/sr.ht#310: 
graphql: investigate better Input types for updates

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.)

Status
REPORTED
Submitter
~emersion
Assigned to
No-one
Submitted
1 year, 4 months ago
Updated
1 year, 3 months ago
Labels
No labels applied.

~adnano 1 year, 4 months ago

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?

~emersion 1 year, 4 months ago

Does GraphQL support using complex types as variables?

Yes, this should work.

~adnano 1 year, 3 months ago

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.

~emersion 1 year, 3 months ago

Not sure how gqlclientgen can be adapted to work with this approach, needs more investigation.

Register here or Log in to comment, or comment via email.