Harrison
Harrison

Reputation: 2690

How should I resolve a field with leading underscore in graphene?

I have a field _id

class Article(graphene.ObjectType):
    _id = graphene.Int()
    article_id = graphene.Int()

    def resolve__id(self, info):
        return self.article_id

This one does not work, it will interpret _id as Id.

Upvotes: 3

Views: 1655

Answers (1)

jkimbo
jkimbo

Reputation: 298

Graphene tries to convert all fields to camel case to maintain convention with JavaScript: http://docs.graphene-python.org/en/latest/types/schema/#auto-camelcase-field-names

This can be turned off at the schema level or you can explicitly override the name of a field with whatever you want:

class Article(graphene.ObjectType):
    id = graphene.Int(name='_id')

Upvotes: 11

Related Questions