Coder Social home page Coder Social logo

Comments (10)

patrick91 avatar patrick91 commented on June 20, 2024 1

@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:

pip install strawberry[django]

or even have a metapackage that does that for you:

pip install strawberry-django

:)

from strawberry.

patrick91 avatar patrick91 commented on June 20, 2024

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? :)

from strawberry.

jaydenwindle avatar jaydenwindle commented on June 20, 2024

I'd love to work on this! I'll throw up some PRs in the next couple of days :)

from strawberry.

jaydenwindle avatar jaydenwindle commented on June 20, 2024

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.

from strawberry.

jaydenwindle avatar jaydenwindle commented on June 20, 2024

Oh interesting - I didn't know there were discussions around that in Graphene. In that case I'll add it directly to this repo :)

from strawberry.

patrick91 avatar patrick91 commented on June 20, 2024

@jaydenwindle :) thanks!

Hopefully it won't be a bad idea!

from strawberry.

conatus avatar conatus commented on June 20, 2024

Would love to see this!

from strawberry.

Rocamonde avatar Rocamonde commented on June 20, 2024

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.

from strawberry.

patrick91 avatar patrick91 commented on June 20, 2024

@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:

@strawberry.type
class Query:
    @strawberry.field
    def user(self) -> User:
         return models.User.objects.last()

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 :)

from strawberry.

la4de avatar la4de commented on June 20, 2024

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

from strawberry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.