Skip to content

Commit 5894be5

Browse files
committed
CI and README
1 parent 357fb5f commit 5894be5

4 files changed

Lines changed: 50 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ jobs:
1717
with:
1818
python-version: 3.13
1919

20-
- name: Install Ariadne-codegen
21-
run: pip install ariadne-codegen
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 18
24+
25+
- name: Install Ariadne-codegen and gqlg
26+
run: |
27+
pip install ariadne-codegen
28+
npm install -g gqlg
2229
2330
- uses: pre-commit/action@v3.0.1
2431
test:

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ repos:
88

99
- repo: local
1010
hooks:
11+
- id: gqlg
12+
name: gqlg
13+
entry: bash -c
14+
echo "Running gqlg" && \
15+
gqlg --schemaFilePath ./openhexa/cli/graphql/schema.generated.graphql --destDirPath ./openhexa/cli/graphql/queries/gqlg --depthLimit 3
16+
language: system
17+
types: [ graphql ]
18+
pass_filenames: false
1119
- id: ariadne-codegen
1220
name: ariadne-codegen
1321
entry: bash -c

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,38 @@ pytest
150150

151151
### Codegen from the GraphQL schema
152152

153+
We use code generation to create Python client code from our GraphQL schema. This involves two tools:
154+
155+
1. [**ariadne-codegen**](https://github.com/mirumee/ariadne-codegen): Generates typed Python GraphQL client code from GraphQL files
156+
2. [**gqlg**](https://github.com/timqian/gql-generator): Automatically generates comprehensive GraphQL queries for all queries and mutations defined in the schema
157+
158+
The code generation process:
159+
160+
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)
161+
2. `gqlg` generates all possible queries/mutations from the schema with a depth limit of 3
162+
3. `ariadne-codegen` uses both the schema and queries to generate typed Python client code
163+
164+
To run code generation manually:
165+
153166
```shell
167+
npm install gql-generator -g
168+
pip install ariadne-codegen
154169
gqlg --schemaFilePath ./openhexa/cli/graphql/schema.generated.graphql --destDirPath ./openhexa/cli/graphql/queries/gqlg --depthLimit 3
170+
ariadne-codegen
171+
```
172+
173+
Both tools run automatically via pre-commit hooks and CI/CD when GraphQL files are modified.
174+
175+
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.
176+
177+
Example of usage of the result :
178+
```python
179+
from openhexa.cli.api import OpenHexaClient, CreateWebappInput, AddToFavoritesInput
180+
181+
client = OpenHexaClient()
182+
new_webapp_id = client.create_webapp(input=CreateWebappInput(description="", icon="", name="",workspaceSlug="", url="")).create_webapp.webapp.id
183+
client.add_to_favorites(input=AddToFavoritesInput(webappId=new_webapp_id))
184+
155185
```
156186

157187
## Release

openhexa/cli/api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
from graphql.utilities import find_breaking_changes
2222
from jinja2 import Template
2323

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

749750

750-
class OpenHexaClient(Client):
751+
class OpenHexaClient(GraphQLClient):
751752
"""OpenHexaClient is a class that provides methods to interact with the OpenHexa GraphQL API."""
752753

753754
def __init__(self, token=None):

0 commit comments

Comments
 (0)