Fixed typos and improved language and markup

This commit is contained in:
Kalle Jepsen 2016-10-07 10:56:01 +02:00
parent 88ccaec8fa
commit 71b4de9369
7 changed files with 50 additions and 57 deletions

View File

@ -24,7 +24,7 @@ server with an associated set of resolve methods that know how to fetch
data. data.
We are going to create a very simple schema, with a ``Query`` with only We are going to create a very simple schema, with a ``Query`` with only
one field: ``hello``. And when we query it should return ``"World"``. one field: ``hello``. And when we query it, it should return ``"World"``.
.. code:: python .. code:: python
@ -41,7 +41,7 @@ one field: ``hello``. And when we query it should return ``"World"``.
Querying Querying
-------- --------
Then, we can start querying our schema: Then we can start querying our schema:
.. code:: python .. code:: python

View File

@ -1,21 +1,21 @@
AbstractTypes AbstractTypes
============= =============
An AbstractType contains fields that could be shared among An AbstractType contains fields that can be shared among
``graphene.ObjectType``, ``graphene.Interface``, ``graphene.ObjectType``, ``graphene.Interface``,
``graphene.InputObjectType`` or other ``graphene.AbstractType``. ``graphene.InputObjectType`` or other ``graphene.AbstractType``.
The basics: The basics:
- Each AbstractType is a Python class that inherits from ``graphene.AbstractType``. - Each AbstractType is a Python class that inherits from ``graphene.AbstractType``.
- Each attribute of the AbstractType represents a field (could be a ``graphene.Field`` or - Each attribute of the AbstractType represents a field (a ``graphene.Field`` or
``graphene.InputField`` depending on where is mounted) ``graphene.InputField`` depending on where it is mounted)
Quick example Quick example
------------- -------------
In this example UserFields is an ``AbstractType`` with a name. ``User`` and In this example UserFields is an ``AbstractType`` with a name. ``User`` and
``UserInput`` are two types that will have their own fields ``UserInput`` are two types that have their own fields
plus the ones defined in ``UserFields``. plus the ones defined in ``UserFields``.
.. code:: python .. code:: python

View File

