You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When values are passed not in the query but using variables, then strawberry-django isn't able to resolve the ordering sequence. It probably happens only if you create a custom order method using @strawberry_django.order_field annotation.
The result is that the query fails with the following assert:
app_1 | File "/opt/venv/lib/python3.10/site-packages/strawberry_django/ordering.py", line 125, in process_order
app_1 | res = f.base_resolver(
app_1 | File "/opt/venv/lib/python3.10/site-packages/strawberry_django/fields/filter_order.py", line 130, in __call__
app_1 | assert sequence is not None
My humble solution
I am not saying that my solution is right, but maybe it will help someone to get on the right track. I extended the original method a little bit and used it in the custom order method:
def resolve_ordering_sequence(info: Info):
sequence: dict = {}
if info is not None and info._raw_info.field_nodes:
field_node = info._raw_info.field_nodes[0]
for arg in field_node.arguments:
if arg.name.value != ORDER_ARG or (
not isinstance(arg.value, ObjectValueNode)
and not isinstance(arg.value, VariableNode)
):
continue
def parse_and_fill(
field: ObjectValueNode | VariableNode,
seq: dict[str, OrderSequence],
):
if isinstance(field, VariableNode):
order_variable = info.variable_values.get(field.name.value)
for i, n in enumerate(order_variable):
seq[n] = OrderSequence(seq=i, children={})
return
for i, f in enumerate(field.fields):
f_sequence: dict[str, OrderSequence] = {}
if isinstance(f.value, ObjectValueNode):
parse_and_fill(f.value, f_sequence)
seq[f.name.value] = OrderSequence(
seq=i, children=f_sequence
)
parse_and_fill(arg.value, sequence)
return sequence
When values are passed not in the query but using variables, then strawberry-django isn't able to resolve the ordering sequence. It probably happens only if you create a custom order method using
@strawberry_django.order_field
annotation.Example
Query example:
variables example:
Causes
The result is that the query fails with the following assert:
My humble solution
I am not saying that my solution is right, but maybe it will help someone to get on the right track. I extended the original method a little bit and used it in the custom
order
method:then in order class:
System Information
strawberry-graphql==0.227.2
strawberry-graphql-django~=0.39.2
Additional Context
If it doesn't make sense, feel free to delete the issue.
Upvote & Fund
The text was updated successfully, but these errors were encountered: