1

如何@property从 django 模型 graphql 结果中添加字段?:

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
    }
}
4

1 回答 1

2

some_property通过添加字段的示例:

class MyObject(DjangoObjectType):

    some_property = graphene.String()

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

询问:

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

输入:

{"variables": {"id": btoa("MyObject:123")}}
于 2019-09-26T21:41:27.947 回答