Skip to content

Commit 0dd6ea2

Browse files
committed
Make graphql-relay-py compatible with graphql-core-next
1 parent 08c5995 commit 0dd6ea2

30 files changed

+677
-928
lines changed

.gitignore

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
# Created by https://www.gitignore.io
2-
3-
### Python ###
4-
# Byte-compiled / optimized / DLL files
51
__pycache__/
62
*.py[cod]
73

8-
# C extensions
94
*.so
105

116
# Distribution / packaging
127
.Python
13-
env/
148
build/
159
develop-eggs/
1610
dist/
@@ -22,40 +16,51 @@ lib64/
2216
parts/
2317
sdist/
2418
var/
19+
wheels/
20+
pip-wheel-metadata/
21+
share/python-wheels/
2522
*.egg-info/
2623
.installed.cfg
2724
*.egg
25+
MANIFEST
2826

29-
# PyInstaller
30-
# Usually these files are written by a python script from a template
31-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
3227
*.manifest
3328
*.spec
3429

35-
# Installer logs
3630
pip-log.txt
3731
pip-delete-this-directory.txt
3832

39-
# Unit test / coverage reports
4033
htmlcov/
4134
.tox/
35+
.nox/
4236
.coverage
4337
.coverage.*
4438
.cache
4539
nosetests.xml
4640
coverage.xml
47-
*,cover
41+
*.cover
42+
.pytest_cache/
4843

4944
# Translations
5045
*.mo
5146
*.pot
5247

53-
# Django stuff:
5448
*.log
5549

56-
# Sphinx documentation
5750
docs/_build/
5851

59-
# PyBuilder
6052
target/
6153

54+
.python-version
55+
56+
.env
57+
.venv
58+
env/
59+
venv/
60+
ENV/
61+
env.bak/
62+
venv.bak/
63+
64+
.mypy_cache/
65+
66+
.idea/

.travis.yml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
language: python
2-
dist: xenial
32

4-
python:
5-
- 2.7
6-
- 3.5
7-
- 3.6
8-
- 3.7
9-
- pypy3
3+
matrix:
4+
include:
5+
- env: TOXENV=flake8
6+
python: 3.7
7+
dist: xenial
8+
sudo: true
9+
- env: TOXENV=py37
10+
python: 3.7
11+
dist: xenial
12+
sudo: true
13+
- env: TOXENV=py36
14+
python: 3.6
15+
16+
cache:
17+
directories:
18+
- $HOME/.cache/pip
19+
- $TRAVIS_BUILD_DIR/.tox
20+
1021
install:
11-
- pip install pytest pytest-cov flake8
22+
- pip install pytest pytest-asyncio pytest-cov flake8
1223
- pip install .
24+
1325
script:
14-
- py.test --cov=graphql_relay
15-
# - flake8
26+
- tox -e $TOXENV -- --cov-report term-missing --cov=graphql
27+
1628
after_success:
17-
- pip install coveralls
18-
- coveralls
29+
- codecov

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @Cito

