Skip to content

Commit 22970e9

Browse files
committed
Upgrade Sphinx and fix various autodoc issues (#104)
1 parent c013660 commit 22970e9

24 files changed

+345
-243
lines changed

docs/conf.py

Lines changed: 108 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -85,50 +85,121 @@
8585
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
8686

8787
# AutoDoc configuration
88-
#autoclass_content = "both"
88+
autoclass_content = "class"
8989
autodoc_default_options = {
9090
'members': True,
9191
'inherited-members': True,
92-
'private-members': False,
9392
'special-members': '__init__',
9493
'undoc-members': True,
9594
'show-inheritance': True
9695
}
9796
autosummary_generate = True
9897

99-
# ignore certain warnings
100-
# (references to some of the Python built-in types do not resolve correctly)
98+
# GraphQL-core top level modules with submodules that can be omitted.
99+
# Sometimes autodoc cannot find classes since it is looking for the
100+
# qualified form, but the documentation has the shorter form.
101+
# We need to give autodoc a little help in this cases.
102+
graphql_modules = {
103+
'error': ['graphql_error'],
104+
'execution': ['execute', 'middleware'],
105+
'language': ['ast', 'directive_locations', 'location',
106+
'source', 'token_kind', 'visitor'],
107+
'pyutils': ['event_emitter', 'frozen_list', 'path'],
108+
'type': ['definition', 'directives', 'schema'],
109+
'utilities': ['find_breaking_changes', 'type_info'],
110+
'validation': ['rules', 'validation_context']}
111+
112+
# GraphQL-core classes that autodoc sometimes cannot find
113+
# (e.g. where specified as string in type hints).
114+
# We need to give autodoc a little help in this cases, too:
115+
graphql_classes = {
116+
'GraphQLAbstractType': 'type',
117+
'GraphQLObjectType': 'type',
118+
'Node': 'language',
119+
'Source': 'language',
120+
'SourceLocation': 'language'
121+
}
122+
123+
# ignore the following undocumented or internal references:
124+
ignore_references = set('''
125+
GNT GT T
126+
enum.Enum
127+
asyncio.events.AbstractEventLoop
128+
graphql.type.schema.InterfaceImplementations
129+
graphql.validation.validation_context.VariableUsage
130+
graphql.validation.rules.known_argument_names.KnownArgumentNamesOnDirectivesRule
131+
graphql.validation.rules.provided_required_arguments.ProvidedRequiredArgumentsOnDirectivesRule
132+
'''.split())
133+
134+
ignore_references.update(__builtins__.keys())
135+
136+
137+
def on_missing_reference(app, env, node, contnode):
138+
"""Fix or skip any missing references."""
139+
if node.get('refdomain') != 'py':
140+
return None
141+
target = node.get('reftarget')
142+
if not target:
143+
return None
144+
if target in ignore_references:
145+
return contnode
146+
typ = node.get('reftype')
147+
if typ != 'class':
148+
return None
149+
if '.' in target: # maybe too specific
150+
base_module, target = target.split('.', 1)
151+
if base_module == 'typing':
152+
return contnode
153+
if base_module == 'graphql':
154+
if '.' not in target:
155+
return None
156+
base_module, target = target.split('.', 1)
157+
if '.' not in target:
158+
return None
159+
sub_modules = graphql_modules.get(base_module)
160+
if not sub_modules:
161+
return
162+
sub_module = target.split('.', 1)[0]
163+
if sub_module not in sub_modules:
164+
return None
165+
target = 'graphql.' + base_module + '.' + target.rsplit('.', 1)[-1]
166+
else: # maybe not specific enough
167+
base_module = graphql_classes.get(target)
168+
if not base_module:
169+
return None
170+
target = 'graphql.' + base_module + '.' + target
171+
# replace target
172+
if contnode.__class__.__name__ == 'Text':
173+
contnode = contnode.__class__(target)
174+
elif contnode.__class__.__name__ == 'literal':
175+
if len(contnode.children) != 1:
176+
return None
177+
textnode = contnode.children[0]
178+
contnode.children[0] = textnode.__class__(target)
179+
else:
180+
return None
181+
node['reftarget'] = target
182+
fromdoc = node.get('refdoc')
183+
if not fromdoc:
184+
doc_module = node.get('py:module')
185+
if doc_module:
186+
if doc_module.startswith('graphql.'):
187+
doc_module = doc_module.split('.', 1)[-1]
188+
if doc_module not in graphql_modules:
189+
doc_module = None
190+
fromdoc = 'modules/' + (doc_module or base_module)
191+
# try resolving again with replaced target
192+
return env.domains['py'].resolve_xref(
193+
env, fromdoc, app.builder, typ, target, node, contnode)
194+
195+
196+
def setup(app):
197+
app.connect('missing-reference', on_missing_reference)
198+
199+
200+
# be nitpicky (handle all possible problems in on_missing_reference)
101201
nitpicky = True
102-
nitpick_ignore = [('py:class', t) for t in (
103-
'dict', 'list', 'object', 'tuple',
104-
'Exception', 'TypeError', 'ValueError',
105-
'builtins.str', 'enum.Enum',
106-
'typing.Callable', 'typing.Dict', 'typing.Generic', 'typing.List',
107-
'graphql.pyutils.cached_property.CachedProperty',
108-
'graphql.pyutils.path.Path',
109-
'graphql.error.graphql_error.GraphQLError',
110-
'graphql.language.ast.DefinitionNode',
111-
'graphql.language.ast.ExecutableDefinitionNode',
112-
'graphql.language.ast.Node',
113-
'graphql.language.ast.ScalarTypeDefinitionNode',
114-
'graphql.language.ast.SelectionNode',
115-
'graphql.language.ast.TypeDefinitionNode',
116-
'graphql.language.ast.TypeExtensionNode',
117-
'graphql.language.ast.TypeNode',
118-
'graphql.language.ast.TypeSystemDefinitionNode',
119-
'graphql.language.ast.ValueNode',
120-
'graphql.language.visitor.Visitor',
121-
'graphql.type.definition.GraphQLNamedType',
122-
'graphql.type.definition.GraphQLType',
123-
'graphql.type.definition.GraphQLWrappingType',
124-
'graphql.validation.rules.ASTValidationRule',
125-
'graphql.validation.rules.SDLValidationRule',
126-
'graphql.validation.rules.ValidationRule',
127-
'graphql.validation.validation_context.ASTValidationContext',
128-
'graphql.validation.rules.known_argument_names'
129-
'.KnownArgumentNamesOnDirectivesRule',
130-
'graphql.validation.rules.provided_required_arguments'
131-
'.ProvidedRequiredArgumentsOnDirectivesRule')]
202+
132203

133204
# The reST default role (used for this markup: `text`) to use for all
134205
# documents.
@@ -172,7 +243,9 @@
172243
# further. For a list of options available for each theme, see the
173244
# documentation.
174245
#
175-
# html_theme_options = {}
246+
html_theme_options = {
247+
'navigation_depth': 5
248+
}
176249

177250
# Add any paths that contain custom themes here, relative to this directory.
178251
# html_theme_path = []

docs/diffs.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ The following shorthand notations are possible:
4949
* Where you need to pass a GraphQLEnumValueMap, i.e. a dictionary with names as keys and GraphQLEnumValues as values, you can pass any other Python objects as values. These will be automatically wrapped into GraphQLEnumValues. You can also pass a Python Enum type as GraphQLEnumValueMap.
5050

5151

52+
.. currentmodule:: graphql.type
53+
5254
Custom output names of arguments and input fields
5355
-------------------------------------------------
5456

@@ -61,18 +63,22 @@ Custom output types of input object types
6163
You can also pass a custom ``out_type`` argument to :class:`GraphQLInputObjectType` that allows conversion to any Python type on egress instead of conversion to a dictionary, which is the default. This is used to support the container feature of Graphene InputObjectTypes.
6264

6365

66+
.. currentmodule:: graphql.execution
67+
6468
Custom middleware
6569
-----------------
6670

67-
The :func:`execution.execute` function takes an additional ``middleware`` argument which must be a sequence of middleware functions or a :class:`MiddlewareManager` object. This feature is used by Graphene to affect the evaluation of fields using custom middleware. There has been a `request <https://github.com/graphql/graphql-js/issues/1516>`_ to add this to GraphQL.js as well, but so far this feature only exists in GraphQL-core.
71+
The :func:`execute` function takes an additional ``middleware`` argument which must be a sequence of middleware functions or a :class:`MiddlewareManager` object. This feature is used by Graphene to affect the evaluation of fields using custom middleware. There has been a `request <https://github.com/graphql/graphql-js/issues/1516>`_ to add this to GraphQL.js as well, but so far this feature only exists in GraphQL-core.
6872

6973

7074
Custom execution context
7175
------------------------
7276

73-
The :func:`execution.execute` function takes an additional ``execution_context_class`` argument which allows specifying a custom execution context class instead of the default :class:`ExecutionContext` used by GraphQL-core.
77+
The :func:`execute` function takes an additional ``execution_context_class`` argument which allows specifying a custom execution context class instead of the default :class:`ExecutionContext` used by GraphQL-core.
7478

7579

80+
.. currentmodule:: graphql
81+
7682
Registering special types for descriptions
7783
------------------------------------------
7884

docs/modules/error.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,3 @@ Error
44
.. currentmodule:: graphql.error
55

66
.. automodule:: graphql.error
7-
8-
.. autoexception:: GraphQLError
9-
:members:
10-
11-
.. autoexception:: GraphQLSyntaxError
12-
13-
.. autofunction:: format_error
14-
.. autofunction:: located_error
15-
.. autofunction:: print_error

docs/modules/execution.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,3 @@ Execution
44
.. currentmodule:: graphql.execution
55

66
.. automodule:: graphql.execution
7-
8-
.. autofunction:: execute
9-
.. autofunction:: default_field_resolver
10-
11-
.. autoclass:: ExecutionContext
12-
.. autoclass:: ExecutionResult
13-
14-
.. autofunction:: get_directive_values
15-

docs/modules/graphql.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Reference
44
.. currentmodule:: graphql
55

66
.. automodule:: graphql
7+
:no-members:
8+
:no-inherited-members:
79

810
.. _top-level-functions:
911

@@ -19,7 +21,7 @@ Sub-Packages
1921
------------
2022

2123
.. toctree::
22-
:maxdepth: 1
24+
:maxdepth: 2
2325

2426
error
2527
execution

docs/modules/language.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
Language
22
========
33

4+
.. currentmodule:: graphql.language
5+
46
.. automodule:: graphql.language
7+
:no-members:
8+
:no-inherited-members:
59

610
AST
711
---
@@ -65,6 +69,10 @@ Each kind of AST node has its own class:
6569
.. autoclass:: VariableDefinitionNode
6670
.. autoclass:: VariableNode
6771

72+
Directive locations are specified using the following enumeration:
73+
74+
.. autoclass:: DirectiveLocation
75+
6876
Lexer
6977
-----
7078

@@ -99,8 +107,17 @@ Visitor
99107
.. autoclass:: Visitor
100108
.. autoclass:: ParallelVisitor
101109

102-
The module also exports the following special symbols which can be used as
103-
return values in the :class:`Visitor` methods to signal particular actions:
110+
The module also exports the following enumeration that can be used as the return type
111+
for :class:`Visitor` methods:
112+
113+
.. currentmodule:: graphql.language.visitor
114+
115+
.. autoclass:: VisitorActionEnum
116+
117+
.. currentmodule:: graphql.language
118+
119+
The module also exports the values of this enumeration directly. These can be used as
120+
return values of :class:`Visitor` methods to signal particular actions:
104121

105122
.. data:: BREAK
106123
:annotation: (same as ``True``)

docs/modules/pyutils.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PyUtils
44
.. currentmodule:: graphql.pyutils
55

66
.. automodule:: graphql.pyutils
7+
:no-members:
8+
:no-inherited-members:
79

810
.. autofunction:: camel_to_snake
911
.. autofunction:: snake_to_camel
@@ -12,21 +14,26 @@ PyUtils
1214
.. autofunction:: register_description
1315
.. autofunction:: unregister_description
1416
.. autoclass:: EventEmitter
15-
:members:
1617
.. autoclass:: EventEmitterAsyncIterator
17-
:members:
1818
.. autofunction:: identity_func
1919
.. autofunction:: inspect
2020
.. autofunction:: is_finite
2121
.. autofunction:: is_integer
2222
.. autoclass:: AwaitableOrValue
23-
:members:
2423
.. autofunction:: suggestion_list
2524
.. autoclass:: FrozenError
25+
:no-members:
26+
:no-inherited-members:
27+
:no-special-members:
2628
.. autoclass:: FrozenList
29+
:no-members:
30+
:no-inherited-members:
31+
:no-special-members:
2732
.. autoclass:: FrozenDict
33+
:no-members:
34+
:no-inherited-members:
35+
:no-special-members:
2836
.. autoclass:: Path
29-
:members:
3037
.. autofunction:: print_path_list
3138

3239
.. autodata:: Undefined

docs/modules/subscription.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ Subscription
55

66
.. automodule:: graphql.subscription
77

8-
.. autofunction:: subscribe
9-
.. autofunction:: create_source_event_stream
10-

docs/modules/type.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Type
44
.. currentmodule:: graphql.type
55

66
.. automodule:: graphql.type
7-
7+
:no-members:
8+
:no-inherited-members:
89

910
Definition
1011
----------

docs/modules/utilities.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Utilities
44
.. currentmodule:: graphql.utilities
55

66
.. automodule:: graphql.utilities
7+
:no-members:
8+
:no-inherited-members:
79

810
The GraphQL query recommended for a full schema introspection:
911

0 commit comments

Comments
 (0)