@ -47,7 +47,7 @@ needs to have the ``description`` property on it.
Usage with Python Enums Usage with Python Enums
----------------------- -----------------------
In case that the Enums are already defined it's possible to reuse them using In case the Enums are already defined it's possible to reuse them using
the ``Enum.from_enum`` function. the ``Enum.from_enum`` function.
.. code:: python .. code:: python
@ -58,10 +58,8 @@ the ``Enum.from_enum`` function.
Notes Notes
----- -----
Internally, ``graphene.Enum`` uses `enum.Enum`_ Python ``graphene.Enum`` uses |enum.Enum|_ internally (or a backport if
implementation if available, or a backport if not. that's not available) and can be used in the exact same way.
So you can use it in the same way as you would do with Python .. |enum.Enum| replace:: ``enum.Enum``
``enum.Enum``. .. _enum.Enum: https://docs.python.org/3/library/enum.html
.. _``enum.Enum``: https://docs.python.org/3/library/enum.html

View File

@ -1,7 +1,7 @@
Interfaces Interfaces
========== ==========
An Interface contains the essential fields that will be implemented among An Interface contains the essential fields that will be implemented by
multiple ObjectTypes. multiple ObjectTypes.
The basics: The basics:
@ -12,8 +12,8 @@ The basics:
Quick example Quick example
------------- -------------
This example model defines a Character, which has a name. ``Human`` and This example model defines a ``Character`` interface with a name. ``Human``
``Droid`` are two of the Interface implementations. and ``Droid`` are two implementations of that interface.
.. code:: python .. code:: python
@ -37,12 +37,11 @@ This example model defines a Character, which has a name. ``Human`` and
function = graphene.String() function = graphene.String()
**name** is a field in the ``Character`` interface that will be in both ``name`` is a field on the ``Character`` interface that will also exist on both
``Human`` and ``Droid`` ObjectTypes (as those implement the ``Character`` the ``Human`` and ``Droid`` ObjectTypes (as those implement the ``Character``
interface). Each ObjectType also define extra fields at the same interface). Each ObjectType may define additional fields.
time.
The above types would have the following representation in a schema: The above types have the following representation in a schema:
.. code:: .. code::

View File

@ -7,15 +7,14 @@ querying.
The basics: The basics:
- Each ObjectType is a Python class that inherits - Each ObjectType is a Python class that inherits from
``graphene.ObjectType``. ``graphene.ObjectType``.
- Each attribute of the ObjectType represents a ``Field``. - Each attribute of the ObjectType represents a ``Field``.
Quick example Quick example
------------- -------------
This example model defines a Person, which has a first\_name and This example model defines a Person, with a first and a last name:
last\_name:
.. code:: python .. code:: python
@ -33,8 +32,7 @@ last\_name:
field is specified as a class attribute, and each attribute maps to a field is specified as a class attribute, and each attribute maps to a
Field. Field.
The above ``Person`` ObjectType would have the following representation The above ``Person`` ObjectType has the following schema representation:
in a schema:
.. code:: .. code::
@ -48,16 +46,15 @@ in a schema:
Resolvers Resolvers
--------- ---------
A resolver is a method that resolves certain field within a A resolver is a method that resolves certain fields within a
``ObjectType``. The resolver of a field will be, if not specified ``ObjectType``. If not specififed otherwise, the resolver of a
otherwise, the ``resolve_{field_name}`` within the ``ObjectType``. field is the ``resolve_{field_name}`` method on the ``ObjectType``.
By default a resolver will take the ``args``, ``context`` and ``info`` By default resolvers take the arguments ``args``, ``context`` and ``info``.
arguments.
NOTE: The class resolvers in a ``ObjectType`` are treated as ``staticmethod``s NOTE: The resolvers on a ``ObjectType`` are always treated as ``staticmethod``s,
always, so the first argument in the resolver: ``self`` (or ``root``) doesn't so the first argument to the resolver method ``self`` (or ``root``) need
need to be an actual instance of the ``ObjectType``. not be an actual instance of the ``ObjectType``.
Quick example Quick example
@ -81,7 +78,7 @@ method in the class.
Resolvers outside the class Resolvers outside the class
~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
A field could also specify a custom resolver outside the class: A field can use a custom resolver from outside the class:
.. code:: python .. code:: python
@ -98,8 +95,8 @@ A field could also specify a custom resolver outside the class:
Instances as data containers Instances as data containers
---------------------------- ----------------------------
Graphene ``ObjectType``\ s could act as containers too. So with the Graphene ``ObjectType``\ s can act as containers too. So with the
previous example you could do. previous example you could do:
.. code:: python .. code:: python

View File

@ -1,7 +1,7 @@
Scalars Scalars
======= =======
Graphene define the following base Scalar Types: Graphene defines the following base Scalar Types:
- ``graphene.String`` - ``graphene.String``
- ``graphene.Int`` - ``graphene.Int``
@ -18,7 +18,7 @@ Graphene also provides custom scalars for Dates and JSON:
Custom scalars Custom scalars
-------------- --------------
You can create a custom scalar for your schema. You can create custom scalars for your schema.
The following is an example for creating a DateTime scalar: The following is an example for creating a DateTime scalar:
.. code:: python .. code:: python
@ -47,8 +47,8 @@ The following is an example for creating a DateTime scalar:
Mounting Scalars Mounting Scalars
---------------- ----------------
This scalars if are mounted in a ``ObjectType``, ``Interface`` or Scalars mounted in a ``ObjectType``, ``Interface`` or ``Mutation`` act as
``Mutation``, would act as ``Field``\ s. ``Field``\ s.
.. code:: python .. code:: python
@ -60,7 +60,7 @@ This scalars if are mounted in a ``ObjectType``, ``Interface`` or
name = graphene.Field(graphene.String()) name = graphene.Field(graphene.String())
If the types are mounted in a ``Field``, would act as ``Argument``\ s. Types mounted in a ``Field`` act as ``Argument``\ s.
.. code:: python .. code:: python

View File

@ -5,6 +5,7 @@ A Schema is created by supplying the root types of each type of operation, query
A schema definition is then supplied to the validator and executor. A schema definition is then supplied to the validator and executor.
.. code:: python .. code:: python
my_schema = Schema( my_schema = Schema(
query=MyRootQuery, query=MyRootQuery,
mutation=MyRootMutation, mutation=MyRootMutation,
@ -13,11 +14,11 @@ A schema definition is then supplied to the validator and executor.
Types Types
----- -----
There are some cases where the schema could not access all the types that we plan to have. There are some cases where the schema cannot access all of the types that we plan to have.
For example, when a field returns an ``Interface``, the schema doesn't know any of the For example, when a field returns an ``Interface``, the schema doesn't know about any of the
implementations. implementations.
In this case, we would need to use the ``types`` argument when creating the Schema. In this case, we need to use the ``types`` argument when creating the Schema.
.. code:: python .. code:: python
@ -31,7 +32,7 @@ In this case, we would need to use the ``types`` argument when creating the Sche
Querying Querying
-------- --------
If you need to query a schema, you can directly call the ``execute`` method on it. To query a schema, call the ``execute`` method on it.
.. code:: python .. code:: python
@ -44,9 +45,9 @@ Auto CamelCase field names
By default all field and argument names (that are not By default all field and argument names (that are not
explicitly set with the ``name`` arg) will be converted from explicitly set with the ``name`` arg) will be converted from
`snake_case` to `camelCase` (`as the API is usually being consumed by a js/mobile client`) ``snake_case`` to ``camelCase`` (as the API is usually being consumed by a js/mobile client)
So, for example if we have the following ObjectType For example with the ObjectType
.. code:: python .. code:: python
@ -54,13 +55,12 @@ So, for example if we have the following ObjectType
last_name = graphene.String() last_name = graphene.String()
other_name = graphene.String(name='_other_Name') other_name = graphene.String(name='_other_Name')
Then the ``last_name`` field name is converted to ``lastName``. the ``last_name`` field name is converted to ``lastName``.
In the case we don't want to apply any transformation, we can specify In case you don't want to apply this transformation, provide a ``name`` argument to the field constructor.
the field name with the ``name`` argument. So ``other_name`` field name ``other_name`` converts to ``_other_Name`` (without further transformations).
would be converted to ``_other_Name`` (without any other transformation).
So, you would need to query with: Your query should look like
.. code:: .. code::
@ -70,8 +70,7 @@ So, you would need to query with:
} }
If you want to disable this behavior, you set use the ``auto_camelcase`` argument To disable this behavior, set the ``auto_camelcase`` to ``False`` upon schema instantiation.
to ``False`` when you create the Schema.
.. code:: python .. code:: python