Skip to content

Commit 957df3d

Browse files
authored
Merge branch 'master' into master
2 parents c821bce + a47dbb3 commit 957df3d

27 files changed

+858
-271
lines changed

.github/workflows/deploy.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 🚀 Deploy to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python 3.9
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.9
18+
- name: Build wheel and source tarball
19+
run: |
20+
pip install wheel
21+
python setup.py sdist bdist_wheel
22+
- name: Publish a Python distribution to PyPI
23+
uses: pypa/[email protected]
24+
with:
25+
user: __token__
26+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/lint.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Lint
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Set up Python 3.9
12+
uses: actions/setup-python@v2
13+
with:
14+
python-version: 3.9
15+
- name: Install dependencies
16+
run: |
17+
python -m pip install --upgrade pip
18+
pip install tox
19+
- name: Run lint 💅
20+
run: tox
21+
env:
22+
TOXENV: flake8

.github/workflows/tests.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
max-parallel: 10
10+
matrix:
11+
sql-alchemy: ["1.2", "1.3", "1.4"]
12+
python-version: ["3.6", "3.7", "3.8", "3.9"]
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install tox tox-gh-actions
24+
- name: Test with tox
25+
run: tox
26+
env:
27+
SQLALCHEMY: ${{ matrix.sql-alchemy }}
28+
TOXENV: ${{ matrix.toxenv }}
29+
- name: Upload coverage.xml
30+
if: ${{ matrix.sql-alchemy == '1.4' && matrix.python-version == '3.9' }}
31+
uses: actions/upload-artifact@v2
32+
with:
33+
name: graphene-sqlalchemy-coverage
34+
path: coverage.xml
35+
if-no-files-found: error
36+
- name: Upload coverage.xml to codecov
37+
if: ${{ matrix.sql-alchemy == '1.4' && matrix.python-version == '3.9' }}
38+
uses: codecov/codecov-action@v1

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ target/
6969
# Databases
7070
*.sqlite3
7171
.vscode
72+
73+
# mypy cache
74+
.mypy_cache/

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
default_language_version:
22
python: python3.7
33
repos:
4-
- repo: git://github.com/pre-commit/pre-commit-hooks
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
55
rev: c8bad492e1b1d65d9126dba3fe3bd49a5a52b9d6 # v2.1.0
66
hooks:
77
- id: check-merge-conflict
@@ -11,15 +11,15 @@ repos:
1111
exclude: ^docs/.*$
1212
- id: trailing-whitespace
1313
exclude: README.md
14-
- repo: git://github.com/PyCQA/flake8
14+
- repo: https://github.com/PyCQA/flake8
1515
rev: 88caf5ac484f5c09aedc02167c59c66ff0af0068 # 3.7.7
1616
hooks:
1717
- id: flake8
18-
- repo: git://github.com/asottile/seed-isort-config
18+
- repo: https://github.com/asottile/seed-isort-config
1919
rev: v1.7.0
2020
hooks:
2121
- id: seed-isort-config
22-
- repo: git://github.com/pre-commit/mirrors-isort
22+
- repo: https://github.com/pre-commit/mirrors-isort
2323
rev: v4.3.4
2424
hooks:
2525
- id: isort

.travis.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A [SQLAlchemy](http://www.sqlalchemy.org/) integration for [Graphene](http://gra
1010

1111
## Installation
1212

13-
For instaling graphene, just run this command in your shell
13+
For installing Graphene, just run this command in your shell.
1414

1515
```bash
1616
pip install "graphene-sqlalchemy>=2.0"
@@ -34,7 +34,7 @@ class UserModel(Base):
3434
last_name = Column(String)
3535
```
3636

37-
To create a GraphQL schema for it you simply have to write the following:
37+
To create a GraphQL schema for it, you simply have to write the following:
3838

3939
```python
4040
import graphene

graphene_sqlalchemy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .fields import SQLAlchemyConnectionField
33
from .utils import get_query, get_session
44

5-
__version__ = "2.3.0"
5+
__version__ = "3.0.0b1"
66

77
__all__ = [
88
"__version__",

graphene_sqlalchemy/batching.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
import aiodataloader
12
import sqlalchemy
2-
from promise import dataloader, promise
33
from sqlalchemy.orm import Session, strategies
44
from sqlalchemy.orm.query import QueryContext
55

6+
from .utils import is_sqlalchemy_version_less_than
7+
68

79
def get_batch_resolver(relationship_prop):
810

911
# Cache this across `batch_load_fn` calls
1012
# This is so SQL string generation is cached under-the-hood via `bakery`
1113
selectin_loader = strategies.SelectInLoader(relationship_prop, (('lazy', 'selectin'),))
1214

13-
class RelationshipLoader(dataloader.DataLoader):
15+
class RelationshipLoader(aiodataloader.DataLoader):
1416
cache = False
1517

16-
def batch_load_fn(self, parents): # pylint: disable=method-hidden
18+
async def batch_load_fn(self, parents):
1719
"""
1820
Batch loads the relationships of all the parents as one SQL statement.
1921
@@ -52,21 +54,36 @@ def batch_load_fn(self, parents): # pylint: disable=method-hidden
5254
states = [(sqlalchemy.inspect(parent), True) for parent in parents]
5355

5456
# For our purposes, the query_context will only used to get the session
55-
query_context = QueryContext(session.query(parent_mapper.entity))
56-
57-
selectin_loader._load_for_path(
58-
query_context,
59-
parent_mapper._path_registry,
60-
states,
61-
None,
62-
child_mapper,
63-
)
64-
65-
return promise.Promise.resolve([getattr(parent, relationship_prop.key) for parent in parents])
57+
query_context = None
58+
if is_sqlalchemy_version_less_than('1.4'):
59+
query_context = QueryContext(session.query(parent_mapper.entity))
60+
else:
61+
parent_mapper_query = session.query(parent_mapper.entity)
62+
query_context = parent_mapper_query._compile_context()
63+
64+
if is_sqlalchemy_version_less_than('1.4'):
65+
selectin_loader._load_for_path(
66+
query_context,
67+
parent_mapper._path_registry,
68+
states,
69+
None,
70+
child_mapper
71+
)
72+
else:
73+
selectin_loader._load_for_path(
74+
query_context,
75+
parent_mapper._path_registry,
76+
states,
77+
None,
78+
child_mapper,
79+
None
80+
)
81+
82+
return [getattr(parent, relationship_prop.key) for parent in parents]
6683

6784
loader = RelationshipLoader()
6885

69-
def resolve(root, info, **args):
70-
return loader.load(root)
86+
async def resolve(root, info, **args):
87+
return await loader.load(root)
7188

7289
return resolve

0 commit comments

Comments
 (0)