|
| 1 | +# GQL python |
| 2 | +A python package for interacting with the PlayerData GraphQL API. |
| 3 | + |
| 4 | +## Folder Structure |
| 5 | +- `playerdata_api`: The main package for interacting with the PlayerData API. |
| 6 | + - `gqlauth`: The main package for authenticating with the PlayerData API. |
| 7 | + - `gqlclient`: The main package for interacting with the PlayerData GraphQL API. |
| 8 | + - `custom_queries`: Custom queries for the PlayerData GraphQL API. |
| 9 | + - `custom_mutations`: Custom mutations for the PlayerData GraphQL API. |
| 10 | + - `custom_fields`: Custom fields for the PlayerData GraphQL API. |
| 11 | + - `input_types`: Input types for the PlayerData GraphQL API. |
| 12 | + - `enums`: Enums for the PlayerData GraphQL API. |
| 13 | + - `custom_typing_fields`: Custom typing fields for the PlayerData GraphQL API. |
| 14 | + - `custom_responses`: Custom responses for the PlayerData GraphQL API. |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +uv is the tool we use to build and manage the `playerdatapy` Python package. |
| 19 | + |
| 20 | +Make sure you install uv using [pipx](https://docs.astral.sh/uv/getting-started/installation/#pypi) or the [official installer](https://docs.astral.sh/uv/getting-started/installation/#standalone-installer). Installing with pip or other methods will lead to unexpected behavior. |
| 21 | + |
| 22 | +We recommend using the [official installer](https://docs.astral.sh/uv/getting-started/installation/#standalone-installer). |
| 23 | + |
| 24 | +Then you can install the required dependencies, in a virtual environment if required. |
| 25 | + |
| 26 | +```bash |
| 27 | + uv sync |
| 28 | +``` |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +To use the GraphqlClient, you need to provide your client id, this will be provided to you by PlayerData. |
| 33 | +To request API credentials, please contact the PlayerData team at support@playerdata.co.uk. |
| 34 | + |
| 35 | + |
| 36 | +### Option 1: Use generated types with PlayerDataAPI |
| 37 | + |
| 38 | +Example usage of this option is provided in the `example_pydantic.py` file. |
| 39 | +The basic flow is to create a PlayerDataAPI instance, build the query objects using the code-generated Pydantic models (generated by ariadne-codegen), and then call the run_queries method. |
| 40 | + |
| 41 | +To run an example of this option, you can use the following command: |
| 42 | + |
| 43 | +```bash |
| 44 | +python example_pydantic.py |
| 45 | +``` |
| 46 | + |
| 47 | +### Option 2: Use the GraphqlClient class directly |
| 48 | + |
| 49 | +Example usage of this option is provided in the `example_direct.py` file. |
| 50 | +The basic flow is to create a GraphqlClient instance, build the query string, and then call the query method. |
| 51 | + |
| 52 | +To run an example of this option, you can use the following command: |
| 53 | + |
| 54 | +```bash |
| 55 | +python example_direct.py |
| 56 | +``` |
| 57 | + |
| 58 | +## Authentication Types |
| 59 | + |
| 60 | +These authentication types are set out in the `playerdatapy.gqlauth.AuthenticationType` enum. |
| 61 | +The default authentication type is `AuthenticationType.AUTHORISATION_CODE_FLOW`. |
| 62 | +These authentication types are used to set the authentication type in the `GraphqlAuth` class. |
| 63 | + |
| 64 | +### Authorisation Code Flow (PKCE) |
| 65 | + |
| 66 | +Authorisation code flow with PKCE is used to authenticate users with non_confidential credentials. |
| 67 | + |
| 68 | +### Authorisation Code Flow |
| 69 | + |
| 70 | +Authorisation code flow is used to authenticate users with confidential credentials. |
| 71 | + |
| 72 | +### Client Credentials Flow |
| 73 | + |
| 74 | +Client credentials flow is used to authenticate backend to backend communication. |
| 75 | + |
| 76 | +### Updates to the API Fields and Mutations |
| 77 | + |
| 78 | +To update the API fields and mutations, you need to set an `AUTH_TOKEN` environment variable. |
| 79 | +This code is auto-generated by Ariadne, so any changes to the API fields and mutations will be reflected in the code. |
| 80 | + |
| 81 | +```shell |
| 82 | +export AUTH_TOKEN=f"Bearer {your_auth_token}" |
| 83 | +python -m ariadne-codegen |
| 84 | +``` |
| 85 | + |
| 86 | +This will generate code and update files in the `playerdatapy` package. |
0 commit comments