DataLoader helpers
- GraftLoader: Strawberry DataLoader wrapper used internally
- Dl: declarative relationship helper
- ManyRelation: helper for many-to-many relation resolution
Dl
A utility class designed to facilitate the linking of source and target fields across different models. This is particularly useful for setting up data loaders where fields from one model may depend on fields in another, and if foreign keys should be created based on relationships.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
str | list[str]
|
The source field(s) from where data is to be fetched. |
target |
str | list[str]
|
The target field(s) where data is to be deposited. |
foreign_key |
bool
|
Indicates whether the relationship should create a foreign key (default is False). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the types of source and target do not match, or if they are lists and do not have the same length. |
Source code in graftql/loaders/dataloader.py
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 | |
GraftLoader
Bases: DataLoader
A customized DataLoader that handles additional filtering mechanisms during data retrieval processes. It is capable of using predefined filter methods to process data based on request-specific parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
filter_method |
callable
|
A method that applies additional filtering to the data based on the request context and specified filters. |
context |
The context of the request, used to pass additional parameters to the filter_method. |
Methods:
| Name | Description |
|---|---|
load |
Overridden to apply filters before returning the data, enhancing the DataLoader's functionality to cater to complex querying needs. |
Source code in graftql/loaders/dataloader.py
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 | |
dict_to_tuple(data)
Converts a dictionary into a tuple, recursively processing nested dictionaries and lists to ensure they are in a hashable and comparable format. This is essential for caching mechanisms within DataLoaders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
The dictionary to be converted. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple
|
A tuple representation of the original dictionary, suitable for use as a key in caching operations. |
Source code in graftql/loaders/dataloader.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |