-
Notifications
You must be signed in to change notification settings - Fork 822
Document how to implement Connection fields and pagination #887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What I found out: The following worked to define a List field class Thing(SQLAlchemyObjectType):
class Meta:
model = models.Thing # sqlalchemy model
things = graphene.List(ThingGraphQLType)
@staticmethod
def resolve_things(args, info):
# returning a query seems to be ok
return Thing.get_query(info=info) However the following does not: class ThingConnection(relay.Connection):
class Meta:
node = Thing
things = relay.ConnectionField(ThingConnection)
@staticmethod
def resolve_things(args, info):
return Thing.get_query(info=info)
But this works: @staticmethod
def resolve_things(args, info):
return Thing.get_query(info=info).all() This is all based on try and error. That could be nice to explain that upfront in the doc. |
After the previous declaration, I see on my schema that ThingConnection exposes However if I try to use the Looks like it's not implemented. So I add the @staticmethod
resolve_things(args,info,first=None):
# 'first' argument is not used anywhere, only added to the signature
return models.Things.query().all() There is three Things in my db. If I query I keep exploring this package but it's a slow process of try and error to discover features, find out what is possible and how to do it. The documentation is really lacking in this area. |
Agree that it's a huge trial and error effort to understand this lib. My understanding is that pagination is implemented on the edges, you appear to be trying to implement it on the root node. ie I think:
That is the benefit that you get from having the tedious amount of boilerplate in your queries. |
Ok I'll start completing the doc as I discover about the package: #892 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@antoine-gallix: There is another solution to this problem in which you do not have to add all arguments of the pagination in your staticmethod resolver. Instead of
just do
This way all your arguments will be passed to the Connection Type and you don't have to care about it anymore :) @louisdvs: I think your way of doing the pagination on the edges is not consistent with the relay specification and should not be applied. If people will query the API thinking it is relay conform, they will fail in doing so. |
From the documentation on relay Connection, there is an example on how to define a connection object type, but in the part that shows how to define a connection field, it's not clear what should the resolver return. The example only show an empty list returned. What type of object is a connection resolver supposed to return? Could you show a concrete example?
Also the sentence in that paragraph is not clear:
What does this sentence mean?
The text was updated successfully, but these errors were encountered: