strawberry-graphql 0.227.2__py3-none-any.whl → 0.227.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
strawberry/relay/types.py CHANGED
@@ -38,7 +38,7 @@ from strawberry.utils.aio import aenumerate, aislice, resolve_awaitable
38
38
  from strawberry.utils.inspect import in_async_context
39
39
  from strawberry.utils.typing import eval_type, is_classvar
40
40
 
41
- from .utils import from_base64, to_base64
41
+ from .utils import from_base64, should_resolve_list_connection_edges, to_base64
42
42
 
43
43
  if TYPE_CHECKING:
44
44
  from strawberry.scalars import ID
@@ -933,6 +933,17 @@ class ListConnection(Connection[NodeType]):
933
933
  overfetch,
934
934
  )
935
935
 
936
+ if not should_resolve_list_connection_edges(info):
937
+ return cls(
938
+ edges=[],
939
+ page_info=PageInfo(
940
+ start_cursor=None,
941
+ end_cursor=None,
942
+ has_previous_page=False,
943
+ has_next_page=False,
944
+ ),
945
+ )
946
+
936
947
  edges = [
937
948
  edge_class.resolve_edge(
938
949
  cls.resolve_node(v, info=info, **kwargs),
strawberry/relay/utils.py CHANGED
@@ -2,6 +2,8 @@ import base64
2
2
  from typing import Any, Tuple, Union
3
3
  from typing_extensions import assert_never
4
4
 
5
+ from strawberry.types.info import Info
6
+ from strawberry.types.nodes import InlineFragment, Selection
5
7
  from strawberry.types.types import StrawberryObjectDefinition
6
8
 
7
9
 
@@ -61,3 +63,42 @@ def to_base64(type_: Union[str, type, StrawberryObjectDefinition], node_id: Any)
61
63
  raise ValueError(f"{type_} is not a valid GraphQL type or name") from e
62
64
 
63
65
  return base64.b64encode(f"{type_name}:{node_id}".encode()).decode()
66
+
67
+
68
+ def should_resolve_list_connection_edges(info: Info) -> bool:
69
+ """Check if the user requested to resolve the `edges` field of a connection.
70
+
71
+ Args:
72
+ info:
73
+ The strawberry execution info resolve the type name from
74
+
75
+ Returns:
76
+ True if the user requested to resolve the `edges` field of a connection, False otherwise.
77
+
78
+ """
79
+ resolve_for_field_names = {"edges", "pageInfo"}
80
+
81
+ def _check_selection(selection: Selection) -> bool:
82
+ """Recursively inspect the selection to check if the user requested to resolve the `edges` field.
83
+ Args:
84
+ selection (Selection): The selection to check.
85
+
86
+ Returns:
87
+ bool: True if the user requested to resolve the `edges` field of a connection, False otherwise.
88
+ """
89
+ if (
90
+ not isinstance(selection, InlineFragment)
91
+ and selection.name in resolve_for_field_names
92
+ ):
93
+ return True
94
+ if selection.selections:
95
+ return any(
96
+ _check_selection(selection) for selection in selection.selections
97
+ )
98
+ return False
99
+
100
+ for selection_field in info.selected_fields:
101
+ for selection in selection_field.selections:
102
+ if _check_selection(selection):
103
+ return True
104
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: strawberry-graphql
3
- Version: 0.227.2
3
+ Version: 0.227.4
4
4
  Summary: A library for creating GraphQL APIs
5
5
  Home-page: https://strawberry.rocks/
6
6
  License: MIT
@@ -173,8 +173,8 @@ strawberry/quart/views.py,sha256=SDUaDX7bPKsv8PziMPb0C3nH6vre-Q3bhzSQp4uPjbY,340
173
173
  strawberry/relay/__init__.py,sha256=Vi4btvA_g6Cj9Tk_F9GCSegapIf2WqkOWV8y3P0cTCs,553
174
174
  strawberry/relay/exceptions.py,sha256=b7sU2MhHVWJOfq27lvqdFcqBZ5P_JWk41JWRjtP-AOI,3916
175
175
  strawberry/relay/fields.py,sha256=0A96V4mQzFJwP9g68tM3zKmbPxnfU2Ix6kbMI-x11LQ,15550
176
- strawberry/relay/types.py,sha256=tazLGFC92vVbsoMTFTqOX4QCrgrxSgsDotgkhjFpl7w,30331
177
- strawberry/relay/utils.py,sha256=1ixGxk0KW-aQ5iebckPzZKYiz_Lh_ngo-5MNYTn0zAY,1748
176
+ strawberry/relay/types.py,sha256=pCFD0UXXofmdTS2wBURjg8KwIfdioMt2j4qNYfk6GqQ,30710
177
+ strawberry/relay/utils.py,sha256=STuJ2j-sTPa70O9juJX21nbhK6yhnHdwiAOWBYKOVdo,3160
178
178
  strawberry/resolvers.py,sha256=g7_g3jmXszziGydY1UG6IItf9s6B1lGLUCnwW1kb8U0,224
179
179
  strawberry/sanic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
180
180
  strawberry/sanic/context.py,sha256=qfoj8QMaAiWbCQFAdm2KPPJGNc7ilXeKAl5z0XJ2nzo,805
@@ -241,8 +241,8 @@ strawberry/utils/logging.py,sha256=flS7hV0JiIOEdXcrIjda4WyIWix86cpHHFNJL8gl1y4,7
241
241
  strawberry/utils/operation.py,sha256=Um-tBCPl3_bVFN2Ph7o1mnrxfxBes4HFCj6T0x4kZxE,1135
242
242
  strawberry/utils/str_converters.py,sha256=avIgPVLg98vZH9mA2lhzVdyyjqzLsK2NdBw9mJQ02Xk,813
243
243
  strawberry/utils/typing.py,sha256=SQVOw1nuFZk2Pe3iz0o8ebzpoyvBVoGSQZVZj6-8k7I,13483
244
- strawberry_graphql-0.227.2.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
245
- strawberry_graphql-0.227.2.dist-info/METADATA,sha256=UneH50cMF5dA0C72rGhpjAovf2j4X3Ww4RlZF-ecgdM,7821
246
- strawberry_graphql-0.227.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
247
- strawberry_graphql-0.227.2.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
248
- strawberry_graphql-0.227.2.dist-info/RECORD,,
244
+ strawberry_graphql-0.227.4.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
245
+ strawberry_graphql-0.227.4.dist-info/METADATA,sha256=uYT_-NobMzrHaDqu5o_I48JxqU6MsMDUitjLvwyv1p8,7821
246
+ strawberry_graphql-0.227.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
247
+ strawberry_graphql-0.227.4.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
248
+ strawberry_graphql-0.227.4.dist-info/RECORD,,