MANIFEST.in

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1+
include MANIFEST.in
2+
3+
include CODEOWNERS
4+
include LICENSE
5+
include README.md
6+
7+
include codecov.yml
8+
include tox.ini
9+
10+
graft graphql
11+
112
global-exclude tests/*
213
recursive-exclude tests *
3-
recursive-exclude tests_py35 *
4-
include LICENSE
14+
15+
global-exclude *.py[co] __pycache__

README.md

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ describes a simple set of examples that exist as [tests](tests) in this
3131
repository. A good way to get started with this repository is to walk through
3232
that documentation and the corresponding tests in this library together.
3333

34-
## Using Relay Library for GraphQL Python (graphql-core)
34+
## Using Relay Library for GraphQL Python (graphql-core-next)
3535

3636
Install Relay Library for GraphQL Python
3737

3838
```sh
39-
pip install graphql-core --pre # Last version of graphql-core
39+
pip install graphql-core-next
4040
pip install graphql-relay
4141
```
4242

@@ -69,25 +69,23 @@ An example usage of these methods from the [test schema](tests/starwars/schema.p
6969
ship_edge, ship_connection = connection_definitions('Ship', shipType)
7070

7171
factionType = GraphQLObjectType(
72-
name= 'Faction',
73-
description= 'A faction in the Star Wars saga',
74-
fields= lambda: {
72+
name='Faction',
73+
description='A faction in the Star Wars saga',
74+
fields=lambda: {
7575
'id': global_id_field('Faction'),
7676
'name': GraphQLField(
7777
GraphQLString,
7878
description='The name of the faction.',
7979
),
8080
'ships': GraphQLField(
81-
shipConnection,
82-
description= 'The ships used by the faction.',
83-
args= connection_args,
84-
resolver= lambda faction, args, *_: connection_from_list(
85-
map(getShip, faction.ships),
86-
args
87-
),
81+
ship_connection,
82+
description='The ships used by the faction.',
83+
args=connection_args,
84+
resolve=lambda faction, _info, **args: connection_from_list(
85+
[getShip(ship) for ship in faction.ships], args),
8886
)
8987
},
90-
interfaces= [node_interface]
88+
interfaces=[node_interface]
9189
)
9290
```
9391

@@ -108,7 +106,7 @@ this, it takes a function to resolve an ID to an object, and to determine
108106
the type of a given object.
109107
- `to_global_id` takes a type name and an ID specific to that type name,
110108
and returns a "global ID" that is unique among all types.
111-
- `from_global_id` takes the "global ID" created by `toGlobalID`, and retuns
109+
- `from_global_id` takes the "global ID" created by `toGlobalID`, and returns
112110
the type name and ID used to create it.
113111
- `global_id_field` creates the configuration for an `id` field on a node.
114112
- `plural_identifying_root_field` creates a field that accepts a list of
@@ -118,17 +116,16 @@ objects.
118116
An example usage of these methods from the [test schema](tests/starwars/schema.py):
119117

120118
```python
121-
def get_node(global_id, context, info):
122-
resolvedGlobalId = from_global_id(global_id)
123-
_type, _id = resolvedGlobalId.type, resolvedGlobalId.id
124-
if _type == 'Faction':
125-
return getFaction(_id)
126-
elif _type == 'Ship':
127-
return getShip(_id)
119+
def get_node(global_id, _info):
120+
type_, id_ = from_global_id(global_id)
121+
if type_ == 'Faction':
122+
return getFaction(id_)
123+
elif type_ == 'Ship':
124+
return getShip(id_)
128125
else:
129126
return None
130127

131-
def get_node_type(obj, context, info):
128+
def get_node_type(obj, _info, _type):
132129
if isinstance(obj, Faction):
133130
return factionType
134131
else:
@@ -173,47 +170,42 @@ configuration that can be used as a top-level field on the mutation type.
173170
An example usage of these methods from the [test schema](tests/starwars/schema.py):
174171

175172
```python
176-
class IntroduceShipMutation(object):
173+
class IntroduceShipMutation:
177174
def __init__(self, shipId, factionId, clientMutationId=None):
178175
self.shipId = shipId
179176
self.factionId = factionId
180-
self.clientMutationId = None
177+
self.clientMutationId = clientMutationId
181178

182-
def mutate_and_get_payload(data, *_):
183-
shipName = data.get('shipName')
184-
factionId = data.get('factionId')
179+
def mutate_and_get_payload(_info, shipName, factionId, **_input):
185180
newShip = createShip(shipName, factionId)
186-
return IntroduceShipMutation(
187-
shipId=newShip.id,
188-
factionId=factionId,
189-
)
181+
return IntroduceShipMutation(shipId=newShip.id, factionId=factionId)
190182

191183
shipMutation = mutation_with_client_mutation_id(
192184
'IntroduceShip',
193185
input_fields={
194-
'shipName': GraphQLField(
186+
'shipName': GraphQLInputField(
195187
GraphQLNonNull(GraphQLString)
196188
),
197-
'factionId': GraphQLField(
189+
'factionId': GraphQLInputField(
198190
GraphQLNonNull(GraphQLID)
199191
)
200192
},
201-
output_fields= {
193+
output_fields={
202194
'ship': GraphQLField(
203195
shipType,
204-
resolver= lambda payload, *_: getShip(payload.shipId)
196+
resolve=lambda payload, _info: getShip(payload.shipId)
205197
),
206198
'faction': GraphQLField(
207199
factionType,
208-
resolver= lambda payload, *_: getFaction(payload.factionId)
200+
resolve=lambda payload, _info: getFaction(payload.factionId)
209201
)
210202
},
211203
mutate_and_get_payload=mutate_and_get_payload
212204
)
213205

214206
mutationType = GraphQLObjectType(
215207
'Mutation',
216-
fields= lambda: {
208+
fields=lambda: {
217209
'introduceShip': shipMutation
218210
}
219211
)

0 commit comments

Comments
 (0)