Skip to content

Commit 818fb6c

Browse files
added docs from ariadne website (#404)
1 parent d39dbcf commit 818fb6c

File tree

8 files changed

+854
-0
lines changed

8 files changed

+854
-0
lines changed

docs/01-intro.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: Introduction
3+
---
4+
5+
# Ariadne Client based on code generator
6+
7+
Python code generator that takes graphql schema, queries, mutations and subscriptions and generates Python package with fully typed and asynchronous GraphQL client.
8+
9+
It's available as `ariadne-codegen` command and reads configuration from the `pyproject.toml` file:
10+
11+
```
12+
$ ariadne-codegen
13+
```
14+
15+
It can also be run as `python -m ariadne_codegen`.
16+
17+
## Features
18+
19+
- Generate pydantic models from schema types, inputs and enums.
20+
- Generate pydantic models for GraphQL results.
21+
- Generate client package with each GraphQL operation available as async method.
22+
23+
## Installation
24+
25+
Ariadne Code Generator can be installed with pip:
26+
27+
```
28+
$ pip install ariadne-codegen
29+
```
30+
31+
To support subscriptions, default base client requires `websockets` package:
32+
33+
```
34+
$ pip install ariadne-codegen[subscriptions]
35+
```

docs/02-configuration.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Configuration
3+
---
4+
5+
# Configuration
6+
7+
`ariadne-codegen` reads configuration from `[tool.ariadne-codegen]` section in your `pyproject.toml`. You can use other configuration file with `--config` option, eg. `ariadne-codegen --config custom_file.toml`
8+
9+
Minimal configuration for client generation:
10+
11+
```toml
12+
[tool.ariadne-codegen]
13+
schema_path = "schema.graphql"
14+
queries_path = "queries.graphql"
15+
```
16+
17+
## Required settings:
18+
19+
- `queries_path` - path to file/directory with queries (Can be optional if `enable_custom_operations` is used)
20+
21+
One of the following 2 parameters is required, in case of providing both of them `schema_path` is prioritized:
22+
23+
- `schema_path` - path to file/directory with graphql schema
24+
- `remote_schema_url` - url to graphql server, where introspection query can be perfomed
25+
26+
## Optional settings:
27+
28+
- `remote_schema_headers` - extra headers that are passed along with introspection query, eg. `{"Authorization" = "Bearer: token"}`. To include an environment variable in a header value, prefix the variable with `$`, eg. `{"Authorization" = "$AUTH_TOKEN"}`
29+
- `remote_schema_verify_ssl` (defaults to `true`) - a flag that specifies wheter to verify ssl while introspecting remote schema
30+
- `target_package_name` (defaults to `"graphql_client"`) - name of generated package
31+
- `target_package_path` (defaults to cwd) - path where to generate package
32+
- `client_name` (defaults to `"Client"`) - name of generated client class
33+
- `client_file_name` (defaults to `"client"`) - name of file with generated client class
34+
- `base_client_name` (defaults to `"AsyncBaseClient"`) - name of base client class
35+
- `base_client_file_path` (defaults to `.../ariadne_codegen/client_generators/dependencies/async_base_client.py`) - path to file where `base_client_name` is defined
36+
- `enums_module_name` (defaults to `"enums"`) - name of file with generated enums models
37+
- `input_types_module_name` (defaults to `"input_types"`) - name of file with generated input types models
38+
- `fragments_module_name` (defaults to `"fragments"`) - name of file with generated fragments models
39+
- `include_comments` (defaults to `"stable"`) - option which sets content of comments included at the top of every generated file. Valid choices are: `"none"` (no comments), `"timestamp"` (comment with generation timestamp), `"stable"` (comment contains a message that this is a generated file)
40+
- `convert_to_snake_case` (defaults to `true`) - a flag that specifies whether to convert fields and arguments names to snake case
41+
- `include_all_inputs` (defaults to `true`) - a flag specifying whether to include all inputs defined in the schema, or only those used in supplied operations
42+
- `include_all_enums` (defaults to `true`) - a flag specifying whether to include all enums defined in the schema, or only those used in supplied operations
43+
- `async_client` (defaults to `true`) - default generated client is `async`, change this to option `false` to generate synchronous client instead
44+
- `opentelemetry_client` (defaults to `false`) - default base clients don't support any performance tracing. Change this option to `true` to use the base client with Open Telemetry support.
45+
- `files_to_include` (defaults to `[]`) - list of files which will be copied into generated package
46+
- `plugins` (defaults to `[]`) - list of plugins to use during generation
47+
- `enable_custom_operations` (defaults to `false`) - enables building custom operations. Generates additional files that contains all the classes and methods for generation.

docs/03-using-generated-client.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Using generated client
3+
---
4+
5+
# Using generated client
6+
7+
Generated client can be imported from package:
8+
9+
```py
10+
from {target_package_name}.{client_file_name} import {client_name}
11+
```
12+
13+
Example with default settings:
14+
15+
```py
16+
from graphql_client.client import Client
17+
```
18+
19+
### Passing headers to client
20+
21+
Client (with default base client), takes passed headers and attaches them to every sent request.
22+
23+
```py
24+
client = Client("https://example.com/graphql", {"Authorization": "Bearer token"})
25+
```
26+
27+
For more complex scenarios, you can pass your own http client:
28+
29+
```py
30+
client = Client(http_client=CustomComplexHttpClient())
31+
```
32+
33+
`CustomComplexHttpClient` needs to be an instance of `httpx.AsyncClient` for async client, or `httpx.Client` for sync.

0 commit comments

Comments
 (0)