djongo icon indicating copy to clipboard operation
djongo copied to clipboard

graphene support

Open wahello opened this issue 7 years ago • 5 comments

How to integrate graphene-django?

Is there any example?

wahello avatar Sep 07 '18 02:09 wahello

up

felipembbraga avatar May 04 '19 21:05 felipembbraga

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

AdrianCarreno avatar Dec 02 '19 14:12 AdrianCarreno

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)

MarshHawk avatar Mar 16 '20 00:03 MarshHawk

Any update on this?

SamKomesarook avatar Apr 28 '21 06:04 SamKomesarook

No updates?

haris1998-web avatar Sep 19 '22 17:09 haris1998-web