Skip to content

Commit 33a65e7

Browse files
author
Awais Hussain
committed
Clean up docstrings in type_adaptor file
Stick to the format of having a one line summary followed by more detailed information.
1 parent b13d8ba commit 33a65e7

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

gql/type_adaptor.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TypeAdaptor(object):
2020
decoded value. All of this logic happens in `_substitute()`.
2121
2222
Public Interface:
23-
parse(): pass in a GQL response to replace all instances of custom
23+
apply(): pass in a GQL response to replace all instances of custom
2424
scalar strings with their deserialized representation."""
2525

2626
def __init__(self, schema: GraphQLSchema, custom_scalars: Dict[str, Any] = {}) -> None:
@@ -32,11 +32,12 @@ def __init__(self, schema: GraphQLSchema, custom_scalars: Dict[str, Any] = {}) -
3232
self.custom_scalars = custom_scalars
3333

3434
def _follow_type_chain(self, node: Any) -> Any:
35-
"""In the schema GraphQL types are often listed with the format
36-
`obj.type.of_type...` where there are 0 or more 'of_type' fields before
37-
you get to the type you are interested in.
35+
""" Get the type of the schema node in question.
3836
39-
This is a convenience method to help us get to these nested types."""
37+
In the GraphQL schema, GraphQLFields have a "type" property. However, often
38+
that dict has an "of_type" property itself. In order to get to the actual
39+
type, we need to indefinitely follow the chain of "of_type" fields to get
40+
to the last one, which is the one we care about."""
4041
if isinstance(node, GraphQLObjectType):
4142
return node
4243

@@ -55,16 +56,17 @@ def _get_scalar_type_name(self, field: GraphQLField) -> Optional[str]:
5556
return None
5657

5758
def _lookup_scalar_type(self, keys: List[str]) -> Optional[str]:
58-
"""
59-
`keys` is a breadcrumb trail telling us where to look in the GraphQL schema.
60-
By default the root level is `schema.query`, if that fails, then we check
61-
`schema.mutation`.
59+
"""Search through the GQL schema and return the type identified by 'keys'.
6260
63-
If keys (e.g. ['wallet', 'balance']) points to a scalar type, then
64-
this function returns the name of that type. (e.g. 'Money')
61+
If keys (e.g. ['film', 'release_date']) points to a scalar type, then
62+
this function returns the name of that type. (e.g. 'DateTime')
6563
6664
If it is not a scalar type (e..g a GraphQLObject or list), then this
67-
function returns None"""
65+
function returns None.
66+
67+
`keys` is a breadcrumb trail telling us where to look in the GraphQL schema.
68+
By default the root level is `schema.query`, if that fails, then we check
69+
`schema.mutation`."""
6870

6971
def iterate(node: Any, lookup: List[str]):
7072
lookup = lookup.copy()
@@ -83,24 +85,27 @@ def iterate(node: Any, lookup: List[str]):
8385
return None
8486

8587
def _substitute(self, keys: List[str], value: Any) -> Any:
86-
"""Looks in the GraphQL schema to find the type identified by 'keys'
88+
"""Get the decoded value of the type identified by `keys`.
89+
90+
If the type is not a custom scalar, then return the original value.
8791
88-
If that type is not a custom scalar, we return the original value.
89-
If it is a custom scalar, we return the deserialized value, as
90-
processed by `<CustomScalarType>.parse_value()`"""
92+
If it is a custom scalar, return the deserialized value, as
93+
output by `<CustomScalarType>.parse_value()`"""
9194
scalar_type = self._lookup_scalar_type(keys)
9295
if scalar_type and scalar_type in self.custom_scalars:
9396
return self.custom_scalars[scalar_type].parse_value(value)
9497
return value
9598

9699
def _traverse(self, response: Dict[str, Any], substitute: Callable) -> Dict[str, Any]:
97-
"""Recursively traverses the GQL response and calls the `substitute`
100+
"""Recursively traverse the GQL response
101+
102+
Recursively traverses the GQL response and calls the `substitute`
98103
function on all leaf nodes. The function is called with 2 arguments:
99104
keys: List[str] is a breadcrumb trail telling us where we are in the
100105
response, and therefore, where to look in the GQL Schema.
101-
value: Any is the value at that node in the tree
106+
value: Any is the value at that node in the response
102107
103-
Builds a new tree with the substituted values so `response` is not
108+
Builds a new tree with the substituted values so old `response` is not
104109
modified."""
105110
def iterate(node: Any, keys: List[str] = []):
106111
if isinstance(node, dict):

0 commit comments

Comments
 (0)