strawberry-graphql 0.273.3__py3-none-any.whl → 0.274.0__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.
@@ -26,7 +26,10 @@ from strawberry.http import (
26
26
  )
27
27
  from strawberry.http.ides import GraphQL_IDE
28
28
  from strawberry.schema.base import BaseSchema
29
- from strawberry.schema.exceptions import InvalidOperationTypeError
29
+ from strawberry.schema.exceptions import (
30
+ CannotGetOperationTypeError,
31
+ InvalidOperationTypeError,
32
+ )
30
33
  from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL
31
34
  from strawberry.subscriptions.protocols.graphql_transport_ws.handlers import (
32
35
  BaseGraphQLTransportWSHandler,
@@ -330,6 +333,8 @@ class AsyncBaseHTTPView(
330
333
  result = await self.execute_operation(
331
334
  request=request, context=context, root_value=root_value
332
335
  )
336
+ except CannotGetOperationTypeError as e:
337
+ raise HTTPException(400, e.as_http_error_reason()) from e
333
338
  except InvalidOperationTypeError as e:
334
339
  raise HTTPException(
335
340
  400, e.as_http_error_reason(request_adapter.method)
@@ -20,7 +20,10 @@ from strawberry.http import (
20
20
  )
21
21
  from strawberry.http.ides import GraphQL_IDE
22
22
  from strawberry.schema import BaseSchema
23
- from strawberry.schema.exceptions import InvalidOperationTypeError
23
+ from strawberry.schema.exceptions import (
24
+ CannotGetOperationTypeError,
25
+ InvalidOperationTypeError,
26
+ )
24
27
  from strawberry.types import ExecutionResult
25
28
  from strawberry.types.graphql import OperationType
26
29
  from strawberry.types.unset import UNSET
@@ -193,6 +196,8 @@ class SyncBaseHTTPView(
193
196
  context=context,
194
197
  root_value=root_value,
195
198
  )
199
+ except CannotGetOperationTypeError as e:
200
+ raise HTTPException(400, e.as_http_error_reason()) from e
196
201
  except InvalidOperationTypeError as e:
197
202
  raise HTTPException(
198
203
  400, e.as_http_error_reason(request_adapter.method)
@@ -1,9 +1,21 @@
1
+ from typing import Optional
2
+
1
3
  from strawberry.types.graphql import OperationType
2
4
 
3
5
 
4
6
  class CannotGetOperationTypeError(Exception):
5
7
  """Internal error raised when we cannot get the operation type from a GraphQL document."""
6
8
 
9
+ def __init__(self, operation_name: Optional[str]) -> None:
10
+ self.operation_name = operation_name
11
+
12
+ def as_http_error_reason(self) -> str:
13
+ return (
14
+ "Can't get GraphQL operation type"
15
+ if self.operation_name is None
16
+ else f'Unknown operation named "{self.operation_name}".'
17
+ )
18
+
7
19
 
8
20
  class InvalidOperationTypeError(Exception):
9
21
  def __init__(self, operation_type: OperationType) -> None:
@@ -498,7 +498,7 @@ class Schema(BaseSchema):
498
498
  try:
499
499
  operation_type = context.operation_type
500
500
  except RuntimeError as error:
501
- raise CannotGetOperationTypeError from error
501
+ raise CannotGetOperationTypeError(context.operation_name) from error
502
502
 
503
503
  if operation_type not in context.allowed_operations:
504
504
  raise InvalidOperationTypeError(operation_type)
@@ -609,7 +609,11 @@ class Schema(BaseSchema):
609
609
  # only return a sanitised version to the client.
610
610
  self._process_errors(result.errors, execution_context)
611
611
 
612
- except (MissingQueryError, InvalidOperationTypeError):
612
+ except (
613
+ MissingQueryError,
614
+ CannotGetOperationTypeError,
615
+ InvalidOperationTypeError,
616
+ ):
613
617
  raise
614
618
  except Exception as exc: # noqa: BLE001
615
619
  return await self._handle_execution_result(
@@ -677,8 +681,15 @@ class Schema(BaseSchema):
677
681
  extensions=extensions_runner.get_extensions_results_sync(),
678
682
  )
679
683
 
680
- if execution_context.operation_type not in allowed_operation_types:
681
- raise InvalidOperationTypeError(execution_context.operation_type) # noqa: TRY301
684
+ try:
685
+ operation_type = execution_context.operation_type
686
+ except RuntimeError as error:
687
+ raise CannotGetOperationTypeError(
688
+ execution_context.operation_name
689
+ ) from error
690
+
691
+ if operation_type not in execution_context.allowed_operations:
692
+ raise InvalidOperationTypeError(operation_type) # noqa: TRY301
682
693
 
683
694
  with extensions_runner.validation():
684
695
  _run_validation(execution_context)
@@ -725,7 +736,11 @@ class Schema(BaseSchema):
725
736
  # extension). That way we can log the original errors but
726
737
  # only return a sanitised version to the client.
727
738
  self._process_errors(result.errors, execution_context)
728
- except (MissingQueryError, InvalidOperationTypeError):
739
+ except (
740
+ MissingQueryError,
741
+ CannotGetOperationTypeError,
742
+ InvalidOperationTypeError,
743
+ ):
729
744
  raise
730
745
  except Exception as exc: # noqa: BLE001
731
746
  errors = [_coerce_error(exc)]
@@ -20,6 +20,7 @@ from strawberry.http.exceptions import (
20
20
  WebSocketDisconnected,
21
21
  )
22
22
  from strawberry.http.typevars import Context, RootValue
23
+ from strawberry.schema.exceptions import CannotGetOperationTypeError
23
24
  from strawberry.subscriptions.protocols.graphql_transport_ws.types import (
24
25
  CompleteMessage,
25
26
  ConnectionInitMessage,
@@ -221,13 +222,13 @@ class BaseGraphQLTransportWSHandler(Generic[Context, RootValue]):
221
222
  try:
222
223
  operation_type = get_operation_type(graphql_document, operation_name)
223
224
  except RuntimeError:
225
+ # Unlike in the other protocol implementations, we access the operation type
226
+ # before executing the operation. Therefore, we don't get a nice
227
+ # CannotGetOperationTypeError, but rather the underlying RuntimeError.
228
+ e = CannotGetOperationTypeError(operation_name)
224
229
  await self.websocket.close(
225
230
  code=4400,
226
- reason=(
227
- f'Unknown operation named "{operation_name}".'
228
- if operation_name
229
- else "Can't get GraphQL operation type"
230
- ),
231
+ reason=e.as_http_error_reason(),
231
232
  )
232
233
  return
233
234
 
@@ -194,18 +194,12 @@ class BaseGraphQLWSHandler(Generic[Context, RootValue]):
194
194
 
195
195
  await self.send_message(CompleteMessage(type="complete", id=operation_id))
196
196
 
197
- except CannotGetOperationTypeError:
197
+ except CannotGetOperationTypeError as e:
198
198
  await self.send_message(
199
199
  ErrorMessage(
200
200
  type="error",
201
201
  id=operation_id,
202
- payload={
203
- "message": (
204
- f'Unknown operation named "{operation_name}".'
205
- if operation_name
206
- else "Can't get GraphQL operation type"
207
- )
208
- },
202
+ payload={"message": e.as_http_error_reason()},
209
203
  )
210
204
  )
211
205
  except asyncio.CancelledError:
@@ -57,7 +57,7 @@ class ExecutionContext:
57
57
 
58
58
  @property
59
59
  def operation_name(self) -> Optional[str]:
60
- if self._provided_operation_name:
60
+ if self._provided_operation_name is not None:
61
61
  return self._provided_operation_name
62
62
 
63
63
  definition = self._get_first_operation()
@@ -25,7 +25,7 @@ def get_operation_type(
25
25
  ) -> OperationType:
26
26
  definition: Optional[OperationDefinitionNode] = None
27
27
 
28
- if operation_name:
28
+ if operation_name is not None:
29
29
  for d in graphql_document.definitions:
30
30
  if not isinstance(d, OperationDefinitionNode):
31
31
  continue
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: strawberry-graphql
3
- Version: 0.273.3
3
+ Version: 0.274.0
4
4
  Summary: A library for creating GraphQL APIs
5
5
  License: MIT
6
6
  Keywords: graphql,api,rest,starlette,async
@@ -134,12 +134,12 @@ strawberry/file_uploads/utils.py,sha256=-c6TbqUI-Dkb96hWCrZabh6TL2OabBuQNkCarOqg
134
134
  strawberry/flask/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
135
135
  strawberry/flask/views.py,sha256=MCvAsNgTZLU8RvTYKWfnLU2w7Wv1ZZpxW9W3TyTZuPY,6355
136
136
  strawberry/http/__init__.py,sha256=ytAirKk7K7D5knY21tpCGeZ-sCPgwMsijL5AxmOy-94,1163
137
- strawberry/http/async_base_view.py,sha256=UXzY0CU12uYZ-6LvqkIeryEn16OdRu8y94p-LgJTFNY,19963
137
+ strawberry/http/async_base_view.py,sha256=fEJGBPqEOnEiYc0bBT4vroqyidoHNBnfF-1iScmOQi0,20124
138
138
  strawberry/http/base.py,sha256=MiX0-RqOkhRvlfpmuvgTHp4tygbUmG8fnLc0uCrOllU,2550
139
139
  strawberry/http/exceptions.py,sha256=9E2dreS1crRoJVUEPuHyx23NcDELDHNzkAOa-rGv-8I,348
140
140
  strawberry/http/ides.py,sha256=WjU0nsMDgr3Bd1ebWkUEkO2d1hk0dI16mLqXyCHqklA,613
141
141
  strawberry/http/parse_content_type.py,sha256=CYHO8F9b9DP1gJ1xxPjc9L2GkBwsyC1O_GCEp1QOuG0,381
142
- strawberry/http/sync_base_view.py,sha256=3T7rkAyqQfJpJTw0NENQyluT9QR4Rw-a_5BPT_2MGX4,7263
142
+ strawberry/http/sync_base_view.py,sha256=_lYjw3uAQoYJ8QEWBWr7g6a88aM5NX8YFTFeZ5qzH88,7424
143
143
  strawberry/http/temporal_response.py,sha256=HTt65g-YxqlPGxjqvH5bzGoU1b3CctVR-9cmCRo5dUo,196
144
144
  strawberry/http/types.py,sha256=H0wGOdCO-5tNKZM_6cAtNRwZAjoEXnAC5N0Q7b70AtU,398
145
145
  strawberry/http/typevars.py,sha256=Uu6NkKe3h7o29ZWwldq6sJy4ioSSeXODTCDRvY2hUpE,489
@@ -168,9 +168,9 @@ strawberry/schema/__init__.py,sha256=u1QCyDVQExUVDA20kyosKPz3TS5HMCN2NrXclhiFAL4
168
168
  strawberry/schema/base.py,sha256=wqvEOQ_aVkfebk9SlG9zg1YXl3MlwxGZhxFRoIkAxu0,4053
169
169
  strawberry/schema/compat.py,sha256=xNpOEDfi-MODpplMGaKuKeQIVcr-tcAaKaU3TlBc1Zs,1873
170
170
  strawberry/schema/config.py,sha256=6d2MPrAgq97-7aze555dRcB3yw-aeUexYMP3KVN22c0,1024
171
- strawberry/schema/exceptions.py,sha256=xXq-2wXfeGualEJObXja6yVIKzFTh_iDXCIWttpIOSE,769
171
+ strawberry/schema/exceptions.py,sha256=8gsMxxFDynMvRkUDuVL9Wwxk_zsmo6QoJ2l4NPxd64M,1137
172
172
  strawberry/schema/name_converter.py,sha256=xFOXEgqldFkxXRkIQvsJN1dPkWbEUaIrTYNOMYSEVwQ,6945
173
- strawberry/schema/schema.py,sha256=pTs_dfhqsftecPblY_jCPU7my8RKB1QnleicCJL35WE,37287
173
+ strawberry/schema/schema.py,sha256=dnmSxoNdlrT02mca32Crtl0F55eweIqE-VOC77kuGjE,37723
174
174
  strawberry/schema/schema_converter.py,sha256=vxFghA8c4vPLx0XM07gjIbWqMWUnaognzmsuCWTSkTk,39112
175
175
  strawberry/schema/types/__init__.py,sha256=oHO3COWhL3L1KLYCJNY1XFf5xt2GGtHiMC-UaYbFfnA,68
176
176
  strawberry/schema/types/base_scalars.py,sha256=JRUq0WjEkR9dFewstZnqnZKp0uOEipo4UXNF5dzRf4M,1971
@@ -187,10 +187,10 @@ strawberry/static/pathfinder.html,sha256=0DPx9AmJ2C_sJstFXnWOz9k5tVQHeHaK7qdVY4l
187
187
  strawberry/subscriptions/__init__.py,sha256=1VGmiCzFepqRFyCikagkUoHHdoTG3XYlFu9GafoQMws,170
188
188
  strawberry/subscriptions/protocols/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
189
189
  strawberry/subscriptions/protocols/graphql_transport_ws/__init__.py,sha256=wN6dkMu6WiaIZTE19PGoN9xXpIN_RdDE_q7F7ZgjCxk,138
190
- strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py,sha256=8F93epfxwktsAgTF7_TwC-9kBnjrzOpF-McEV36xEVw,15257
190
+ strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py,sha256=XJYPq_Nl6PWYu-u_uAmh-AO1k2wD3gAQjGMhRjkcwbo,15475
191
191
  strawberry/subscriptions/protocols/graphql_transport_ws/types.py,sha256=N9r2mXg5jmmjYoZV5rWf3lAzgylCOUrbKGmClXCoOso,2169
192
192
  strawberry/subscriptions/protocols/graphql_ws/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
193
- strawberry/subscriptions/protocols/graphql_ws/handlers.py,sha256=5mFyfP3brn0aS3SmeF7-z2vWTS2NhsLTD3JVE1zbr6k,8891
193
+ strawberry/subscriptions/protocols/graphql_ws/handlers.py,sha256=4o_ptDXL1gMLVQUfxJYO8Xfm_I3gt-Y1Z2CsOb7K1yw,8658
194
194
  strawberry/subscriptions/protocols/graphql_ws/types.py,sha256=Uumiz-1O5qQnx-ERBaQtaf7db5yx-V9LMypOn9oGKwM,2003
195
195
  strawberry/test/__init__.py,sha256=lKVbKJDBnrYSPYHIKrg54UpaZcSoL93Z01zOpA1IzZM,115
196
196
  strawberry/test/client.py,sha256=ILAttb6A3jplH5wJNMeyyT1u_Q8KnollfpYLP_BVZR4,6438
@@ -203,7 +203,7 @@ strawberry/types/auto.py,sha256=WZ2cQAI8nREUigBzpzFqIKGjJ_C2VqpAPNe8vPjTciM,3007
203
203
  strawberry/types/base.py,sha256=Bfa-5Wen8qR7m6tlSMRRGlGE-chRGMHjQMopfNdbbrk,15197
204
204
  strawberry/types/cast.py,sha256=fx86MkLW77GIximBAwUk5vZxSGwDqUA6XicXvz8EXwQ,916
205
205
  strawberry/types/enum.py,sha256=IcCz0FLswJtDC_bU8aG1cjreawcqHywAzzVRBZUSAqs,6229
206
- strawberry/types/execution.py,sha256=Ylc0lH0nyHyQW509mVqBh2sIN5qpf4cJtt8QhVmWGgI,3749
206
+ strawberry/types/execution.py,sha256=m27VlmvaRLQsMnWWymxMMPOlaf0lUge4ZXea_OsoH2k,3761
207
207
  strawberry/types/field.py,sha256=vxb7JvkHfRmDCYsjhDmVnO2lMbtSOteQm3jQUeSFu6g,21605
208
208
  strawberry/types/fields/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
209
209
  strawberry/types/fields/resolver.py,sha256=b6lxfw6AMOUFWm7vs7a9KzNkpR8b_S110DoIosrrWDQ,14679
@@ -229,11 +229,11 @@ strawberry/utils/graphql_lexer.py,sha256=JUVJrJ6Ax0t7m6-DTWFzf4cvXrC02VPmL1NS2zM
229
229
  strawberry/utils/importer.py,sha256=NtTgNaNSW4TnlLo_S34nxXq14RxUAec-QlEZ0LON28M,629
230
230
  strawberry/utils/inspect.py,sha256=-aFT65PkQ9KXo5w8Q2uveBJ8jEpi40sTqRipRQVdYR8,3406
231
231
  strawberry/utils/logging.py,sha256=U1cseHGquN09YFhFmRkiphfASKCyK0HUZREImPgVb0c,746
232
- strawberry/utils/operation.py,sha256=CCIREeh3-CzjvjyjhmYPRCVDZUX36jAxF6LbK8r5wEw,1222
232
+ strawberry/utils/operation.py,sha256=ZgVOw3K2jQuLjNOYUHauF7itJD0QDNoPw9PBi0IYf6k,1234
233
233
  strawberry/utils/str_converters.py,sha256=-eH1Cl16IO_wrBlsGM-km4IY0IKsjhjnSNGRGOwQjVM,897
234
234
  strawberry/utils/typing.py,sha256=SDvX-Du-9HAV3-XXjqi7Q5f5qPDDFd_gASIITiwBQT4,14073
235
- strawberry_graphql-0.273.3.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
236
- strawberry_graphql-0.273.3.dist-info/METADATA,sha256=I0ZsVsO1wjkPWnRZeORNDtTmagpWN1jDNu7oZT9_DuE,7444
237
- strawberry_graphql-0.273.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
238
- strawberry_graphql-0.273.3.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
239
- strawberry_graphql-0.273.3.dist-info/RECORD,,
235
+ strawberry_graphql-0.274.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
236
+ strawberry_graphql-0.274.0.dist-info/METADATA,sha256=Qi_EBzRuPvmFcfFTQWmxWId7EoPQVqlgJusjp9345kk,7444
237
+ strawberry_graphql-0.274.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
238
+ strawberry_graphql-0.274.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
239
+ strawberry_graphql-0.274.0.dist-info/RECORD,,