Closed pomidoroshev closed 1 year ago
I tried a naive fix with a test, and it turned out that there's another problem: StrawberryUnion
can't match the types strawberry.types.types.Connection
and FruitConnection
and raises UnallowedReturnTypeForUnion
:
File "<...>/site-packages/strawberry/union.py", line 201, in _resolve_union_type
raise UnallowedReturnTypeForUnion(
strawberry.exceptions.UnallowedReturnTypeForUnion: The type "<class 'strawberry.types.types.Connection'>" of the field "fruitsOrError" is not in the list of the types of the union: "['FruitConnection', 'OperationMessage']"
Github action log: https://github.com/pomidoroshev/strawberry-django-plus/actions/runs/5179448035/jobs/9332339724#step:7:952
@pomidoroshev hrm, I overlooked that =P
You probably need to resolve the union the same way as in the other function above it. It is not great doing that twice, but I think it is not a major issue, specially because this PR should soon be merged and the way of resolving this will be greatly simplified.
Feel free to try to send a PR for that. Otherwise I will try to fix that tomorrow :)
@bellini666
You probably need to resolve the union the same way as in the other function above it.
Yep, I did that, just copy-pasted your solution https://github.com/pomidoroshev/strawberry-django-plus/commit/7c21431e9136e9812360a692074406e9d3db9daa#diff-bf0a824c6ab1aff4a9b72c271bc38ebeae4db3b82f27073eccfc2db59d34f534R1078-R1089
The problem happens afterwards, when the nodes are resolved, and Strawberry checks the actual returned types against the types inside the union. The union contains FruitConnection
, the returned value is strawberry.types.types.Connection
, and it causes UnallowedReturnTypeForUnion
I submitted a PR to illustrate the problem of UnallowedReturnTypeForUnion
#226
Hey @pomidoroshev ,
There's indeed something strange happening here..
Having said that, the relay PR got merged yesterday on strawberry and I'll try to refactor strawberrry-django-plus to use it this weekend. If everything goes accordingly to the plan, this issue will be solved as well.
@pomidoroshev I just released the new version which uses the official integration. Could you check if it solves your issue?
@bellini666 Unfortunately, no. I haven't fixed the test in the related PR yet, but I tried on my own project.
The following code works fine:
from strawberry import relay
from strawberry_django_plus import gql
from strawberry_django_plus.permissions import IsAuthenticated
from strawberry_django_plus.types import OperationMessage
@gql.django.type(Profile)
class ProfileType(relay.Node):
first_name: str
last_name: str
# ...
@gql.type
class ProfilesQuery:
all_profiles: relay.ListConnection[ProfileType] = gql.django.connection(
directives=[IsAuthenticated()]
)
But if I add | OperationMessage
, it raises TypeError: Query fields cannot be resolved.
:
@gql.type
class ProfilesQuery:
all_profiles: relay.ListConnection[ProfileType] | OperationMessage = gql.django.connection(
directives=[IsAuthenticated()]
)
Since the relay mode is a native Strawberry feature, I tested it there and submitted an issue as well https://github.com/strawberry-graphql/strawberry/issues/2893
@pomidoroshev was actually going to comment that here :)
Let's continue this discussion there
The problem of the original issue #223 was fixed, but there's another one: