@@ -2,14 +2,15 @@ Relay Library for GraphQL Python
2
2
================================
3
3
4
4
This is a library to allow the easy creation of Relay-compliant servers
5
- using the `GraphQL Python <https://github.com/graphql-python/graphql-core >`__
6
- reference implementation of a GraphQL server.
5
+ using the `GraphQL
6
+ Python <https://github.com/graphql-python/graphql-core> `__ reference
7
+ implementation of a GraphQL server.
7
8
8
9
Note: The code is a **exact ** port of the original `graphql-relay js
9
10
implementation <https://github.com/graphql/graphql-relay-js> `__ from
10
11
Facebook
11
12
12
- |Build Status | |Coverage Status |
13
+ |PyPI version | | Build Status | |Coverage Status |
13
14
14
15
Getting Started
15
16
---------------
@@ -36,7 +37,7 @@ this repository is to walk through that documentation and the
36
37
corresponding tests in this library together.
37
38
38
39
Using Relay Library for GraphQL Python (graphql-core)
39
- ---------------------------------------------------
40
+ -----------------------------------------------------
40
41
41
42
Install Relay Library for GraphQL Python
42
43
@@ -46,8 +47,9 @@ Install Relay Library for GraphQL Python
46
47
pip install graphql-relay
47
48
48
49
When building a schema for
49
- `GraphQL <https://github.com/graphql-python/graphql-core >`__, the provided library
50
- functions can be used to simplify the creation of Relay patterns.
50
+ `GraphQL <https://github.com/graphql-python/graphql-core >`__, the
51
+ provided library functions can be used to simplify the creation of Relay
52
+ patterns.
51
53
52
54
Connections
53
55
~~~~~~~~~~~
@@ -61,9 +63,9 @@ returning those types.
61
63
- ``connection_definitions `` returns a ``connection_type `` and its
62
64
associated ``edgeType ``, given a name and a node type.
63
65
- ``connection_from_list `` is a helper method that takes an array and
64
- the arguments from ``connection_args ``, does pagination and filtering,
65
- and returns an object in the shape expected by a `` connection_type ``'s
66
- ``resolver `` function.
66
+ the arguments from ``connection_args ``, does pagination and
67
+ filtering, and returns an object in the shape expected by a
68
+ ``connection_type ``'s `` resolver `` function.
67
69
- ``connection_from_promised_list `` is similar to
68
70
``connection_from_list ``, but it takes a promise that resolves to an
69
71
array, and returns a promise that resolves to the expected shape by
@@ -77,7 +79,7 @@ schema <tests/starwars/schema.py>`__:
77
79
78
80
.. code :: python
79
81
80
- shipConnection = connection_definitions(' Ship' , shipType).connection_type
82
+ ship_edge, ship_connection = connection_definitions(' Ship' , shipType)
81
83
82
84
factionType = GraphQLObjectType(
83
85
name = ' Faction' ,
@@ -120,20 +122,20 @@ nodes and for implementing global IDs around local IDs.
120
122
to an object, and to determine the type of a given object.
121
123
- ``to_global_id `` takes a type name and an ID specific to that type
122
124
name, and returns a "global ID" that is unique among all types.
123
- - ``from_global_id `` takes the "global ID" created by ``toGlobalID ``, and
124
- retuns the type name and ID used to create it.
125
- - ``global_id_field `` creates the configuration for an ``id `` field on a
126
- node.
127
- - ``plural_identifying_root_field `` creates a field that accepts a list of
128
- non-ID identifiers (like a username) and maps then to their
125
+ - ``from_global_id `` takes the "global ID" created by ``toGlobalID ``,
126
+ and retuns the type name and ID used to create it.
127
+ - ``global_id_field `` creates the configuration for an ``id `` field on
128
+ a node.
129
+ - ``plural_identifying_root_field `` creates a field that accepts a list
130
+ of non-ID identifiers (like a username) and maps then to their
129
131
corresponding objects.
130
132
131
133
An example usage of these methods from the `test
132
134
schema <tests/starwars/schema.py> `__:
133
135
134
136
.. code :: python
135
137
136
- def get_node (global_id , * args ):
138
+ def get_node (global_id , context , info ):
137
139
resolvedGlobalId = from_global_id(global_id)
138
140
_type, _id = resolvedGlobalId.type, resolvedGlobalId.id
139
141
if _type == ' Faction' :
@@ -143,14 +145,13 @@ schema <tests/starwars/schema.py>`__:
143
145
else :
144
146
return None
145
147
146
- def get_node_type (obj ):
148
+ def get_node_type (obj , context , info ):
147
149
if isinstance (obj, Faction):
148
150
return factionType
149
151
else :
150
152
return shipType
151
153
152
- _node_definitions = node_definitions(get_node, get_node_type)
153
- node_field, node_interface = _node_definitions.node_field, _node_definitions.node_interface
154
+ node_interface, node_field = node_definitions(get_node, get_node_type)
154
155
155
156
factionType = GraphQLObjectType(
156
157
name = ' Faction' ,
@@ -182,11 +183,11 @@ Mutations
182
183
A helper function is provided for building mutations with single inputs
183
184
and client mutation IDs.
184
185
185
- - ``mutation_with_client_mutation_id `` takes a name, input fields, output
186
- fields, and a mutation method to map from the input fields to the
187
- output fields, performing the mutation along the way. It then creates
188
- and returns a field configuration that can be used as a top-level
189
- field on the mutation type.
186
+ - ``mutation_with_client_mutation_id `` takes a name, input fields,
187
+ output fields, and a mutation method to map from the input fields to
188
+ the output fields, performing the mutation along the way. It then
189
+ creates and returns a field configuration that can be used as a
190
+ top-level field on the mutation type.
190
191
191
192
An example usage of these methods from the `test
192
193
schema <tests/starwars/schema.py> `__:
@@ -240,10 +241,10 @@ schema <tests/starwars/schema.py>`__:
240
241
241
242
This code creates a mutation named ``IntroduceShip ``, which takes a
242
243
faction ID and a ship name as input. It outputs the ``Faction `` and the
243
- ``Ship `` in question. ``mutate_and_get_payload `` then gets an object with a
244
- property for each input field, performs the mutation by constructing the
245
- new ship, then returns an object that will be resolved by the output
246
- fields.
244
+ ``Ship `` in question. ``mutate_and_get_payload `` then gets an object
245
+ with a property for each input field, performs the mutation by
246
+ constructing the new ship, then returns an object that will be resolved
247
+ by the output fields.
247
248
248
249
Our mutation type then creates the ``introduceShip `` field using the
249
250
return value of ``mutation_with_client_mutation_id ``.
@@ -263,6 +264,8 @@ After developing, the full test suite can be evaluated by running:
263
264
264
265
python setup.py test # Use --pytest-args="-v -s" for verbose mode
265
266
267
+ .. |PyPI version | image :: https://badge.fury.io/py/graphql-relay.svg
268
+ :target: https://badge.fury.io/py/graphql-relay
266
269
.. |Build Status | image :: https://travis-ci.org/graphql-python/graphql-relay-py.svg?branch=master
267
270
:target: https://travis-ci.org/graphql-python/graphql-relay-py
268
271
.. |Coverage Status | image :: https://coveralls.io/repos/graphql-python/graphql-relay-py/badge.svg?branch=master&service=github
0 commit comments