Models
GraftModel
Bases: SQLModel
An extension of SQLModel that integrates Strawberry GraphQL functionalities, enabling the dynamic generation of GraphQL schemas directly from SQLModel definitions. This class supports configuring GraphQL operations such as queries and mutations, and facilitates the management of permissions for these operations.
Attributes:
| Name | Type | Description |
|---|---|---|
__strawberry_schema__ |
StrawberryType
|
Holds the GraphQL schema associated with this model, allowing for integration with the Strawberry GraphQL library. |
__enable_put_mutation__ |
bool | None
|
Controls whether PUT mutations (update
operations) are enabled for this model in the GraphQL API. Set to |
__enable_delete_mutation__ |
bool | None
|
Determines whether DELETE mutations
(delete operations) are enabled for this model in the GraphQL API. Set to
|
__enable_query__ |
bool | None
|
Specifies whether the model can be queried via
the GraphQL API. Set to |
__queryname__ |
str
|
Provides a custom name for GraphQL queries related to this model. Defaults to the model's table name plus 's' (e.g., 'users' for a User model) if not explicitly set. |
__enginename__ |
str
|
Identifier for the database engine used by this model, useful for applications that connect to multiple databases or require specific database configurations. |
__filter_attributes__ |
Optional[dict[str, dict[str, Any]]]
|
Definition of filters allowed by the model,
useful for filter attribute declarations. Defaults to |
__custom_resolvers__ |
Optional[list[Callable]]
|
Definition of custom resolvers allowed by the model,
useful to make custom attributes. Defaults to |
__directives__ |
List[Any]
|
Maps Custom directives applied to model [Key(fields="id", resolvable=True)] |
__mutation_permission_classes__ |
Dict[str, List[Type[BasePermission]]]
|
Maps specific mutation names to their respective permission classes. This allows for fine-grained control over which permissions apply to each mutation. If a mutation is not listed, it defaults to having no specific permissions. |
__default_order_by__ |
dict[str, OrderBy] | str
|
Order by for database queries. Can be a string for backward compatibility or a dictionary with attribute as key and OrderBy as value. Example: {"id": OrderBy.ASC} |
__sql_preset_order_by__ |
Optional[str]
|
Raw SQL string for setting a hidden ordering rule |
__sql_preset_filter__ |
Optional[str]
|
Raw SQL string for setting a hidden filter condition for this model's queries. |
Classes: GraftModel: An extended SQLModel that incorporates GraphQL functionalities by using Strawberry GraphQL. This class allows defining GraphQL schemas, query names, engine names, and supports dynamic field resolution using dependency injection.
Strawberry: An inner class used to encapsulate GraphQL-specific configurations
and properties for the GraftModel class.
Methods:
init_subclass: Automatically called when a subclass of GraftModel is defined.
Sets up the necessary GraphQL configurations and registers the subclass in a
setup registry for further reference.
permission_getter: Async static method intended to be overridden to provide
custom logic for determining user permissions for executing GraphQL queries.
Should return True if the query is permitted, False otherwise.
Source code in graftql/core/model.py
13 14 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 | |