Skip to content

Commit

Permalink
Make graphql-relay-py compatible with graphql-core-next
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Jun 28, 2019
1 parent 08c5995 commit 0dd6ea2
Show file tree
Hide file tree
Showing 30 changed files with 677 additions and 928 deletions.
35 changes: 20 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# Created by https://www.gitignore.io

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
Expand All @@ -22,40 +16,51 @@ lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

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

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.cover
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

.python-version

.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

.mypy_cache/

.idea/
35 changes: 23 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
language: python
dist: xenial

python:
- 2.7
- 3.5
- 3.6
- 3.7
- pypy3
matrix:
include:
- env: TOXENV=flake8
python: 3.7
dist: xenial
sudo: true
- env: TOXENV=py37
python: 3.7
dist: xenial
sudo: true
- env: TOXENV=py36
python: 3.6

cache:
directories:
- $HOME/.cache/pip
- $TRAVIS_BUILD_DIR/.tox

install:
- pip install pytest pytest-cov flake8
- pip install pytest pytest-asyncio pytest-cov flake8
- pip install .

script:
- py.test --cov=graphql_relay
# - flake8
- tox -e $TOXENV -- --cov-report term-missing --cov=graphql

after_success:
- pip install coveralls
- coveralls
- codecov
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @Cito
15 changes: 13 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
include MANIFEST.in

include CODEOWNERS
include LICENSE
include README.md

include codecov.yml
include tox.ini

graft graphql

global-exclude tests/*
recursive-exclude tests *
recursive-exclude tests_py35 *
include LICENSE

global-exclude *.py[co] __pycache__
66 changes: 29 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ describes a simple set of examples that exist as [tests](tests) in this
repository. A good way to get started with this repository is to walk through
that documentation and the corresponding tests in this library together.

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

Install Relay Library for GraphQL Python

```sh
pip install graphql-core --pre # Last version of graphql-core
pip install graphql-core-next
pip install graphql-relay
```

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

factionType = GraphQLObjectType(
name= 'Faction',
description= 'A faction in the Star Wars saga',
fields= lambda: {
name='Faction',
description='A faction in the Star Wars saga',
fields=lambda: {
'id': global_id_field('Faction'),
'name': GraphQLField(
GraphQLString,
description='The name of the faction.',
),
'ships': GraphQLField(
shipConnection,
description= 'The ships used by the faction.',
args= connection_args,
resolver= lambda faction, args, *_: connection_from_list(
map(getShip, faction.ships),
args
),
ship_connection,
description='The ships used by the faction.',
args=connection_args,
resolve=lambda faction, _info, **args: connection_from_list(
[getShip(ship) for ship in faction.ships], args),
)
},
interfaces= [node_interface]
interfaces=[node_interface]
)
```

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

```python
def get_node(global_id, context, info):
resolvedGlobalId = from_global_id(global_id)
_type, _id = resolvedGlobalId.type, resolvedGlobalId.id
if _type == 'Faction':
return getFaction(_id)
elif _type == 'Ship':
return getShip(_id)
def get_node(global_id, _info):
type_, id_ = from_global_id(global_id)
if type_ == 'Faction':
return getFaction(id_)
elif type_ == 'Ship':
return getShip(id_)
else:
return None

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

```python
class IntroduceShipMutation(object):
class IntroduceShipMutation:
def __init__(self, shipId, factionId, clientMutationId=None):
self.shipId = shipId
self.factionId = factionId
self.clientMutationId = None
self.clientMutationId = clientMutationId

def mutate_and_get_payload(data, *_):
shipName = data.get('shipName')
factionId = data.get('factionId')
def mutate_and_get_payload(_info, shipName, factionId, **_input):
newShip = createShip(shipName, factionId)
return IntroduceShipMutation(
shipId=newShip.id,
factionId=factionId,
)
return IntroduceShipMutation(shipId=newShip.id, factionId=factionId)

shipMutation = mutation_with_client_mutation_id(
'IntroduceShip',
input_fields={
'shipName': GraphQLField(
'shipName': GraphQLInputField(
GraphQLNonNull(GraphQLString)
),
'factionId': GraphQLField(
'factionId': GraphQLInputField(
GraphQLNonNull(GraphQLID)
)
},
output_fields= {
output_fields={
'ship': GraphQLField(
shipType,
resolver= lambda payload, *_: getShip(payload.shipId)
resolve=lambda payload, _info: getShip(payload.shipId)
),
'faction': GraphQLField(
factionType,
resolver= lambda payload, *_: getFaction(payload.factionId)
resolve=lambda payload, _info: getFaction(payload.factionId)
)
},
mutate_and_get_payload=mutate_and_get_payload
)

mutationType = GraphQLObjectType(
'Mutation',
fields= lambda: {
fields=lambda: {
'introduceShip': shipMutation
}
)
Expand Down
Loading

0 comments on commit 0dd6ea2

Please sign in to comment.