From b8ecc3929d55e69de9abb1d8c4cf75ffd45ac656 Mon Sep 17 00:00:00 2001 From: Dan Palmer Date: Sun, 9 Sep 2018 18:19:58 +0100 Subject: [PATCH 1/2] Add basic type documentation for Relay fields This adds documentation in the API for `PageInfo`s and `Edges`. This is useful to include in Graphene because `PageInfo` is always the same, and Edges always have the same format, so documentation for both can be created automatically. --- graphene/relay/connection.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/graphene/relay/connection.py b/graphene/relay/connection.py index 2782865c..a0f5a14c 100644 --- a/graphene/relay/connection.py +++ b/graphene/relay/connection.py @@ -12,6 +12,12 @@ from .node import is_node class PageInfo(ObjectType): + class Meta: + description = ( + "The Relay compliant `PageInfo` type, containing data necessary to" + " paginate this connection." + ) + has_next_page = Boolean( required=True, name="hasNextPage", @@ -64,13 +70,18 @@ class Connection(ObjectType): node = Field(_node, description="The item at the end of the edge") cursor = String(required=True, description="A cursor for use in pagination") + class EdgeMeta: + description = "A Relay edge containing a `{}` and its cursor.".format( + base_name + ) + edge_name = "{}Edge".format(base_name) if edge_class: edge_bases = (edge_class, EdgeBase, ObjectType) else: edge_bases = (EdgeBase, ObjectType) - edge = type(edge_name, edge_bases, {}) + edge = type(edge_name, edge_bases, {"Meta": EdgeMeta}) cls.Edge = edge options["name"] = name From 2a3d92682a76080b4e80d9adea6f9fafbc1962cd Mon Sep 17 00:00:00 2001 From: Dan Palmer Date: Sun, 9 Sep 2018 18:44:01 +0100 Subject: [PATCH 2/2] Add descriptions to the fields as well --- graphene/relay/connection.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/graphene/relay/connection.py b/graphene/relay/connection.py index a0f5a14c..927dfcc4 100644 --- a/graphene/relay/connection.py +++ b/graphene/relay/connection.py @@ -88,8 +88,22 @@ class Connection(ObjectType): _meta.node = node _meta.fields = OrderedDict( [ - ("page_info", Field(PageInfo, name="pageInfo", required=True)), - ("edges", Field(NonNull(List(edge)))), + ( + "page_info", + Field( + PageInfo, + name="pageInfo", + required=True, + description="Pagination data for this connection.", + ), + ), + ( + "edges", + Field( + NonNull(List(edge)), + description="Contains the nodes in this connection.", + ), + ), ] ) return super(Connection, cls).__init_subclass_with_meta__(