revise documentation with imports, capitalization

This commit is contained in:
Dave A 2019-06-09 09:50:10 -04:00
parent 37d32de39f
commit 125ef51836
7 changed files with 50 additions and 28 deletions

View File

@ -5,6 +5,8 @@ class Context(object):
.. code:: python
from graphene import Context
context = Context(loaders=build_dataloaders(), request=my_web_request)
schema.execute('{ hello(name: "world") }', context=context)

View File

@ -19,22 +19,26 @@ class InputField(MountedType):
.. code:: python
class Person(graphene.InputObjectType):
first_name = graphene.String(required=True) # implicitly mounted as Input Field
last_name = graphene.InputField(String, description='Surname') # explicitly mounted as Input Field
from graphene import InputObjectType, String, InputField
class Person(InputObjectType):
# implicitly mounted as Input Field
first_name = String(required=True)
# explicitly mounted as Input Field
last_name = InputField(String, description="Surname")
args:
type (class for a graphene.UnmountedType): must be a class (not an instance) of an
type (class for a graphene.UnmountedType): Must be a class (not an instance) of an
unmounted graphene type (ex. scalar or object) which is used for the type of this
field in the GraphQL schema.
name (optional, str): the name of the GraphQL input field (must be unique in a type).
name (optional, str): Name of the GraphQL input field (must be unique in a type).
Defaults to attribute name.
default_value (optional, Any): Default value to use as input if none set in user operation (
query, mutation, etc.).
deprecation_reason (optional, str): Setting this value indicates that the field is
depreciated and may provide instruction or reason on how for clients to proceed.
description (optional, str): the description of the GraphQL field in the schema.
required (optional, bool): indicates this input field as not null in the graphql scehma.
description (optional, str): Description of the GraphQL field in the schema.
required (optional, bool): Indicates this input field as not null in the graphql scehma.
Raises a validation error if argument not provided. Same behavior as graphene.NonNull.
Default False.
**extra_args (optional, Dict): Not used.

View File

@ -38,11 +38,11 @@ class Interface(BaseType):
``resolve_type`` on Interface and an ObjectType with ``Meta.possible_types`` or ``is_type_of``.
Meta:
name (str): the name of the GraphQL type (must be unique in schema). Defaults to class
name (str): Name of the GraphQL type (must be unique in schema). Defaults to class
name.
description (str): the description of the GraphQL type in the schema. Defaults to class
description (str): Description of the GraphQL type in the schema. Defaults to class
docstring.
fields (Dict[str, graphene.Field]): dictionary of field name to Field. Not recommended to
fields (Dict[str, graphene.Field]): Dictionary of field name to Field. Not recommended to
use (prefer class attributes).
"""

View File

@ -29,7 +29,7 @@ class Mutation(ObjectType):
.. code:: python
from graphene import Mutation, String, Boolean, Field
from graphene import Mutation, ObjectType, String, Boolean, Field
class CreatePerson(Mutation):
class Arguments:
@ -43,7 +43,7 @@ class Mutation(ObjectType):
ok = True
return CreatePerson(person=person, ok=ok)
class Mutation(graphene.ObjectType):
class Mutation(ObjectType):
create_person = CreatePerson.Field()
Meta class options (optional):
@ -54,14 +54,14 @@ class Mutation(ObjectType):
change and return output.
arguments (Dict[str, graphene.Argument]): Or ``Arguments`` inner class with attributes on
Mutation class. Arguments to use for the mutation Field.
name (str): the name of the GraphQL type (must be unique in schema). Defaults to class
name (str): Name of the GraphQL type (must be unique in schema). Defaults to class
name.
description (str): the description of the GraphQL type in the schema. Defaults to class
description (str): Description of the GraphQL type in the schema. Defaults to class
docstring.
interfaces (Iterable[graphene.Interface]): NOT IMPLEMENTED (use ``output`` to define a
payload implementing interfaces). GraphQL interfaces to extend with the payload
object. All fields from interface will be included in this object's schema.
fields (Dict[str, graphene.Field]): dictionary of field name to Field. Not recommended to
fields (Dict[str, graphene.Field]): Dictionary of field name to Field. Not recommended to
use (prefer class attributes or ``Meta.output``).
"""

View File

@ -37,12 +37,16 @@ class ObjectType(BaseType):
.. code:: python
from graphene import ObjectType, String, Field
class Person(ObjectType):
class Meta:
description = 'A human'
first_name = graphene.String() # implicitly mounted as Field
last_name = graphene.Field(String) # explicitly mounted as Field
# implicitly mounted as Field
first_name = String()
# explicitly mounted as Field
last_name = Field(String)
def resolve_last_name(parent, info):
return last_name
@ -51,21 +55,25 @@ class ObjectType(BaseType):
.. code:: python
graphene.Feild(Person, description='My favorite person')``.
from graphene import ObjectType, Field
class Query(ObjectType):
person = Field(Person, description="My favorite person")
Meta class options (optional):
name (str): the name of the GraphQL type (must be unique in schema). Defaults to class
name (str): Name of the GraphQL type (must be unique in schema). Defaults to class
name.
description (str): the description of the GraphQL type in the schema. Defaults to class
description (str): Description of the GraphQL type in the schema. Defaults to class
docstring.
interfaces (Iterable[graphene.Interface]): GraphQL interfaces to extend with this object.
all fields from interface will be included in this object's schema.
possible_types (Iterable[class]): used to test parent value object via isintance to see if
possible_types (Iterable[class]): Used to test parent value object via isintance to see if
this type can be used to resolve an ambigous type (interface, union).
default_resolver (any Callable resolver): Override the default resolver for this
type. Defaults to graphene default resolver which returns an attribute or dictionary
key with the same name as the field.
fields (Dict[str, graphene.Field]): dictionary of field name to Field. Not recommended to
fields (Dict[str, graphene.Field]): Dictionary of field name to Field. Not recommended to
use (prefer class attributes).
An _ObjectType_ can be used as a simple value object by creating an instance of the class.
@ -76,8 +84,8 @@ class ObjectType(BaseType):
assert p.first_name == 'Bob'
Args:
*args (List[Any]): positional values to use for Field values of value object
**kwargs (Dict[str: Any]): keyword arguments to use for Field values of value object
*args (List[Any]): Positional values to use for Field values of value object
**kwargs (Dict[str: Any]): Keyword arguments to use for Field values of value object
"""
@classmethod

View File

@ -44,7 +44,9 @@ class List(Structure):
.. code:: python
field_name = graphene.List(graphene.String, description='There will be many values')
from graphene import List, String
field_name = List(String, description="There will be many values")
"""
def __str__(self):
@ -70,12 +72,14 @@ class NonNull(Structure):
Note: the enforcement of non-nullability occurs within the executor.
NonNull can also be indicated on all Mounted types with the argument ``required``.
NonNull can also be indicated on all Mounted types with the keyword argument ``required``.
.. code:: python
field_name = graphene.NonNull(graphene.String, description='This field will not be null')
another_field = graphene.String(required=True, description='This is equivalent to the above')
from graphene import NonNull, String
field_name = NonNull(String, description='This field will not be null')
another_field = String(required=True, description='This is equivalent to the above')
"""

View File

@ -10,6 +10,8 @@ class UnmountedType(OrderedType):
.. code:: python
from graphene import ObjectType, Field, String
class MyObjectType(ObjectType):
my_field = Field(String, description='Description here')
@ -17,6 +19,8 @@ class UnmountedType(OrderedType):
.. code:: python
from graphene import ObjectType, String
class MyObjectType(ObjectType):
my_field = String(description='Description here')