mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-22 22:52:58 +03:00
Fixed global registry related errors.
This commit is contained in:
parent
ca0dcfbd22
commit
ebcc1f046d
|
@ -21,6 +21,7 @@ except ImportError:
|
|||
def convert_sqlalchemy_relationship(relationship, registry, connections, type_name):
|
||||
direction = relationship.direction
|
||||
model = relationship.mapper.entity
|
||||
print(registry)
|
||||
|
||||
def dynamic_type():
|
||||
_type = registry.get_type_for_model(model)
|
||||
|
@ -34,6 +35,7 @@ def convert_sqlalchemy_relationship(relationship, registry, connections, type_na
|
|||
try:
|
||||
connection_type = connections[relationship.key]
|
||||
except KeyError:
|
||||
print(_type)
|
||||
raise KeyError("No Connection provided for relationship {} on type {}. Specify it in its Meta "
|
||||
"class on the 'connections' dict.".format(relationship.key, type_name))
|
||||
return SQLAlchemyConnectionField(connection_type)
|
||||
|
|
|
@ -7,7 +7,7 @@ from graphene.relay import Node, Connection
|
|||
from ..types import SQLAlchemyObjectType
|
||||
from ..fields import SQLAlchemyConnectionField
|
||||
|
||||
from .models import Article, Base, Editor, Reporter
|
||||
from .models import Article, Base, Editor, Reporter, Pet
|
||||
|
||||
db = create_engine('sqlite:///test_sqlalchemy.sqlite3')
|
||||
|
||||
|
@ -46,10 +46,34 @@ def setup_fixtures(session):
|
|||
def test_should_query_well(session):
|
||||
setup_fixtures(session)
|
||||
|
||||
class ArticleType(SQLAlchemyObjectType):
|
||||
|
||||
class Meta:
|
||||
model = Article
|
||||
|
||||
ArticleTypeConnection = Connection.for_type(ArticleType)
|
||||
|
||||
ReporterNodeConnection = graphene.Dynamic(lambda: Connection.for_type(ReporterType))
|
||||
|
||||
class A(SQLAlchemyObjectType):
|
||||
class Meta:
|
||||
model = Pet
|
||||
connections = {
|
||||
'reporters': ReporterNodeConnection,
|
||||
'articles': ArticleTypeConnection,
|
||||
}
|
||||
interfaces = (Node, )
|
||||
|
||||
AConnection = Connection.for_type(A)
|
||||
|
||||
class ReporterType(SQLAlchemyObjectType):
|
||||
|
||||
class Meta:
|
||||
model = Reporter
|
||||
connections = {
|
||||
'pets': AConnection,
|
||||
'articles': AConnection,
|
||||
}
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
reporter = graphene.Field(ReporterType)
|
||||
|
@ -106,12 +130,25 @@ def test_should_node(session):
|
|||
|
||||
ArticleNodeConnection = Connection.for_type(ArticleNode)
|
||||
|
||||
ReporterNodeConnection = graphene.Dynamic(lambda: Connection.for_type(ReporterNode))
|
||||
|
||||
class A(SQLAlchemyObjectType):
|
||||
class Meta:
|
||||
model = Pet
|
||||
connections = {
|
||||
'reporters': ReporterNodeConnection
|
||||
}
|
||||
interfaces = (Node, )
|
||||
|
||||
AConnection = Connection.for_type(A)
|
||||
|
||||
class ReporterNode(SQLAlchemyObjectType):
|
||||
|
||||
class Meta:
|
||||
model = Reporter
|
||||
connections = {
|
||||
'articles': ArticleNodeConnection
|
||||
'articles': ArticleNodeConnection,
|
||||
'pets': AConnection,
|
||||
}
|
||||
interfaces = (Node, )
|
||||
|
||||
|
@ -264,12 +301,25 @@ def test_should_mutate_well(session):
|
|||
|
||||
ArticleNodeConnection = Connection.for_type(ArticleNode)
|
||||
|
||||
ReporterNodeConnection = graphene.Dynamic(lambda: Connection.for_type(ReporterNode))
|
||||
|
||||
class A(SQLAlchemyObjectType):
|
||||
class Meta:
|
||||
model = Pet
|
||||
connections = {
|
||||
'reporters': ReporterNodeConnection
|
||||
}
|
||||
interfaces = (Node, )
|
||||
|
||||
AConnection = Connection.for_type(A)
|
||||
|
||||
class ReporterNode(SQLAlchemyObjectType):
|
||||
|
||||
class Meta:
|
||||
model = Reporter
|
||||
connections = {
|
||||
'articles': ArticleNodeConnection
|
||||
'articles': ArticleNodeConnection,
|
||||
'pets': AConnection,
|
||||
}
|
||||
interfaces = (Node, )
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ def construct_fields(options, type_name):
|
|||
inspected_model = sqlalchemyinspect(options.model)
|
||||
|
||||
fields = OrderedDict()
|
||||
print('options in construct_fields', options)
|
||||
|
||||
for name, column in inspected_model.columns.items():
|
||||
is_not_in_only = only_fields and name not in only_fields
|
||||
|
|
|
@ -7,7 +7,7 @@ import six
|
|||
|
||||
from graphql_relay import connection_from_list
|
||||
|
||||
from ..types import Boolean, Int, List, String, AbstractType
|
||||
from ..types import Boolean, Int, List, String, AbstractType, Dynamic
|
||||
from ..types.field import Field
|
||||
from ..types.objecttype import ObjectType, ObjectTypeMeta
|
||||
from ..types.options import Options
|
||||
|
@ -123,7 +123,7 @@ def is_connection(gql_type):
|
|||
class IterableConnectionField(Field):
|
||||
|
||||
def __init__(self, gql_type, *args, **kwargs):
|
||||
assert is_connection(gql_type), (
|
||||
assert is_connection(gql_type) or isinstance(gql_type, Dynamic), (
|
||||
'The provided type "{}" for this ConnectionField has to be a Connection as defined by the Relay'
|
||||
' spec.'.format(gql_type)
|
||||
)
|
||||
|
@ -137,6 +137,14 @@ class IterableConnectionField(Field):
|
|||
**kwargs
|
||||
)
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
gql_type = super(IterableConnectionField, self).type
|
||||
if isinstance(gql_type, Dynamic):
|
||||
return gql_type.get_type()
|
||||
else:
|
||||
return gql_type
|
||||
|
||||
@staticmethod
|
||||
def connection_resolver(resolver, connection, root, args, context, info):
|
||||
resolved = Promise.resolve(resolver(root, args, context, info))
|
||||
|
|
Loading…
Reference in New Issue
Block a user