Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code generation for GraphQL enum & mutation input types #155

Closed
wants to merge 13 commits into from

Conversation

bderrly
Copy link
Contributor

@bderrly bderrly commented Apr 12, 2024

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 bderrly requested a review from a team as a code owner April 12, 2024 16:07
@bderrly
Copy link
Contributor Author

bderrly commented Apr 12, 2024

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
Copy link
Contributor Author

bderrly commented Sep 4, 2024

@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?

@SaaldjorMike
Copy link
Member

SaaldjorMike commented Nov 19, 2024

@bderrly With #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.

@bderrly
Copy link
Contributor Author

bderrly commented Nov 23, 2024

I am glad to see the changes in #179!

@bderrly bderrly closed this Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants