Setup
The Setup class manages database engines and permission checks.
Setup
A configuration class responsible for setting up and managing database engines, executing queries, and facilitating permission checks for GraphQL operations.
Attributes:
| Name | Type | Description |
|---|---|---|
engine |
Dict[str, Engine]
|
A dictionary of SQLAlchemy engine instances indexed by name. |
get_permission |
callable
|
A function to determine if a request is permitted based on custom business logic. |
async_engine |
bool
|
A flag indicating if the engine configuration supports asynchronous operations. |
classes |
Dict[str, GraftModel]
|
A registry of model classes that might be involved in GraphQL queries or mutations. |
Source code in graftql/core/setup.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
execute_query(query, engine)
async
classmethod
Executes a given SQL query using the specified database engine, either asynchronously or synchronously based on the engine configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Select
|
The SQL query to be executed. |
required |
engine
|
str
|
The key of the engine in the 'engine' attribute to be used for the query. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
The result of the query execution, typically a list of database records. |
Source code in graftql/core/setup.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
get_auth(module, request_type)
classmethod
Creates a custom Strawberry GraphQL permission class that performs authentication and authorization checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
GraftModel
|
The model class for which permissions are being checked. |
required |
request_type
|
str
|
The type of request (e.g., 'query' or 'mutation') to determine the appropriate permissions. |
required |
Returns:
| Type | Description |
|---|---|
BasePermission
|
An instance of a Strawberry permission class that can be used to control access to GraphQL operations. |
Source code in graftql/core/setup.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
has_permission(module, context, request_type)
async
classmethod
Determines if a user has permission to execute a GraphQL query or mutation based on the provided context and request type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
GraftModel
|
The model class for which permissions are being checked. |
required |
context
|
dict
|
The context of the GraphQL request. |
required |
request_type
|
str
|
The type of request (e.g., 'query' or 'mutation') to determine the appropriate permissions. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A boolean indicating if the user has permission to execute the request. |
Source code in graftql/core/setup.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
setup(engine, permission_getter=None, query_filter=None)
classmethod
Configures the database engines and sets default functions for permission checks and query filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Dict[str, Engine] | Engine
|
A dictionary of engines or a single engine to be used. |
required |
permission_getter
|
callable
|
A function to determine if a request is permitted. |
None
|
query_filter
|
callable
|
A function to filter queries based on specific conditions. |
None
|
Source code in graftql/core/setup.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |