Skip to content

Adapted code to new resolvers API #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ deploy:
tags: true
password:
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=
distributions: "sdist bdist_wheel"
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Please read [UPGRADE-v1.0.md](https://github.com/graphql-python/graphene/blob/master/UPGRADE-v1.0.md)
to learn how to upgrade to Graphene `1.0`.
Please read [UPGRADE-v2.0.md](https://github.com/graphql-python/graphene/blob/master/UPGRADE-v2.0.md)
to learn how to upgrade to Graphene `2.0`.

---

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

```bash
pip install "graphene-sqlalchemy>=1.0"
pip install "graphene-sqlalchemy>=2.0"
```

## Examples
Expand Down Expand Up @@ -47,8 +47,8 @@ class User(SQLAlchemyObjectType):
class Query(graphene.ObjectType):
users = graphene.List(User)

def resolve_users(self, args, context, info):
query = User.get_query(context) # SQLAlchemy query
def resolve_users(self, info):
query = User.get_query(info.context) # SQLAlchemy query
return query.all()

schema = graphene.Schema(query=Query)
Expand Down
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Please read
`UPGRADE-v1.0.md <https://github.com/graphql-python/graphene/blob/master/UPGRADE-v1.0.md>`__
to learn how to upgrade to Graphene ``1.0``.
`UPGRADE-v2.0.md <https://github.com/graphql-python/graphene/blob/master/UPGRADE-v2.0.md>`__
to learn how to upgrade to Graphene ``2.0``.

--------------

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

.. code:: bash

pip install "graphene-sqlalchemy>=1.0"
pip install "graphene-sqlalchemy>=2.0"

Examples
--------
Expand Down Expand Up @@ -53,8 +53,8 @@ following:
class Query(graphene.ObjectType):
users = graphene.List(User)

def resolve_users(self, args, context, info):
query = User.get_query(context) # SQLAlchemy query
def resolve_users(self, info):
query = User.get_query(info.context) # SQLAlchemy query
return query.all()

schema = graphene.Schema(query=Query)
Expand Down
13 changes: 9 additions & 4 deletions graphene_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
get_session
)

__all__ = ['SQLAlchemyObjectType',
'SQLAlchemyConnectionField',
'get_query',
'get_session']
__version__ = '2.0.dev2017072601'

__all__ = [
'__version__',
'SQLAlchemyObjectType',
'SQLAlchemyConnectionField',
'get_query',
'get_session'
]
13 changes: 6 additions & 7 deletions graphene_sqlalchemy/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from sqlalchemy.orm.query import Query

from graphene import final_resolver
from graphene.relay import ConnectionField
from graphene.relay.connection import PageInfo
from graphql_relay.connection.arrayconnection import connection_from_list_slice
Expand All @@ -17,8 +16,8 @@ def model(self):
return self.type._meta.node._meta.model

@classmethod
def get_query(cls, model, context, info, args):
return get_query(model, context)
def get_query(cls, model, info, **args):
return get_query(model, info.context)

@property
def type(self):
Expand All @@ -31,10 +30,10 @@ def type(self):
return _type._meta.connection

@classmethod
def connection_resolver(cls, resolver, connection, model, root, args, context, info):
iterable = resolver(root, args, context, info)
def connection_resolver(cls, resolver, connection, model, root, info, **args):
iterable = resolver(root, info, **args)
if iterable is None:
iterable = cls.get_query(model, context, info, args)
iterable = cls.get_query(model, info, **args)
if isinstance(iterable, Query):
_len = iterable.count()
else:
Expand All @@ -54,7 +53,7 @@ def connection_resolver(cls, resolver, connection, model, root, args, context, i
return connection

def get_resolver(self, parent_resolver):
return final_resolver(partial(self.connection_resolver, parent_resolver, self.type, self.model))
return partial(self.connection_resolver, parent_resolver, self.type, self.model)


__connectionFactory = SQLAlchemyConnectionField
Expand Down
2 changes: 1 addition & 1 deletion graphene_sqlalchemy/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class Arguments:
ok = graphene.Boolean()
article = graphene.Field(ArticleNode)

def mutate(self, headline, reporter_id):
def mutate(self, info, headline, reporter_id):
new_article = Article(
headline=headline,
reporter_id=reporter_id,
Expand Down
7 changes: 3 additions & 4 deletions graphene_sqlalchemy/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from graphene import ObjectType, Schema, String, annotate, Context
from graphene import ObjectType, Schema, String

from ..utils import get_session

Expand All @@ -9,9 +9,8 @@ def test_get_session():
class Query(ObjectType):
x = String()

@annotate(context=Context)
def resolve_x(self, context):
return get_session(context)
def resolve_x(self, info):
return get_session(info.context)

query = '''
query ReporterQuery {
Expand Down
13 changes: 6 additions & 7 deletions graphene_sqlalchemy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init_subclass_with_meta__(cls, model=None, registry=None, skip_registry=Fa
registry.register(cls)

@classmethod
def is_type_of(cls, root, context, info):
def is_type_of(cls, root, info):
if isinstance(root, cls):
return True
if not is_mapped_instance(root):
Expand All @@ -144,19 +144,18 @@ def is_type_of(cls, root, context, info):
return isinstance(root, cls._meta.model)

@classmethod
def get_query(cls, context):
def get_query(cls, info):
model = cls._meta.model
return get_query(model, context)
return get_query(model, info.context)

@classmethod
def get_node(cls, id, context, info):
def get_node(cls, info, id):
try:
return cls.get_query(context).get(id)
return cls.get_query(info).get(id)
except NoResultFound:
return None

# @annotate(info=ResolveInfo)
def resolve_id(self):
def resolve_id(self, info):
# graphene_type = info.parent_type.graphene_type
keys = self.__mapper__.primary_key_from_instance(self)
return tuple(keys) if len(keys) > 1 else keys[0]
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ norecursedirs =
filterwarnings =
error
ignore::DeprecationWarning

[bdist_wheel]
universal=1
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
from setuptools import find_packages, setup
import sys
import ast
import re

_version_re = re.compile(r'__version__\s+=\s+(.*)')

with open('graphene_django/__init__.py', 'rb') as f:
version = str(ast.literal_eval(_version_re.search(
f.read().decode('utf-8')).group(1)))


setup(
name='graphene-sqlalchemy',
version='2.0.dev2017072601',
version=version,

description='Graphene SQLAlchemy integration',
long_description=open('README.rst').read(),
Expand Down