Skip to content

Add batching flag to SQLAlchemyObjectType and ORMField #2

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 7 commits into from

Conversation

jnak
Copy link
Owner

@jnak jnak commented Jan 6, 2020

Preview


if not _type:
batching_ = batching if is_selectin_available else False
connection_field_factory_ = connection_field_factory

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this allocation ?

**field_kwargs
)
resolver = get_custom_resolver(obj_type, orm_field_name)
if resolver is None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't find this syntax very readable. maybe something like that ?

Suggested change
if resolver is None:
if resolver is None and batching_:

)
resolver = get_custom_resolver(obj_type, orm_field_name)
if resolver is None:
resolver = get_batch_resolver(relationship_prop) if batching_ else \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resolver = get_batch_resolver(relationship_prop) if batching_ else \
resolver = get_batch_resolver(relationship_prop)

resolver = get_custom_resolver(obj_type, orm_field_name)
if resolver is None:
resolver = get_batch_resolver(relationship_prop) if batching_ else \
get_attr_resolver(obj_type, relationship_prop.key)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
get_attr_resolver(obj_type, relationship_prop.key)
elif resolver is None:
resolver = get_attr_resolver(obj_type, relationship_prop.key)

Comment on lines +70 to +72
if connection_field_factory_ is None:
connection_field_factory_ = BatchSQLAlchemyConnectionField.from_relationship if batching_ else \
default_connection_field_factory

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And same thing here, I think :)

Comment on lines +158 to 177
resolver = get_custom_resolver(obj_type, orm_field_name) or get_attr_resolver(obj_type, attr_name)

if isinstance(attr, ColumnProperty):
field = convert_sqlalchemy_column(
attr,
registry,
custom_resolver or _get_attr_resolver(obj_type, orm_field_name, attr_name),
**orm_field.kwargs
)
field = convert_sqlalchemy_column(attr, registry, resolver, **orm_field.kwargs)
elif isinstance(attr, RelationshipProperty):
batching_ = orm_field.kwargs.pop('batching', batching)
field = convert_sqlalchemy_relationship(
attr,
registry,
connection_field_factory,
custom_resolver or _get_relationship_resolver(obj_type, attr, attr_name),
**orm_field.kwargs
)
attr, obj_type, connection_field_factory, batching_, attr_name,
orm_field_name, **orm_field.kwargs)
elif isinstance(attr, CompositeProperty):
if attr_name != orm_field_name or orm_field.kwargs:
# TODO Add a way to override composite property fields
raise ValueError(
"ORMField kwargs for composite fields must be empty. "
"Field: {}.{}".format(obj_type.__name__, orm_field_name))
field = convert_sqlalchemy_composite(
attr,
registry,
custom_resolver or _get_attr_resolver(obj_type, orm_field_name, attr_name),
)
field = convert_sqlalchemy_composite(attr, registry, resolver)
elif isinstance(attr, hybrid_property):
field = convert_sqlalchemy_hybrid_method(
attr,
custom_resolver or _get_attr_resolver(obj_type, orm_field_name, attr_name),
**orm_field.kwargs
)
field = convert_sqlalchemy_hybrid_method(attr, resolver, **orm_field.kwargs)
else:
raise Exception('Property type is not supported') # Should never happen

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice cleanup ;)

@jnak
Copy link
Owner Author

jnak commented Jan 24, 2020

@Nabellaleen Thanks for the review. Unfortunately, I have to close this one and send a new one in the graphql-python/graphene-sqlalchemy repo (vs my own) now that the benchmark PR is merged. I'll make sure to address your comments in the new PR.

@jnak jnak closed this Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants