cli icon indicating copy to clipboard operation
cli copied to clipboard

Add code generation for GraphQL enum & mutation input types

Open bderrly opened this issue 1 year ago • 2 comments

Add code genration for the input types and enumerations used on the Logscale GraphQL endpoint. The generation code is a modified version of that used in the https://github.com/shurcooL/graphql module.

I am looking for feedback on this as a path forward before I embark on the work to fully incorporate it and remove duplicate types already found in the CLI code.

bderrly avatar Apr 12 '24 16:04 bderrly

Building this made me wonder if the API should be split off into a separate git repository and thus Go module from the CLI. This would remove the need for the go workspace change I made here but also be a cleaner separation of concerns to prevent bleed over into the API patterns to meet the needs of the CLI.

bderrly avatar Apr 12 '24 16:04 bderrly

@SaaldjorMike, one concern that I recall having about this PR is related to the backwards compatibility of the GraphQL API. If we generate this code and tie it to a specific CLI (or eventually API) release version then do we have guarantees that it will work for people running an older version of Logscale? Will we need to generate different releases of the generated API to match each stable Logscale release?

bderrly avatar Sep 04 '24 21:09 bderrly

@bderrly With https://github.com/humio/cli/pull/179 being merged in, we will from now on generate Go code from graphql queries/mutations based of the schema. This means that we going forward will be code-generating the Go code for interacting with the LogScale GraphQL API in https://github.com/humio/cli for things relevant to the humioctl tool, and separately within https://github.com/humio/humio-operator/ for things we need in that project. This is not limited to enums or input types.

The most recent changes refactors how we interact with GraphQL for the humioctl tool. Going forward, you have to

  1. update https://github.com/humio/cli/tree/master/internal/api/humiographql with any new interaction with the LogScale GraphQL API
  2. generate Go-code based on the updated GraphQL queries/mutations: go generate ./...
  3. update humioctl within https://github.com/humio/cli/tree/master/cmd/humioctl so it uses the newly generated code

Right now the code path is as follows: https://github.com/humio/cli/tree/master/cmd/humioctl calls https://github.com/humio/cli/tree/master/internal/api which in turn calls the autogenerated code in https://github.com/humio/cli/blob/master/internal/api/humiographql/humiographql.go.

SaaldjorMike avatar Nov 19 '24 18:11 SaaldjorMike

I am glad to see the changes in #179!

bderrly avatar Nov 23 '24 23:11 bderrly