Skip to content

Commit 71443e8

Browse files
committed
Add fields_args to object type reference
1 parent dd88023 commit 71443e8

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

REFERENCE.md

+35-3
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,44 @@ class UsersGroupType(ObjectType):
151151
`DeferredType` makes `UserType` happy about `UsersGroup` dependency, deferring dependency check to `make_executable_schema`. If "real" `UsersGroup` is not provided at that time, error will be raised about missing types required to create schema.
152152

153153

154+
### `__fields_args__`
155+
156+
Optional attribute that can be used to specify custom mappings between GraphQL args and Python kwargs:
157+
158+
```python
159+
from ariadne_graphql_modules import DeferredType, ObjectType, gql
160+
161+
from my_app.models import Article
162+
163+
164+
class SearchQuery(ObjectType):
165+
__schema__ = gql(
166+
"""
167+
type Query {
168+
search(query: String!, includeDrafts: Boolean): [Article!]!
169+
}
170+
"""
171+
)
172+
__fields_args__ = {
173+
"includeDrafts": "with_drafts",
174+
}
175+
__requires__ = [DeferredType("Article")]
176+
177+
@staticmethod
178+
async def resolve_search(*_, query: str, with_drafts: bool | None):
179+
articles = Article.query.search(query)
180+
if not with_drafts:
181+
articles = articles.filter(is_draft=False)
182+
return await articles.all()
183+
```
184+
185+
154186
## `MutationType`
155187

156188
Convenience type for defining single mutation:
157189

158190
```python
159-
from ariadne_graphql_modules import MutationType, convert_case, gql
191+
from ariadne_graphql_modules import MutationType, gql
160192

161193
from my_app import create_user
162194

@@ -182,7 +214,7 @@ class UserRegisterMutation(MutationType):
182214
Recommended use for this type is to create custom base class for your GraphQL API:
183215

184216
```python
185-
from ariadne_graphql_modules import MutationType, convert_case, gql
217+
from ariadne_graphql_modules import MutationType, gql
186218

187219

188220
class BaseMutation(MutationType):
@@ -206,7 +238,7 @@ class BaseMutation(MutationType):
206238
Optional attribute that can be used to specify custom mapping between GraphQL schema and Python:
207239

208240
```python
209-
from ariadne_graphql_modules import MutationType, convert_case, gql
241+
from ariadne_graphql_modules import MutationType, gql
210242

211243
from my_app import create_user
212244

0 commit comments

Comments
 (0)