Skip to content

Commit a2fe8dd

Browse files
authored
Add note about the use of args (#1170)
* Add note about the use of `args` Closes #1037 * Some improvements * Link to correct place
1 parent 9fdab03 commit a2fe8dd

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

docs/api/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Object types
2020
.. autoclass:: graphene.Mutation
2121
:members:
2222

23+
.. _fields-mounted-types:
24+
2325
Fields (Mounted Types)
2426
----------------------
2527

docs/types/objecttypes.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ You can then execute the following query:
158158
}
159159
}
160160
161+
*Note:* There are several arguments to a field that are "reserved" by Graphene
162+
(see :ref:`fields-mounted-types`).
163+
You can still define an argument that clashes with one of these fields by using
164+
the ``args`` parameter like so:
165+
166+
.. code:: python
167+
168+
from graphene import ObjectType, Field, String
169+
170+
class Query(ObjectType):
171+
answer = String(args={'description': String()})
172+
173+
def resolve_answer(parent, info, description):
174+
return description
175+
176+
161177
Convenience Features of Graphene Resolvers
162178
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
163179

graphene/types/field.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ class Person(ObjectType):
4040
last_name = graphene.Field(String, description='Surname') # explicitly mounted as Field
4141
4242
args:
43-
type (class for a graphene.UnmountedType): must be a class (not an instance) of an
43+
type (class for a graphene.UnmountedType): Must be a class (not an instance) of an
4444
unmounted graphene type (ex. scalar or object) which is used for the type of this
4545
field in the GraphQL schema.
46-
args (optional, Dict[str, graphene.Argument]): arguments that can be input to the field.
47-
Prefer to use **extra_args.
46+
args (optional, Dict[str, graphene.Argument]): Arguments that can be input to the field.
47+
Prefer to use ``**extra_args``, unless you use an argument name that clashes with one
48+
of the Field arguments presented here (see :ref:`example<ResolverParamGraphQLArguments>`).
4849
resolver (optional, Callable): A function to get the value for a Field from the parent
4950
value object. If not set, the default resolver method for the schema is used.
5051
source (optional, str): attribute name to resolve for this field from the parent value

0 commit comments

Comments
 (0)