2

How to add a @property field from a django model graphql results?:

class MyModel(...):
    ...
    @property
    def some_property(self):
        return 'property here'
class MyObject(DjangoObjectType):
    class Meta:
        model = MyModel
        interfaces = (relay.Node,)
        filter_fields = []
query GetMyModel(id: ID!){
    getMyModel(id: $id){
        someProperty
    }
}
jmunsch
  • 22,771
  • 11
  • 93
  • 114

1 Answers1

3

An example by adding the some_property field:

class MyObject(DjangoObjectType):

    some_property = graphene.String()

    class Meta:
        model = MyModel
        interfaces = (relay.Node,)
        filter_fields = []

query:

query GetMyModel(id: ID!){
    getMyModel(id: $id){
        someProperty
    }
}

input:

{"variables": {"id": btoa("MyObject:123")}}
jmunsch
  • 22,771
  • 11
  • 93
  • 114