-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
Add Django Support #84
Comments
Yes totally! I'd love to see this happen (I'd love to use strawberry for some Django side project I have). I'm currently focused on finishing ASGI support (mainly adding tests and a better structure of the code), would you like to work on this? :) |
I'd love to work on this! I'll throw up some PRs in the next couple of days :) |
I've been giving this some thought, and I think that Django support would make more sense as it's own package (similar to how Graphene is set up). That way we don't have to worry about managing extra dependencies or releasing changes to strawberry that affect only the Django package. I'll spin up a repo with the Django extensions and we can add it to the strawberry org when it's ready to release. |
@jaydenwindle I'm a bit opposed to that, to be honest, there were some talks of merging some of the libraries back to the graphene repo. For example, if we do changes to strawberry "core" we need to update all the other packages probably. For dependencies we could do something like:
or even have a metapackage that does that for you:
:) |
Oh interesting - I didn't know there were discussions around that in Graphene. In that case I'll add it directly to this repo :) |
@jaydenwindle :) thanks! Hopefully it won't be a bad idea! |
Would love to see this! |
Hi @patrick91! Does Django support at this stage also imply the automatic conversion of a QuerySet into the dataclass-like structure that Strawberry uses? So a resolver can return a model instance or a QuerySet, and this is converted to the appropriate type and handled accordingly by GraphQL. |
@Rocamonde so, we don't do any implicit conversion, but duck typing works. If you return anything that looks like the GraphQL type then things work :) So for example this works:
we don't check what type is being returned in the resolvers. So this works, and works for lists too. I think the only place where this doesn't work is Union types, because we need to understand what type we are returning (but we can find a work around for that). We do this a lot in PyCon Italia's website: https://github.com/pythonitalia/pycon/blob/master/backend/api/conferences/types.py#L127-L155 Hope this helps :) |
I have been missing django model integration so I started to prototype this feature. Please try and leave feedback. https://github.com/la4de/strawberry-graphql-django There is sample projects which can be used for testing as well. https://github.com/la4de/strawberry-graphql-django/tree/main/examples/django |
I'd love to see strawberry support Django as a first class citizen via a contrib package. To start, it could be as simple as adding a Django view that exposes a GraphQL endpoint and the GraphQL Playground. From there, a lot of other neat features could be added, such as:
Is this something that strawberry would be interested in supporting?
The text was updated successfully, but these errors were encountered: