Khan / genqlient

a truly type-safe Go GraphQL client
MIT License
1.02k stars 99 forks source link

Annotated optional fields with `omitempty` by using new optional config value #308

Open rmennes opened 5 months ago

rmennes commented 5 months ago

It could be useful to annotate optional fields annotate with omitempty when using pointers. By allowing this option, input fields that get removed (and not used is the executed queries) will not break. This gives the library an advantage to be more resilient against break API changes.

To introduce this option, a new optional config value is introduced pointer_omitempty.

If optional: pointer_omitempty is set. We generate

type Task_insert_input struct {
  Id: *int `json:"id,omitempty"`
}

based on

input task_insert_input {
  id: Int
}

The @genqlient(omitempty) config will override the previous defined config.

I have:

rmennes commented 4 months ago

@benjaminjkraft Thanks for the feedback. I updated the PR accordingly. I hope I understood your suggestion correctly.