doableware / djongo

Django and MongoDB database connector
https://www.djongomapper.com
GNU Affero General Public License v3.0
1.88k stars 355 forks source link

graphene support #181

Open wahello opened 6 years ago

wahello commented 6 years ago

How to integrate graphene-django?

Is there any example?

felipembbraga commented 5 years ago

up

AdrianCarreno commented 4 years ago

@nesdis this issue has been open for more than a year and no answer. Is there any chance of getting support for Graphene?

MarshHawk commented 4 years ago

It turns out integrating graphene is pretty simple. I would even go so far as to say djongo makes it easier than using graphene-mongo. The one difference is that models using EmbeddedModelField and ArrayModelField require custom types. For example, if you have defined a model that is all standard django fields, you can just inherit from DjangoObjectType in the type definition:

#model
class Player(models.Model):
    uuid = models.UUIDField(primary_key=False, default=uuid.uuid4, editable=False, unique=True)
    name = models.CharField(max_length=200)

    class Meta:
        abstract = True

    def __str__(self):
        return self.name

#graphql type
class PlayerType(DjangoObjectType):
    class Meta:
        model = Player

If you have a list of players, then use a custom type:

#model
class Game(models.Model):
    players = models.ArrayModelField(
        model_container=Player,
    )

#graphene  custom type
class GameType(graphene.ObjectType):
    players = graphene.List(PlayerType)
SamKomesarook commented 3 years ago

Any update on this?

haris1998-web commented 2 years ago

No updates?