graphql-python / graphene-sqlalchemy

Graphene SQLAlchemy integration
http://docs.graphene-python.org/projects/sqlalchemy/en/latest/
MIT License
975 stars 225 forks source link

Question: How to not using relay pagination? #314

Closed shaozi closed 2 years ago

shaozi commented 2 years ago

Relay pagination is nice, but sometimes, I just want to have a simple list backref. I know it will not exceed more than 10 elements in the list. so pagination just added a layer of extra work and no benefits.

Is there a way to disable relay pagination?

richin13 commented 2 years ago

yep, you should be able to use a list, like so:


class Ship(graphene.ObjectType):
    names = graphene.List(graphene.String())

then query it like:

{
    ship(...) { names }
}

resulting in:

{
  "data": {"ship": {"names": [item1, item2, ...]}}
}
shaozi commented 2 years ago

That is great! I did not think of that it could be so easy!

shaozi commented 2 years ago

What about many to many relationship?

erikwrede commented 2 years ago

@shaozi it should work exactly the same for a many to many relationship, just use a list on the other side of the relationship as well.

class Destination(graphene.ObjectType)
    name = graphene.String()
    ships = graphene.List(Ship)

class Ship(graphene.ObjectType):
    destinations = graphene.List(Destination)

For using plain Strings, you would have to create an extra ObjectType.

erikwrede commented 2 years ago

I'm closing this issue, since the problem seems to be solved. Feel free to reply again or open another Issue if you experience further problems.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.