insolite / graphene-peewee-async

Graphene peewee-async integration
37 stars 9 forks source link

peewee field with choices #5

Closed art1415926535 closed 6 years ago

art1415926535 commented 6 years ago

Peewee field with a choices argument is not passed to GraphQL.

For example we can modify model from tests:

GENRES = (
    (0, 'Science fiction'),
    (1, 'Guide'),
    (2, 'Horror'),
)

class Book(BaseModel):
    name = CharField()
    year = IntegerField()
    author = ForeignKeyField(Author)
    genre = IntegerField(choices=GENRES)

and modify test:

        book = self.loop.run_until_complete(
            self.manager.create(Book, name='bar', year=2000, author=author, genre=1)  # genre was added
        )

        result = self.loop.run_until_complete(self.query('''
            query {
                book (id: ''' + str(book.id) + ''') {
                    id
                    name
                    year
                    genre  # this
                    author {
                        id
                        name
                        rating
                    }
                }
            }
        '''))

unittest: AssertionError: [GraphQLError('Cannot query field "genre" on type "Book".',)] is not None

I tried to figure point of this error and found what function from graphene return None.

So. What's wrong with my code?

insolite commented 6 years ago

Thanks for reporting. That's definetely a bug in peewee=>graphl field conversion. I will fix it soon.

insolite commented 6 years ago

Well, it was intended to work through Enum but had a little bug in field creation. Having that fixed I realized that using of Enum adds some restrictions and non-obvious value conversions as a result. If you look at the graphene-django implementation there are uppercasing of strings and prefixing of integers. And there are some discussions on this theme: graphql-python/graphene-django#67 graphql-python/graphene-django#133 graphql-python/graphene-django#280 I'm not sure it should be this way so looking back at the issues feedback above I'd rather ignore choices at the moment and just fix the missing field.

insolite commented 6 years ago

Released in v2.1.3