-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Can't get relationships to work. Unexpected type ForwardRef? #97
Comments
+1 Have the same exception |
1 similar comment
+1 Have the same exception |
I have the same issue. Downgrading to 0.3.1 fixed it, so I guess something in 0.4.0 broke it. |
Thanks for the report! I'll try to look into it this weekend. Has anyone gathered some more detail of what could have caused the issue? That would really help me dive straight into the fixing 🙂 |
I've investigated further. The issue is this change, specifically L289. The node type names are now passed as a strawberry-sqlalchemy/src/strawberry_sqlalchemy_mapper/mapper.py Lines 278 to 293 in 4fa950f
Since The problem in this case: the mapped type is not a I did this as a test, but this yielded another error: the type I'm still looking for a quick and easy fix, but long-term I see this being fixed through one of these options:
For me personally, a central registry is the preferred approach since it gives full control over the way we access types. This is a mid-term effort and requires heavy refactoring, so having something that works short-term to fix the occurring issues would be preferable. /cc @mattalbr |
Actually in strawberry django all relations and the types to those relations should be created explicitly: https://strawberry-graphql.github.io/strawberry-graphql-django/guide/fields/#relationships , and thus, those can be done using Lazy types If we try to map a relationship using auto or passing to the fields list, we map them to a type that only has a pk attribute (https://github.com/strawberry-graphql/strawberry-graphql-django/blob/main/strawberry_django/fields/types.py#L250) or to the Node interface when using relay. But we usually suggest users to map relations explicitly Having said that, based on how this code works, a type registry is probably the way to go for this. TBH, I'm not totally familiar with this code but doesn't something like that already exists when creating the Edge/Connection? i.e. Also, it seems that I'm the one who caused this issue so I can try to fix it as well :) |
Use a lazy type to properly resolve and specialize the `Edge`/`Connection` types that are created from the model. The reason we are using a subclass of `LazyType` is because the original one expects a path to be passed to be used to import it later. We don't have one here, but we do have a mapper containing all the created types that can be retrieved later. Fix strawberry-graphql#97
This should fix the issue: #106 |
Use a lazy type to properly resolve and specialize the `Edge`/`Connection` types that are created from the model. The reason we are using a subclass of `LazyType` is because the original one expects a path to be passed to be used to import it later. We don't have one here, but we do have a mapper containing all the created types that can be retrieved later. Fix strawberry-graphql#97
Use a lazy type to properly resolve and specialize the `Edge`/`Connection` types that are created from the model. The reason we are using a subclass of `LazyType` is because the original one expects a path to be passed to be used to import it later. We don't have one here, but we do have a mapper containing all the created types that can be retrieved later. Fix #97
I've merged #106 to ensure a quick fix for the affected projects. We can keep this issue open until we are certain about the definitive future solution for this. The use of lazy types is exactly what I've envisioned, but I'm looking forward to hear matt's opinion on the matter. @dentatar @Gianfranco753 @0x587 @johansigfrids please try out the new release |
I'm trying to catch up here, but you two (Erik and Thiago) understand strawberry's typing system WAY better than me. I really need to hop in and play around with Thiago's new relay code to get a better understanding. That said, I took a look at #106 and it looks good to me. I appreciate you both! |
Well, I finally had time to test it out and it is not quite working yet. The ForwardRef error is gone and it starts up fine, but attempting to query the connection results in the following error:
|
Got the same issues in my project. A one-to-many relationship not working with
Downgrading from 0.4.2 to 0.3.1 fixes relationships for the time being. |
Ok, here is what is going on here: When trying to instantiate the connection and the edges in here we are missing some attributes:
This is because in my relay PR I changed the Because we didn't have any tests for the resolvers themselves I didn't even see that they were missing those. We have 2 options to solve that:
@mattalbr @erikwrede thoughts about this? |
Same problem, same resolution |
Friendly bump, the issue prevents lib update. |
Will take a look at this during the weekend. @erikwrede @mattalbr could you take a look at my comment in #97 (comment)? I'm leaning towards the first option in there, but I would appreciate your thoughts 😊 |
We changed auto generated edges/connections to inherit from `relay.Edge`/`relay.Connection`, which requires some extra fields to be instantiated. Fix strawberry-graphql#97
We changed auto generated edges/connections to inherit from `relay.Edge`/`relay.Connection`, which requires some extra fields to be instantiated. Fix strawberry-graphql#97
We changed auto generated edges/connections to inherit from `relay.Edge`/`relay.Connection`, which requires some extra fields to be instantiated. Fix strawberry-graphql#97
We changed auto generated edges/connections to inherit from `relay.Edge`/`relay.Connection`, which requires some extra fields to be instantiated. Fix strawberry-graphql#97
We changed auto generated edges/connections to inherit from `relay.Edge`/`relay.Connection`, which requires some extra fields to be instantiated. Fix #97
python 3.11
sqlalchemy 2.0.23
strawberry-graphql 0.216.0
strawberry-sqlalchemy-mapper 0.4.0
Trying to use this mapper and was playing around with some basics but can't get relationships to work. It doesn't seem like i do something wrong, this is literally the example from readme:
models.py
app.py
main.py
Got this error:
Upvote & Fund
The text was updated successfully, but these errors were encountered: