Skip to content
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ jobs:
with:
python-version: 3.13

- name: Install Ariadne-codegen
run: pip install ariadne-codegen
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Install Ariadne-codegen and gqlg
run: |
pip install ariadne-codegen
npm install -g gqlg

- uses: pre-commit/action@v3.0.1
test:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# AI tools settings
/.claude/settings.local.json

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's introduce our new co-worker ☺️

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

welcome claude

8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ repos:

- repo: local
hooks:
- id: gqlg
name: gqlg
entry: bash -c
echo "Running gqlg" && \
gqlg --schemaFilePath ./openhexa/cli/graphql/schema.generated.graphql --destDirPath ./openhexa/cli/graphql/queries/gqlg --depthLimit 3
language: system
types: [ graphql ]
pass_filenames: false
- id: ariadne-codegen
name: ariadne-codegen
entry: bash -c
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,42 @@ You can run the tests using pytest:
pytest
```

### Codegen from the GraphQL schema

We use code generation to create Python client code from our GraphQL schema. This involves two tools:

1. [**ariadne-codegen**](https://github.com/mirumee/ariadne-codegen): Generates typed Python GraphQL client code from GraphQL files
2. [**gqlg**](https://github.com/timqian/gql-generator): Automatically generates comprehensive GraphQL queries for all queries and mutations defined in the schema

The code generation process:

1. The GraphQL schema is manually taken from the [Openhexa Monorepo](https://github.com/BLSQ/openhexa-app/blob/main/frontend/schema.generated.graphql) and saved in [`openhexa/cli/graphql/schema.generated.graphql`](https://github.com/BLSQ/openhexa-sdk-python/blob/main/openhexa/cli/graphql/schema.generated.graphql)
2. `gqlg` generates all possible queries/mutations from the schema with a depth limit of 3
3. `ariadne-codegen` uses both the schema and queries to generate typed Python client code

To run code generation manually:

```shell
npm install gql-generator -g
pip install ariadne-codegen
gqlg --schemaFilePath ./openhexa/cli/graphql/schema.generated.graphql --destDirPath ./openhexa/cli/graphql/queries/gqlg --depthLimit 3
ariadne-codegen
```

Both tools run automatically via pre-commit hooks and CI/CD when GraphQL files are modified.

You can add new queries or mutations in the [`openhexa/cli/graphql/queries/queries.graphql`](https://github.com/BLSQ/openhexa-sdk-python/blob/main/openhexa/cli/graphql/queries.graphql) directory, and they will be picked up by the code generation process.

Example of usage of the result :
```python
from openhexa.cli.api import OpenHexaClient, CreateWebappInput, AddToFavoritesInput

client = OpenHexaClient()
new_webapp_id = client.create_webapp(input=CreateWebappInput(description="", icon="", name="",workspaceSlug="", url="")).create_webapp.webapp.id
client.add_to_favorites(input=AddToFavoritesInput(webappId=new_webapp_id))
Comment on lines +179 to +183

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of usage


```

## Release

This project uses [release-please](https://github.com/googleapis/release-please) to manage releases using conventional commits.
Expand Down
5 changes: 3 additions & 2 deletions openhexa/cli/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from graphql.utilities import find_breaking_changes
from jinja2 import Template

from openhexa.cli.graphql.graphql_client import Client
from openhexa.cli.graphql.graphql_client import * # noqa: F401, F403 This allows to pass through the typed classes
from openhexa.cli.graphql.graphql_client import Client as GraphQLClient
from openhexa.cli.settings import settings
from openhexa.sdk.pipelines import get_local_workspace_config
from openhexa.sdk.pipelines.runtime import get_pipeline
Expand Down Expand Up @@ -747,7 +748,7 @@ def is_dhis2_connection_up(workspace_slug: str, connection_slug: str) -> bool:
return response["data"]["connectionBySlug"]["status"] == "UP"


class OpenHexaClient(Client):
class OpenHexaClient(GraphQLClient):
"""OpenHexaClient is a class that provides methods to interact with the OpenHexa GraphQL API."""

def __init__(self, token=None):
Expand Down
4 changes: 1 addition & 3 deletions openhexa/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,7 @@ def pipelines_list():
if settings.current_workspace is None:
_terminate("No workspace activated", err=True)

workspace_pipelines = (
OpenHexaClient().get_workspace_pipelines(workspace_slug=settings.current_workspace).pipelines.items
)
workspace_pipelines = OpenHexaClient().pipelines(workspace_slug=settings.current_workspace).pipelines.items
if len(workspace_pipelines) == 0:
click.echo(f"No pipelines in workspace {settings.current_workspace}")
return
Expand Down
Loading