Skip to content

Road to 2.0 #57

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 15 commits into from
Aug 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adapted code to the new resovlers api
  • Loading branch information
syrusakbary committed Aug 1, 2017
commit 41309d08fe8f56bb3a36f88d52e2756a3c420276
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]