Skip to content

Commit e76ad9d

Browse files
committed
Merge pull request #63 from graphql-python/features/2.0-newresolvers
Adapted code to new resolvers API
2 parents fb6fb69 + 514eaae commit e76ad9d

File tree

10 files changed

+50
-34
lines changed

10 files changed

+50
-34
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ deploy:
5757
tags: true
5858
password:
5959
secure: q0ey31cWljGB30l43aEd1KIPuAHRutzmsd2lBb/2zvD79ReBrzvCdFAkH2xcyo4Volk3aazQQTNUIurnTuvBxmtqja0e+gUaO5LdOcokVdOGyLABXh7qhd2kdvbTDWgSwA4EWneLGXn/SjXSe0f3pCcrwc6WDcLAHxtffMvO9gulpYQtUoOqXfMipMOkRD9iDWTJBsSo3trL70X1FHOVr6Yqi0mfkX2Y/imxn6wlTWRz28Ru94xrj27OmUnCv7qcG0taO8LNlUCquNFAr2sZ+l+U/GkQrrM1y+ehPz3pmI0cCCd7SX/7+EG9ViZ07BZ31nk4pgnqjmj3nFwqnCE/4IApGnduqtrMDF63C9TnB1TU8oJmbbUCu4ODwRpBPZMnwzaHsLnrpdrB89/98NtTfujdrh3U5bVB+t33yxrXVh+FjgLYj9PVeDixpFDn6V/Xcnv4BbRMNOhXIQT7a7/5b99RiXBjCk6KRu+Jdu5DZ+3G4Nbr4oim3kZFPUHa555qbzTlwAfkrQxKv3C3OdVJR7eGc9ADsbHyEJbdPNAh/T+xblXTXLS3hPYDvgM+WEGy3CytBDG3JVcXm25ZP96EDWjweJ7MyfylubhuKj/iR1Y1wiHeIsYq9CqRrFQUWL8gFJBfmgjs96xRXXXnvyLtKUKpKw3wFg5cR/6FnLeYZ8k=
60+
distributions: "sdist bdist_wheel"

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Please read [UPGRADE-v1.0.md](https://github.com/graphql-python/graphene/blob/master/UPGRADE-v1.0.md)
2-
to learn how to upgrade to Graphene `1.0`.
1+
Please read [UPGRADE-v2.0.md](https://github.com/graphql-python/graphene/blob/master/UPGRADE-v2.0.md)
2+
to learn how to upgrade to Graphene `2.0`.
33

44
---
55

@@ -13,7 +13,7 @@ A [SQLAlchemy](http://www.sqlalchemy.org/) integration for [Graphene](http://gra
1313
For instaling graphene, just run this command in your shell
1414

1515
```bash
16-
pip install "graphene-sqlalchemy>=1.0"
16+
pip install "graphene-sqlalchemy>=2.0"
1717
```
1818

1919
## Examples
@@ -47,8 +47,8 @@ class User(SQLAlchemyObjectType):
4747
class Query(graphene.ObjectType):
4848
users = graphene.List(User)
4949

50-
def resolve_users(self, args, context, info):
51-
query = User.get_query(context) # SQLAlchemy query
50+
def resolve_users(self, info):
51+
query = User.get_query(info.context) # SQLAlchemy query
5252
return query.all()
5353

5454
schema = graphene.Schema(query=Query)

README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Please read
2-
`UPGRADE-v1.0.md <https://github.com/graphql-python/graphene/blob/master/UPGRADE-v1.0.md>`__
3-
to learn how to upgrade to Graphene ``1.0``.
2+
`UPGRADE-v2.0.md <https://github.com/graphql-python/graphene/blob/master/UPGRADE-v2.0.md>`__
3+
to learn how to upgrade to Graphene ``2.0``.
44

55
--------------
66

@@ -17,7 +17,7 @@ For instaling graphene, just run this command in your shell
1717

1818
.. code:: bash
1919
20-
pip install "graphene-sqlalchemy>=1.0"
20+
pip install "graphene-sqlalchemy>=2.0"
2121
2222
Examples
2323
--------
@@ -53,8 +53,8 @@ following:
5353
class Query(graphene.ObjectType):
5454
users = graphene.List(User)
5555
56-
def resolve_users(self, args, context, info):
57-
query = User.get_query(context) # SQLAlchemy query
56+
def resolve_users(self, info):
57+
query = User.get_query(info.context) # SQLAlchemy query
5858
return query.all()
5959
6060
schema = graphene.Schema(query=Query)

graphene_sqlalchemy/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
get_session
1010
)
1111

12-
__all__ = ['SQLAlchemyObjectType',
13-
'SQLAlchemyConnectionField',
14-
'get_query',
15-
'get_session']
12+
__version__ = '2.0.dev2017072601'
13+
14+
__all__ = [
15+
'__version__',
16+
'SQLAlchemyObjectType',
17+
'SQLAlchemyConnectionField',
18+
'get_query',
19+
'get_session'
20+
]

graphene_sqlalchemy/fields.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from sqlalchemy.orm.query import Query
44

5-
from graphene import final_resolver
65
from graphene.relay import ConnectionField
76
from graphene.relay.connection import PageInfo
87
from graphql_relay.connection.arrayconnection import connection_from_list_slice
@@ -17,8 +16,8 @@ def model(self):
1716
return self.type._meta.node._meta.model
1817

1918
@classmethod
20-
def get_query(cls, model, context, info, args):
21-
return get_query(model, context)
19+
def get_query(cls, model, info, **args):
20+
return get_query(model, info.context)
2221

2322
@property
2423
def type(self):
@@ -31,10 +30,10 @@ def type(self):
3130
return _type._meta.connection
3231

3332
@classmethod
34-
def connection_resolver(cls, resolver, connection, model, root, args, context, info):
35-
iterable = resolver(root, args, context, info)
33+
def connection_resolver(cls, resolver, connection, model, root, info, **args):
34+
iterable = resolver(root, info, **args)
3635
if iterable is None:
37-
iterable = cls.get_query(model, context, info, args)
36+
iterable = cls.get_query(model, info, **args)
3837
if isinstance(iterable, Query):
3938
_len = iterable.count()
4039
else:
@@ -54,7 +53,7 @@ def connection_resolver(cls, resolver, connection, model, root, args, context, i
5453
return connection
5554

5655
def get_resolver(self, parent_resolver):
57-
return final_resolver(partial(self.connection_resolver, parent_resolver, self.type, self.model))
56+
return partial(self.connection_resolver, parent_resolver, self.type, self.model)
5857

5958

6059
__connectionFactory = SQLAlchemyConnectionField

graphene_sqlalchemy/tests/test_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class Arguments:
277277
ok = graphene.Boolean()
278278
article = graphene.Field(ArticleNode)
279279

280-
def mutate(self, headline, reporter_id):
280+
def mutate(self, info, headline, reporter_id):
281281
new_article = Article(
282282
headline=headline,
283283
reporter_id=reporter_id,

graphene_sqlalchemy/tests/test_utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from graphene import ObjectType, Schema, String, annotate, Context
1+
from graphene import ObjectType, Schema, String
22

33
from ..utils import get_session
44

@@ -9,9 +9,8 @@ def test_get_session():
99
class Query(ObjectType):
1010
x = String()
1111

12-
@annotate(context=Context)
13-
def resolve_x(self, context):
14-
return get_session(context)
12+
def resolve_x(self, info):
13+
return get_session(info.context)
1514

1615
query = '''
1716
query ReporterQuery {

graphene_sqlalchemy/types.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def __init_subclass_with_meta__(cls, model=None, registry=None, skip_registry=Fa
134134
registry.register(cls)
135135

136136
@classmethod
137-
def is_type_of(cls, root, context, info):
137+
def is_type_of(cls, root, info):
138138
if isinstance(root, cls):
139139
return True
140140
if not is_mapped_instance(root):
@@ -144,19 +144,18 @@ def is_type_of(cls, root, context, info):
144144
return isinstance(root, cls._meta.model)
145145

146146
@classmethod
147-
def get_query(cls, context):
147+
def get_query(cls, info):
148148
model = cls._meta.model
149-
return get_query(model, context)
149+
return get_query(model, info.context)
150150

151151
@classmethod
152-
def get_node(cls, id, context, info):
152+
def get_node(cls, info, id):
153153
try:
154-
return cls.get_query(context).get(id)
154+
return cls.get_query(info).get(id)
155155
except NoResultFound:
156156
return None
157157

158-
# @annotate(info=ResolveInfo)
159-
def resolve_id(self):
158+
def resolve_id(self, info):
160159
# graphene_type = info.parent_type.graphene_type
161160
keys = self.__mapper__.primary_key_from_instance(self)
162161
return tuple(keys) if len(keys) > 1 else keys[0]

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ norecursedirs =
2424
filterwarnings =
2525
error
2626
ignore::DeprecationWarning
27+
28+
[bdist_wheel]
29+
universal=1

setup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
from setuptools import find_packages, setup
2+
import sys
3+
import ast
4+
import re
5+
6+
_version_re = re.compile(r'__version__\s+=\s+(.*)')
7+
8+
with open('graphene_sqlalchemy/__init__.py', 'rb') as f:
9+
version = str(ast.literal_eval(_version_re.search(
10+
f.read().decode('utf-8')).group(1)))
11+
212

313
setup(
414
name='graphene-sqlalchemy',
5-
version='2.0.dev2017072601',
15+
version=version,
616

717
description='Graphene SQLAlchemy integration',
818
long_description=open('README.rst').read(),

0 commit comments

Comments
 (0)