-
Notifications
You must be signed in to change notification settings - Fork 184
SequelizeJSON support #137
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
Comments
This is not supported at the moment but maybe with #33 there is a chance to implement More info (I think this is the source): https://github.com/mickhansen/graphql-sequelize on this file. |
@KingDarBoja Okey, thank you for so fast response. I am going to move just RAW GraphQL queries. |
Maybe, I did understand you wrong, but I am using regular python dictionaries and it seems to work (you can use any Python code which results in a serializable dict): ds.mutation_root.update_suppliers(
where=filter_none_values({
'id': {'_eq': supplier_id},
'contact_person_id': user_id and {'_eq': user_id}
}),
_set=serialize(supplier)
).select(
ds.supplier_mutation_response.affected_rows,
ds.supplier_mutation_response.returning.select(
ds.supplier.id
)
)
from functools import singledispatch
def filter_none_values(data: dict):
return {k: v for k, v in data.items() if v is not None}
@singledispatch
def serialize(ob):
return ob
@serialize.register(dict)
def _serialize_dict(ob):
return {k: serialize(v) for k, v in ob.items()}
@serialize.register(list)
def _serialize_list(ob):
return [serialize(v) for v in ob]
@serialize.register(Enum)
def _serialize_enum(ob):
return ob.name
@serialize.register(date)
def _serialize_date(ob):
return ob.isoformat() Besides that, I am using SimpleNamespace (with a nested helper) to convert the dict response to a python object with regular fields for easier access: from functools import singledispatch
from types import SimpleNamespace
@singledispatch
def nested_namespace(ob):
return ob
@nested_namespace.register(dict)
def _nested_dict(ob):
return SimpleNamespace(**{k: nested_namespace(v) for k, v in ob.items()})
@nested_namespace.register(list)
def _nested_list(ob):
return [nested_namespace(v) for v in ob] You can use it like: response = await session.execute(query)
return nested_namespace(response) Hopefully in the future gql will support these kind of functionality natively (#104 this goes in that direction), but for now I can workaround with my helper functions. I hope, I was able to help you 👍 By the way, I am using:
|
@ SpeciesDecipit |
Hello!
Does GQL package (3.0.0a1) have the support of making queries with DSL for SequelizeJSON type? For example:
Where
where
argument is SequelizeJSONBecause in case of using in such way:
I got an error: Cannot convert value to AST: {'county': {'eq': 'Pulaski'}}.
GraphQL schema:
The text was updated successfully, but these errors were encountered: