Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ GOLANG_MIGRATE ?= ${PROJECT_BIN}/migrate
bin/golang-migrate:
GOBIN=$(PROJECT_PATH)/bin ${GO} install -tags 'mysql,postgres' github.com/golang-migrate/migrate/v4/cmd/[email protected]

GENQLIENT ?= ${PROJECT_BIN}/genqlient
bin/genqlient:
GOBIN=$(PROJECT_PATH)/bin ${GO} install github.com/Khan/[email protected]

OPENAPI_GENERATOR ?= ${PROJECT_BIN}/openapi-generator-cli
NPM ?= "$(shell which npm)"
bin/openapi-generator-cli:
Expand All @@ -249,7 +253,7 @@ clean/deps:
rm -Rf bin/*

.PHONY: deps
deps: bin/protoc bin/protoc-gen-go bin/protoc-gen-go-grpc bin/golangci-lint bin/goverter bin/openapi-generator-cli bin/envtest
deps: bin/protoc bin/protoc-gen-go bin/protoc-gen-go-grpc bin/golangci-lint bin/goverter bin/openapi-generator-cli bin/envtest bin/genqlient

.PHONY: vendor
vendor:
Expand Down
19 changes: 19 additions & 0 deletions catalog/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
PROJECT_BIN := $(CURDIR)/../bin
OPENAPI_GENERATOR := $(PROJECT_BIN)/openapi-generator-cli
GENQLIENT_BIN ?= $(PROJECT_BIN)/genqlient
GENQLIENT_CONFIG := internal/catalog/genqlient/genqlient.yaml
GENQLIENT_OUTPUT := internal/catalog/genqlient/generated.go
GENQLIENT_SOURCES := $(wildcard internal/catalog/genqlient/queries/*.graphql)
GRAPHQL_SCHEMA := internal/catalog/genqlient/queries/schema.graphql

.PHONY: gen/openapi-server
gen/openapi-server: internal/server/openapi/api_model_catalog_service.go
Expand All @@ -16,10 +21,24 @@ pkg/openapi/client.go: ../api/openapi/catalog.yaml
--ignore-file-override ./.openapi-generator-ignore --additional-properties=isGoSubmodule=true,enumClassPrefix=true,useOneOfDiscriminatorLookup=true
gofmt -w pkg/openapi

.PHONY: gen/graphql
gen/graphql: $(GENQLIENT_OUTPUT)

$(GENQLIENT_OUTPUT): $(GENQLIENT_CONFIG) $(GENQLIENT_SOURCES) $(PROJECT_BIN)/genqlient
$(GENQLIENT_BIN) --config $(GENQLIENT_CONFIG)

.PHONY: download/graphql-schema
download/graphql-schema:
npx get-graphql-schema https://catalog.redhat.com/api/containers/graphql/ > $(GRAPHQL_SCHEMA)

.PHONY: clean-pkg-openapi
clean-pkg-openapi:
while IFS= read -r file; do rm -f "pkg/openapi/$$file"; done < pkg/openapi/.openapi-generator/FILES

.PHONY: clean-graphql
clean-graphql:
rm -f $(GENQLIENT_OUTPUT)

.PHONY: clean-internal-server-openapi
clean-internal-server-openapi:
while IFS= read -r file; do rm -f "internal/server/openapi/$$file"; done < internal/server/openapi/.openapi-generator/FILES
30 changes: 30 additions & 0 deletions catalog/internal/catalog/genqlient/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Using Genqlient with the Red Hat Ecosystem Catalog

This directory contains the necessary files to generate a type-safe Go GraphQL client for the Red Hat Ecosystem Catalog using [genqlient](https://github.com/Khan/genqlient).

### File Structure

- `genqlient.yaml`: The configuration file for `genqlient`. It specifies the location of the GraphQL schema, the directory containing the GraphQL queries, and the output file for the generated code.
- `queries/`: This directory contains the GraphQL schema and query files.
- `schema.graphql`: The GraphQL schema for the Red Hat Ecosystem Catalog API.
- `*.graphql`: Files containing the GraphQL queries.

### Generating the Client

To regenerate the client, you will first need to ensure the required tools are installed by running `make deps` from the project root. Once the tools are installed, you can generate the client by running the following command from the `catalog` directory:

```bash
make gen/graphql
```

This will generate the `generated.go` file in the current directory.

### Downloading the Schema

The `schema.graphql` file can be updated by downloading the latest version from the Red Hat Ecosystem Catalog API. You can do this by running the following command from the `catalog` directory:

```bash
make download/graphql-schema
```

This will download the schema and save it to the correct location. After updating the schema, you should regenerate the client to ensure it is up to date.
389 changes: 389 additions & 0 deletions catalog/internal/catalog/genqlient/generated.go

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions catalog/internal/catalog/genqlient/genqlient.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# genqlient.yaml
schema: queries/schema.graphql
operations:
- "queries/find_repository_images.graphql"
- "queries/get_repository.graphql"
generated: generated.go
package: genqlient
bindings:
DateTime:
type: time.Time
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
query FindRepositoryImages($registry: String!, $repository: String!) {
find_repository_images_by_registry_path(
registry: $registry
repository: $repository
sort_by: [{ field: "creation_date", order: DESC }]
) {
error {
detail
status
}
total
data {
creation_date
last_update_date
repositories {
registry
tags {
name
}
}
parsed_data {
labels {
name
value
}
}
}
}
}
21 changes: 21 additions & 0 deletions catalog/internal/catalog/genqlient/queries/get_repository.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
query GetRepository($registry: String!, $repository: String!) {
get_repository_by_registry_path(
registry: $registry
repository: $repository
) {
error {
detail
status
}
data {
creation_date
last_update_date
release_categories
vendor_label
display_data {
short_description
long_description
}
}
}
}
Loading
Loading