Skip to content

Create SQLAlchemyConnectionField through a factory method #46

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

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d7b9fc2
handle datetime as datetime.datetime instead of string
palmkevin Oct 27, 2016
5920243
convert biginteger to float
palmkevin Oct 28, 2016
92f73ec
Removed commeted BigInteger-int-mapping line
palmkevin Nov 18, 2016
5fdaae6
Create Conections through connection-factory
palmkevin Nov 18, 2016
1359a4d
Merge remote-tracking branch 'refs/remotes/graphql-python/master'
palmkevin Nov 18, 2016
bcc4b1f
Merge branch 'BigInteger'
palmkevin Nov 18, 2016
5b7a6bb
Merge branch 'BigInteger'
palmkevin Nov 18, 2016
26112de
Add depndency to iso8601 to correctly handle datetime
palmkevin Nov 18, 2016
b8a4c8e
Add dependency to iso8601: required for datetime handling
palmkevin Nov 18, 2016
32e70e8
Merge branch 'BigInteger'
palmkevin Nov 18, 2016
a407a4d
Merge branch 'DateTime'
palmkevin Nov 18, 2016
fe3cd93
Merge branch 'DateTime'
palmkevin Nov 18, 2016
dc5218c
Merge branch 'DateTime'
palmkevin Nov 21, 2016
e5bdaec
Create SQLAlchemyConnectionField through a factory method. Overriding…
palmkevin Nov 21, 2016
d16da23
Merge branch 'ConnectionFactory'
palmkevin Nov 21, 2016
cbf0a22
Add free lins to match code lint checks
palmkevin Nov 21, 2016
4834275
Merge branch 'ConnectionFactory'
palmkevin Nov 21, 2016
129fc47
Merge branch 'DateTime'
palmkevin Nov 21, 2016
ec928df
Added test for connection factory
May 2, 2017
e0c8331
Merge branch 'ConnectionFactory'
May 2, 2017
c943739
Added test for connection factory
May 2, 2017
0273538
Added test for connection factory
May 2, 2017
c0556ef
Added test for connection factory
May 2, 2017
e588326
Merge remote-tracking branch 'origin/master'
May 2, 2017
073dc55
Added test for connection factory Description
May 2, 2017
197a96b
Merge branch 'ConnectionFactory'
May 2, 2017
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
6 changes: 3 additions & 3 deletions graphene_sqlalchemy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from graphene.relay import is_node
from graphene.types.json import JSONString

from .fields import SQLAlchemyConnectionField
from .fields import createConnectionField

try:
from sqlalchemy_utils import ChoiceType, JSONType, ScalarListType
Expand Down Expand Up @@ -36,7 +36,7 @@ def dynamic_type():
elif (direction == interfaces.ONETOMANY or
direction == interfaces.MANYTOMANY):
if is_node(_type):
return SQLAlchemyConnectionField(_type)
return createConnectionField(_type)
return Field(List(_type))

return Dynamic(dynamic_type)
Expand Down Expand Up @@ -102,7 +102,6 @@ def convert_column_to_datetime(type, column, registry=None):


@convert_sqlalchemy_type.register(types.SmallInteger)
@convert_sqlalchemy_type.register(types.BigInteger)
@convert_sqlalchemy_type.register(types.Integer)
def convert_column_to_int_or_id(type, column, registry=None):
if column.primary_key:
Expand All @@ -118,6 +117,7 @@ def convert_column_to_boolean(type, column, registry=None):

@convert_sqlalchemy_type.register(types.Float)
@convert_sqlalchemy_type.register(types.Numeric)
@convert_sqlalchemy_type.register(types.BigInteger)
def convert_column_to_float(type, column, registry=None):
return Float(description=column.doc, required=not(column.nullable))

Expand Down
17 changes: 17 additions & 0 deletions graphene_sqlalchemy/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,20 @@ def connection_resolver(cls, resolver, connection, model, root, args, context, i

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


__connectionFactory = SQLAlchemyConnectionField


def createConnectionField(_type):
return __connectionFactory(_type)


def registerConnectionFieldFactory(factoryMethod):
global __connectionFactory
__connectionFactory = factoryMethod


def unregisterConnectionFieldFactory():
global __connectionFactory
__connectionFactory = SQLAlchemyConnectionField
28 changes: 28 additions & 0 deletions graphene_sqlalchemy/tests/test_connectionfactory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from graphene_sqlalchemy.fields import SQLAlchemyConnectionField, registerConnectionFieldFactory, unregisterConnectionFieldFactory
import graphene

def test_register():
class LXConnectionField(SQLAlchemyConnectionField):
@classmethod
def _applyQueryArgs(cls, model, q, args):
return q

@classmethod
def connection_resolver(cls, resolver, connection, model, root, args, context, info):

def LXResolver(root, args, context, info):
iterable = resolver(root, args, context, info)
if iterable is None:
iterable = cls.get_query(model, context, info, args)

# We accept always a query here. All LX-queries can be filtered and sorted
iterable = cls._applyQueryArgs(model, iterable, args)
return iterable

return SQLAlchemyConnectionField.connection_resolver(LXResolver, connection, model, root, args, context, info)

def createLXConnectionField(table):
return LXConnectionField(table, filter=table.filter(), order_by=graphene.List(of_type=table.order_by))

registerConnectionFieldFactory(createLXConnectionField)
unregisterConnectionFieldFactory()
2 changes: 1 addition & 1 deletion graphene_sqlalchemy/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_should_small_integer_convert_int():


def test_should_big_integer_convert_int():
assert_column_conversion(types.BigInteger(), graphene.Int)
assert_column_conversion(types.BigInteger(), graphene.Float)


def test_should_integer_convert_int():
Expand Down