Skip to content

Catd graphql play #2100

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ require (
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/graphql-go/graphql v0.8.1 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.0 // indirect
github.com/h2non/filetype v1.1.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5T
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA=
github.com/gosuri/uitable v0.0.4 h1:IG2xLKRvErL3uhY6e1BylFzG+aJiwQviDDTfOKeKTpY=
github.com/gosuri/uitable v0.0.4/go.mod h1:tKR86bXuXPZazfOTG1FIzvjIdXzd0mo4Vtn16vt0PJo=
github.com/graphql-go/graphql v0.8.1 h1:p7/Ou/WpmulocJeEx7wjQy611rtXGQaAcXGqanuMMgc=
github.com/graphql-go/graphql v0.8.1/go.mod h1:nKiHzRM0qopJEwCITUuIsxk9PlVlwIiiI8pnJEhordQ=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20210315223345-82c243799c99 h1:JYghRBlGCZyCF2wNUJ8W0cwaQdtpcssJ4CgC406g+WU=
Expand Down
106 changes: 106 additions & 0 deletions internal/catalogd/graphql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# GraphQL Integration

This package provides dynamic GraphQL schema generation for operator catalog data, integrated into the catalogd storage server.

## Usage

The GraphQL endpoint is now available as part of the catalogd storage server at:

```
{catalog}/api/v1/graphql
```

Where `{catalog}` is replaced by the actual catalog name at runtime.

## Example Usage

### Making a GraphQL Request

```bash
curl -X POST http://localhost:8080/my-catalog/api/v1/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "{ summary { totalSchemas schemas { name totalObjects totalFields } } }"
}'
```

### Sample Queries

#### Get catalog summary:
```graphql
{
summary {
totalSchemas
schemas {
name
totalObjects
totalFields
}
}
}
```

#### Get bundles with pagination:
```graphql
{
bundles(limit: 5, offset: 0) {
name
package
version
}
}
```

#### Get packages:
```graphql
{
packages(limit: 10) {
name
description
}
}
```

#### Get bundle properties (union types):
```graphql
{
bundles(limit: 5) {
name
properties {
type
value {
... on PropertyValueFeaturesOperatorsOpenshiftIo {
disconnected
cnf
cni
csi
fips
}
}
}
}
}
```

## Features

- **Dynamic Schema Generation**: Automatically discovers schema structure from catalog metadata
- **Union Types**: Supports complex bundle properties with variable structures
- **Pagination**: Built-in limit/offset pagination for all queries
- **Field Name Sanitization**: Converts JSON field names to valid GraphQL identifiers
- **Catalog-Specific**: Each catalog gets its own dynamically generated schema

## Integration

The GraphQL functionality is integrated into the `LocalDirV1` storage handler in `internal/catalogd/storage/localdir.go`:

- `handleV1GraphQL()`: Handles POST requests to the GraphQL endpoint
- `createCatalogFS()`: Creates filesystem interface for catalog data
- `buildCatalogGraphQLSchema()`: Builds dynamic GraphQL schema for specific catalogs

## Technical Details

- Uses `declcfg.WalkMetasFS` to discover schema structure
- Generates GraphQL object types dynamically from discovered fields
- Creates union types for bundle properties with variable structures
- Supports all standard GraphQL features including introspection
Loading
Loading