Skip to content

Commit 2999def

Browse files
committed
Document differences from GraphQL.js
1 parent da6f8ea commit 2999def

File tree

5 files changed

+106
-3
lines changed

5 files changed

+106
-3
lines changed

docs/conf.py

+12
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@
8484
# This patterns also effect to html_static_path and html_extra_path
8585
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
8686

87+
# AutoDoc configuration
88+
#autoclass_content = "both"
89+
autodoc_default_options = {
90+
'members': True,
91+
'inherited-members': True,
92+
'private-members': False,
93+
'special-members': '__init__',
94+
'undoc-members': True,
95+
'show-inheritance': True
96+
}
97+
autosummary_generate = True
98+
8799
# The reST default role (used for this markup: `text`) to use for all
88100
# documents.
89101
#

docs/diffs.rst

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
Differences from GraphQL.js
2+
===========================
3+
4+
The goal of GraphQL-core 3 is to be a faithful replication of `GraphQL.js`_, the JavaScript reference implementation for GraphQL, in Python 3, and to keep it aligned and up to date with the ongoing development of GraphQL.js. Therefore, we strive to be as compatible as possible to the original JavaScript library, sometimes at the cost of being less Pythonic than other libraries written particularly for Python. We also avoid incorporating additional features that do not exist in the JavaScript library, in order to keep the task of maintaining the Python code and keeping it in line with the JavaScript code manageable. The preferred way of getting new features into GraphQL-core is to propose and discuss them on the `GraphQL.js issue tracker`_ first, try to get them included into GraphQL.js, and from there ported to GraphQL-core.
5+
6+
.. _GraphQL.js: https://github.com/graphql/graphql-js
7+
.. _GraphQL.js issue tracker: https://github.com/graphql/graphql-js/issues
8+
.. _Graphene: https://graphene-python.org/
9+
10+
.. currentmodule:: graphql
11+
12+
Having said this, in a few places we allowed the API to be a bit more Pythonic than the direct equivalent would have been. We also added a few features that do not exist in the JavaScript library, mostly to support existing higher level libraries such as Graphene_ and the different naming conventions in Python. The most notable differences are the following:
13+
14+
15+
Direct attributes access in GraphQL types
16+
-----------------------------------------
17+
18+
You can access
19+
20+
* the **fields** of GraphQLObjectTypes, GraphQLInterfaceTypes and GraphQLInputObjectTypes,
21+
* the **interfaces** of GraphQLObjectTypes,
22+
* the **types** of GraphQLUnionTypes, and
23+
* the **values** of GraphQLEnumTypes
24+
25+
directly as attributes, instead of using getters.
26+
27+
For example, to get the fields of a GraphQLObjectType ``obj``, you write ``obj.fields`` instead of ``obj.getFields()``.
28+
29+
30+
Arguments, fields and values are lists
31+
--------------------------------------
32+
33+
* The **arguments** of GraphQLDirectives and GraphQLFields,
34+
* the **fields** of GraphQLObjectTypes, GraphQLInterfaceTypes and GraphQLInputObjectTypes, and
35+
* the **values** of GraphQLEnumTypes
36+
37+
are always Python dictionaries in GraphQL-core, while they are returned as Arrays in GraphQL.js. Also, the values of these dictionaries do not have ``name`` attributes, since the names are already used as the keys of these dictionaries.
38+
39+
40+
Shorthand notations for creating GraphQL types
41+
----------------------------------------------
42+
43+
The following shorthand notations are possible:
44+
45+
* Where you need to pass a GraphQLArgumentMap, i.e. a dictionary with names as keys and GraphQLArguments as values, you can also pass GraphQLInputTypes as values. The GraphQLInputTypes are then automatically wrapped into GraphQLArguments.
46+
* Where you need to pass a GraphQLFieldMap, i.e. a dictionary with names as keys and GraphQLFields as values, you can also pass GraphQLOutputTypes as values. The GraphQLOutputTypes are then automatically wrapped into GraphQLFields.
47+
* Where you need to pass a GraphQLInputFieldMap, i.e. a dictionary with names as keys and GraphQLInputFields as values, you can also pass GraphQLInputTypes as values. The GraphQLInputTypes are then automatically wrapped into GraphQLInputFields.
48+
* 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.
49+
50+
51+
Custom output names of arguments and input fields
52+
-------------------------------------------------
53+
54+
You can pass a custom ``out_name`` argument to :class:`GraphQLArgument` and :class:`GraphQLInputField` that allows using JavaScript naming conventions (camelCase) on ingress and Python naming conventions (snake_case) on egress. This feature is used by Graphene.
55+
56+
57+
Custom output types of input object types
58+
-----------------------------------------
59+
60+
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.
61+
62+
63+
Custom Middleware
64+
-----------------
65+
66+
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.
67+
68+
69+
Custom execution contexts
70+
-------------------------
71+
72+
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.
73+
74+
75+
Registering other types for descriptions
76+
----------------------------------------
77+
78+
Normally, descriptions for GraphQL types must be strings. However, sometimes you may want to use other kinds of objects which are not strings, but are only resolved to strings at runtime. This is possible if you register the classes of such objects with :func:`pyutils.register_description`.
79+
80+
81+
Overridable type map reducer
82+
----------------------------
83+
84+
It is possible to override the :meth:`GraphQLSchema.type_map_reducer` method with a custom implementation. This is used by Graphene to convert its own types to the GraphQL-core types.
85+
86+
87+
If you notice any other important differences, please let us know so that they can be either removed or listed here.

docs/index.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ Contents
88
:maxdepth: 2
99

1010
intro
11-
1211
usage/index
13-
12+
diffs
1413
modules/graphql
1514

1615

src/graphql/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@
267267
# Types
268268
ExecutionContext,
269269
ExecutionResult,
270+
# Middleware
271+
Middleware,
272+
MiddlewareManager,
270273
)
271274

272275
from .subscription import subscribe, create_source_event_stream
@@ -593,6 +596,8 @@
593596
"get_directive_values",
594597
"ExecutionContext",
595598
"ExecutionResult",
599+
"Middleware",
600+
"MiddlewareManager",
596601
"subscribe",
597602
"create_source_event_stream",
598603
"validate",

src/graphql/type/schema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class GraphQLSchema:
6464
# you want them to be included in the final schema.
6565
types=[human_type, droid_type])
6666
67-
Note: If a list of `directives` are provided to GraphQLSchema, that will be the
67+
Note: If a list of `directives` is provided to GraphQLSchema, that will be the
6868
exact list of directives represented and allowed. If `directives` is not provided,
6969
then a default set of the specified directives (e.g. @include and @skip) will be
7070
used. If you wish to provide *additional* directives to these specified directives,

0 commit comments

Comments
 (0)