Skip to content

Commit da1359e

Browse files
dvndrsnjkimbo
authored andcommitted
expose livehtml autobuild in Makefile + Add API autodoc (#971)
* expose livehtml autobuild in Makefile * add API documentation for schema * document graphene core API * fixes black lint * Update graphene/types/union.py Co-Authored-By: Jonathan Kim <jkimbo@gmail.com> * Update graphene/types/argument.py Co-Authored-By: Jonathan Kim <jkimbo@gmail.com> * Update graphene/types/field.py Co-Authored-By: Jonathan Kim <jkimbo@gmail.com> * Update graphene/types/inputfield.py Co-Authored-By: Jonathan Kim <jkimbo@gmail.com> * add note about non-functional `interfaces` meta argument in mutation * update with other virtual environment configuration * pin autobuild * format argument example code * format enum input object and interface examples * format enum mutation union examples * revise documentation with imports, capitalization
1 parent 40229b8 commit da1359e

23 files changed

+580
-26
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ __pycache__/
1111
# Distribution / packaging
1212
.Python
1313
env/
14+
venv/
15+
.venv/
1416
build/
1517
develop-eggs/
1618
dist/

Makefile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ help:
33
@echo "Please use \`make <target>' where <target> is one of"
44
@grep -E '^\.PHONY: [a-zA-Z_-]+ .*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = "(: |##)"}; {printf "\033[36m%-30s\033[0m %s\n", $$2, $$3}'
55

6+
.PHONY: install-dev ## Install development dependencies
7+
install-dev:
8+
pip install -e ".[test]"
9+
10+
test:
11+
py.test graphene
12+
613
.PHONY: docs ## Generate docs
7-
docs:
8-
@cd docs &&\
9-
pip install -r requirements.txt &&\
10-
make html &&\
11-
cd -
14+
docs: install-dev
15+
cd docs && make install && make html
16+
17+
.PHONY: docs-live ## Generate docs with live reloading
18+
docs-live: install-dev
19+
cd docs && make install && make livehtml

docs/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ help:
1919
@echo "Please use \`make <target>' where <target> is one of"
2020
@grep -E '^\.PHONY: [a-zA-Z_-]+ .*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = "(: |##)"}; {printf "\033[36m%-30s\033[0m %s\n", $$2, $$3}'
2121

22-
.PHONY: clean
22+
.PHONY: install ## to install all documentation related requirements
23+
install:
24+
pip install -r requirements.txt
25+
26+
.PHONY: clean ## to remove all built documentation
2327
clean:
2428
rm -rf $(BUILDDIR)/*
2529

@@ -199,6 +203,6 @@ dummy:
199203
@echo
200204
@echo "Build finished. Dummy builder generates no files."
201205

202-
.PHONY: livehtml
206+
.PHONY: livehtml ## to build and serve live-reloading documentation
203207
livehtml:
204-
sphinx-autobuild -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
208+
sphinx-autobuild -b html --watch ../graphene $(ALLSPHINXOPTS) $(BUILDDIR)/html

docs/_static/.gitkeep

Whitespace-only changes.

docs/api/index.rst

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
API Reference
2+
=============
3+
4+
Schema
5+
------
6+
7+
.. autoclass:: graphene.types.schema.Schema
8+
:members:
9+
10+
.. Uncomment sections / types as API documentation is fleshed out
11+
.. in each class
12+
13+
Object types
14+
------------
15+
16+
.. autoclass:: graphene.ObjectType
17+
18+
.. autoclass:: graphene.InputObjectType
19+
20+
.. autoclass:: graphene.Mutation
21+
:members:
22+
23+
Fields (Mounted Types)
24+
----------------------
25+
26+
.. autoclass:: graphene.Field
27+
28+
.. autoclass:: graphene.Argument
29+
30+
.. autoclass:: graphene.InputField
31+
32+
Fields (Unmounted Types)
33+
------------------------
34+
35+
.. autoclass:: graphene.types.unmountedtype.UnmountedType
36+
37+
GraphQL Scalars
38+
---------------
39+
40+
.. autoclass:: graphene.Int()
41+
42+
.. autoclass:: graphene.Float()
43+
44+
.. autoclass:: graphene.String()
45+
46+
.. autoclass:: graphene.Boolean()
47+
48+
.. autoclass:: graphene.ID()
49+
50+
Graphene Scalars
51+
----------------
52+
53+
.. autoclass:: graphene.Date()
54+
55+
.. autoclass:: graphene.DateTime()
56+
57+
.. autoclass:: graphene.Time()
58+
59+
.. autoclass:: graphene.Decimal()
60+
61+
.. autoclass:: graphene.UUID()
62+
63+
.. autoclass:: graphene.JSONString()
64+
65+
Enum
66+
----
67+
68+
.. autoclass:: graphene.Enum()
69+
70+
Structures
71+
----------
72+
73+
.. autoclass:: graphene.List
74+
75+
.. autoclass:: graphene.NonNull
76+
77+
Type Extension
78+
--------------
79+
80+
.. autoclass:: graphene.Interface()
81+
82+
.. autoclass:: graphene.Union()
83+
84+
Execution Metadata
85+
------------------
86+
87+
.. autoclass:: graphene.ResolveInfo
88+
89+
.. autoclass:: graphene.Context
90+
91+
.. autoclass:: graphql.execution.base.ExecutionResult
92+
93+
.. Relay
94+
.. -----
95+
96+
.. .. autoclass:: graphene.Node
97+
98+
.. .. autoclass:: graphene.GlobalID
99+
100+
.. .. autoclass:: graphene.ClientIDMutation
101+
102+
.. .. autoclass:: graphene.Connection
103+
104+
.. .. autoclass:: graphene.ConnectionField
105+
106+
.. .. autoclass:: graphene.PageInfo

docs/conf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
# add these directories to sys.path here. If the directory is relative to the
2323
# documentation root, use os.path.abspath to make it absolute, like shown here.
2424
#
25-
# import os
26-
# import sys
27-
# sys.path.insert(0, os.path.abspath('.'))
25+
import os
26+
import sys
27+
28+
sys.path.insert(0, os.path.abspath(".."))
2829

2930
# -- General configuration ------------------------------------------------
3031

@@ -41,6 +42,7 @@
4142
"sphinx.ext.todo",
4243
"sphinx.ext.coverage",
4344
"sphinx.ext.viewcode",
45+
"sphinx.ext.napoleon",
4446
]
4547
if not on_rtd:
4648
extensions += ["sphinx.ext.githubpages"]

docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ Contents:
1111
execution/index
1212
relay/index
1313
testing/index
14+
api/index
1415

1516
Integrations
16-
-----
17+
------------
1718

1819
* `Graphene-Django <http://docs.graphene-python.org/projects/django/en/latest/>`_ (`source <https://github.com/graphql-python/graphene-django/>`_)
1920
* `Graphene-SQLAlchemy <http://docs.graphene-python.org/projects/sqlalchemy/en/latest/>`_ (`source <https://github.com/graphql-python/graphene-sqlalchemy/>`_)

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Required library
22
Sphinx==1.5.3
3+
sphinx-autobuild==0.7.1
34
# Docs template
45
http://graphene-python.org/sphinx_graphene_theme.zip

graphene/types/argument.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,37 @@
88

99

1010
class Argument(MountedType):
11+
"""
12+
Makes an Argument available on a Field in the GraphQL schema.
13+
14+
Arguments will be parsed and provided to resolver methods for fields as keyword arguments.
15+
16+
All ``arg`` and ``**extra_args`` for a ``graphene.Field`` are implicitly mounted as Argument
17+
using the below parameters.
18+
19+
.. code:: python
20+
21+
from graphene import String, Boolean, Argument
22+
23+
age = String(
24+
# Boolean implicitly mounted as Argument
25+
dog_years=Boolean(description="convert to dog years"),
26+
# Boolean explicitly mounted as Argument
27+
decades=Argument(Boolean, default_value=False),
28+
)
29+
30+
args:
31+
type (class for a graphene.UnmountedType): must be a class (not an instance) of an
32+
unmounted graphene type (ex. scalar or object) which is used for the type of this
33+
argument in the GraphQL schema.
34+
required (bool): indicates this argument as not null in the graphql scehma. Same behavior
35+
as graphene.NonNull. Default False.
36+
name (str): the name of the GraphQL argument. Defaults to parameter name.
37+
description (str): the description of the GraphQL argument in the schema.
38+
default_value (Any): The value to be provided if the user does not set this argument in
39+
the operation.
40+
"""
41+
1142
def __init__(
1243
self,
1344
type,

graphene/types/context.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
class Context(object):
2+
"""
3+
Context can be used to make a convenient container for attributes to provide
4+
for execution for resolvers of a GraphQL operation like a query.
5+
6+
.. code:: python
7+
8+
from graphene import Context
9+
10+
context = Context(loaders=build_dataloaders(), request=my_web_request)
11+
schema.execute('{ hello(name: "world") }', context=context)
12+
13+
def resolve_hello(parent, info, name):
14+
info.context.request # value set in Context
15+
info.context.loaders # value set in Context
16+
# ...
17+
18+
args:
19+
**params (Dict[str, Any]): values to make available on Context instance as attributes.
20+
21+
"""
22+
223
def __init__(self, **params):
324
for key, value in params.items():
425
setattr(self, key, value)

graphene/types/enum.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,30 @@ def from_enum(cls, enum, description=None, deprecation_reason=None): # noqa: N8
6767

6868

6969
class Enum(six.with_metaclass(EnumMeta, UnmountedType, BaseType)):
70+
"""
71+
Enum type definition
72+
73+
Defines a static set of values that can be provided as a Field, Argument or InputField.
74+
75+
.. code:: python
76+
77+
from graphene import Enum
78+
79+
class NameFormat(Enum):
80+
FIRST_LAST = "first_last"
81+
LAST_FIRST = "last_first"
82+
83+
Meta:
84+
enum (optional, Enum): Python enum to use as a base for GraphQL Enum.
85+
86+
name (optional, str): Name of the GraphQL type (must be unique in schema). Defaults to class
87+
name.
88+
description (optional, str): Description of the GraphQL type in the schema. Defaults to class
89+
docstring.
90+
deprecation_reason (optional, str): Setting this value indicates that the enum is
91+
depreciated and may provide instruction or reason on how for clients to proceed.
92+
"""
93+
7094
@classmethod
7195
def __init_subclass_with_meta__(cls, enum=None, _meta=None, **options):
7296
if not _meta:

graphene/types/field.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,47 @@ def source_resolver(source, root, info, **args):
1919

2020

2121
class Field(MountedType):
22+
"""
23+
Makes a field available on an ObjectType in the GraphQL schema. Any type can be mounted as a
24+
Field:
25+
26+
- Object Type
27+
- Scalar Type
28+
- Enum
29+
- Interface
30+
- Union
31+
32+
All class attributes of ``graphene.ObjectType`` are implicitly mounted as Field using the below
33+
arguments.
34+
35+
.. code:: python
36+
37+
class Person(ObjectType):
38+
first_name = graphene.String(required=True) # implicitly mounted as Field
39+
last_name = graphene.Field(String, description='Surname') # explicitly mounted as Field
40+
41+
args:
42+
type (class for a graphene.UnmountedType): must be a class (not an instance) of an
43+
unmounted graphene type (ex. scalar or object) which is used for the type of this
44+
field in the GraphQL schema.
45+
args (optional, Dict[str, graphene.Argument]): arguments that can be input to the field.
46+
Prefer to use **extra_args.
47+
resolver (optional, Callable): A function to get the value for a Field from the parent
48+
value object. If not set, the default resolver method for the schema is used.
49+
source (optional, str): attribute name to resolve for this field from the parent value
50+
object. Alternative to resolver (cannot set both source and resolver).
51+
deprecation_reason (optional, str): Setting this value indicates that the field is
52+
depreciated and may provide instruction or reason on how for clients to proceed.
53+
required (optional, bool): indicates this field as not null in the graphql scehma. Same behavior as
54+
graphene.NonNull. Default False.
55+
name (optional, str): the name of the GraphQL field (must be unique in a type). Defaults to attribute
56+
name.
57+
description (optional, str): the description of the GraphQL field in the schema.
58+
default_value (optional, Any): Default value to resolve if none set from schema.
59+
**extra_args (optional, Dict[str, Union[graphene.Argument, graphene.UnmountedType]): any
60+
additional arguments to mount on the field.
61+
"""
62+
2263
def __init__(
2364
self,
2465
type,

graphene/types/inputfield.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,46 @@
44

55

66
class InputField(MountedType):
7+
"""
8+
Makes a field available on an ObjectType in the GraphQL schema. Any type can be mounted as a
9+
Input Field except Interface and Union:
10+
11+
- Object Type
12+
- Scalar Type
13+
- Enum
14+
15+
Input object types also can't have arguments on their input fields, unlike regular ``graphene.Field``.
16+
17+
All class attributes of ``graphene.InputObjectType`` are implicitly mounted as InputField
18+
using the below arguments.
19+
20+
.. code:: python
21+
22+
from graphene import InputObjectType, String, InputField
23+
24+
class Person(InputObjectType):
25+
# implicitly mounted as Input Field
26+
first_name = String(required=True)
27+
# explicitly mounted as Input Field
28+
last_name = InputField(String, description="Surname")
29+
30+
args:
31+
type (class for a graphene.UnmountedType): Must be a class (not an instance) of an
32+
unmounted graphene type (ex. scalar or object) which is used for the type of this
33+
field in the GraphQL schema.
34+
name (optional, str): Name of the GraphQL input field (must be unique in a type).
35+
Defaults to attribute name.
36+
default_value (optional, Any): Default value to use as input if none set in user operation (
37+
query, mutation, etc.).
38+
deprecation_reason (optional, str): Setting this value indicates that the field is
39+
depreciated and may provide instruction or reason on how for clients to proceed.
40+
description (optional, str): Description of the GraphQL field in the schema.
41+
required (optional, bool): Indicates this input field as not null in the graphql scehma.
42+
Raises a validation error if argument not provided. Same behavior as graphene.NonNull.
43+
Default False.
44+
**extra_args (optional, Dict): Not used.
45+
"""
46+
747
def __init__(
848
self,
949
type,

0 commit comments

Comments
 (0)