strawberry-graphql 0.288.3__py3-none-any.whl → 0.289.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.
@@ -114,7 +114,38 @@
114
114
  #
115
115
  `;
116
116
 
117
- const fetchURL = window.location.href;
117
+ // Parse URL parameters for sharing queries
118
+ const parameters = {};
119
+
120
+ for (const entry of window.location.search.slice(1).split("&")) {
121
+ const eq = entry.indexOf("=");
122
+ if (eq >= 0) {
123
+ parameters[decodeURIComponent(entry.slice(0, eq))] =
124
+ decodeURIComponent(entry.slice(eq + 1));
125
+ }
126
+ }
127
+
128
+ function updateURL(data) {
129
+ Object.assign(parameters, data);
130
+
131
+ const newSearch =
132
+ "?" +
133
+ Object.keys(parameters)
134
+ .filter(function (key) {
135
+ return Boolean(parameters[key]);
136
+ })
137
+ .map(function (key) {
138
+ return (
139
+ encodeURIComponent(key) +
140
+ "=" +
141
+ encodeURIComponent(parameters[key])
142
+ );
143
+ })
144
+ .join("&");
145
+ history.replaceState(null, null, newSearch);
146
+ }
147
+
148
+ const fetchURL = window.location.href.split("?")[0];
118
149
 
119
150
  function httpUrlToWebSockeUrl(url) {
120
151
  const parsedURL = new URL(url);
@@ -124,33 +155,65 @@
124
155
  return parsedURL.toString();
125
156
  }
126
157
 
127
- const headers = {};
158
+ const defaultHeaders = {};
128
159
  const csrfToken = Cookies.get("csrftoken");
129
160
 
130
161
  if (csrfToken) {
131
- headers["x-csrftoken"] = csrfToken;
162
+ defaultHeaders["x-csrftoken"] = csrfToken;
132
163
  }
133
164
 
134
165
  const subscriptionUrl = httpUrlToWebSockeUrl(fetchURL);
135
166
 
136
167
  const fetcher = GraphiQL.createFetcher({
137
168
  url: fetchURL,
138
- headers: headers,
169
+ headers: defaultHeaders,
139
170
  subscriptionUrl,
140
171
  });
141
172
 
142
- const explorerPlugin = GraphiQLPluginExplorer.explorerPlugin();
143
-
144
- const root = ReactDOM.createRoot(document.getElementById("graphiql"));
145
-
146
- root.render(
147
- React.createElement(GraphiQL, {
173
+ function GraphiQLWithExplorer() {
174
+ const [query, setQuery] = React.useState(
175
+ parameters.q || EXAMPLE_QUERY,
176
+ );
177
+ const [variables, setVariables] = React.useState(
178
+ parameters.variables,
179
+ );
180
+ const [headers, setHeaders] = React.useState(parameters.headers);
181
+
182
+ function onEditQuery(newQuery) {
183
+ setQuery(newQuery);
184
+ updateURL({ q: newQuery });
185
+ }
186
+
187
+ function onEditVariables(newVariables) {
188
+ setVariables(newVariables);
189
+ updateURL({ variables: newVariables });
190
+ }
191
+
192
+ function onEditHeaders(newHeaders) {
193
+ setHeaders(newHeaders);
194
+ updateURL({ headers: newHeaders });
195
+ }
196
+
197
+ const explorerPlugin = GraphiQLPluginExplorer.explorerPlugin();
198
+
199
+ return React.createElement(GraphiQL, {
148
200
  fetcher: fetcher,
149
201
  defaultEditorToolsVisibility: true,
150
202
  plugins: [explorerPlugin],
203
+ query: query,
204
+ variables: variables,
205
+ headers: headers,
206
+ onEditQuery: onEditQuery,
207
+ onEditVariables: onEditVariables,
208
+ onEditHeaders: onEditHeaders,
151
209
  inputValueDeprecation: true,
152
- }),
153
- );
210
+ isHeadersEditorEnabled: true,
211
+ shouldPersistHeaders: true,
212
+ });
213
+ }
214
+
215
+ const root = ReactDOM.createRoot(document.getElementById("graphiql"));
216
+ root.render(React.createElement(GraphiQLWithExplorer));
154
217
  </script>
155
218
  </body>
156
219
  </html>
strawberry/types/enum.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import dataclasses
2
2
  from collections.abc import Callable, Iterable, Mapping
3
3
  from enum import EnumMeta
4
- from typing import TYPE_CHECKING, Any, TypeGuard, TypeVar, overload
4
+ from typing import TYPE_CHECKING, Any, Literal, TypeGuard, TypeVar, overload
5
5
 
6
6
  from strawberry.exceptions import ObjectIsNotAnEnumError
7
7
  from strawberry.types.base import (
@@ -103,6 +103,7 @@ def enum_value(
103
103
 
104
104
 
105
105
  EnumType = TypeVar("EnumType", bound=EnumMeta)
106
+ GraphqlEnumNameFrom = Literal["key", "value"]
106
107
 
107
108
 
108
109
  def _process_enum(
@@ -110,6 +111,7 @@ def _process_enum(
110
111
  name: str | None = None,
111
112
  description: str | None = None,
112
113
  directives: Iterable[object] = (),
114
+ graphql_name_from: GraphqlEnumNameFrom = "key",
113
115
  ) -> EnumType:
114
116
  if not isinstance(cls, EnumMeta):
115
117
  raise ObjectIsNotAnEnumError(cls)
@@ -119,6 +121,7 @@ def _process_enum(
119
121
 
120
122
  values = []
121
123
  for item in cls: # type: ignore
124
+ graphql_name = None
122
125
  item_value = item.value
123
126
  item_name = item.name
124
127
  deprecation_reason = None
@@ -135,13 +138,19 @@ def _process_enum(
135
138
  cls._value2member_map_[item_value.value] = item
136
139
  cls._member_map_[item_name]._value_ = item_value.value
137
140
 
138
- if item_value.graphql_name:
139
- item_name = item_value.graphql_name
140
-
141
+ graphql_name = item_value.graphql_name
141
142
  item_value = item_value.value
142
143
 
144
+ if not graphql_name:
145
+ if graphql_name_from == "key":
146
+ graphql_name = item_name
147
+ elif graphql_name_from == "value":
148
+ graphql_name = item_value
149
+ else:
150
+ raise ValueError(f"Invalid mode: {graphql_name_from}")
151
+
143
152
  value = EnumValue(
144
- item_name,
153
+ graphql_name,
145
154
  item_value,
146
155
  deprecation_reason=deprecation_reason,
147
156
  directives=item_directives,
@@ -174,6 +183,7 @@ def enum(
174
183
  name: str | None = None,
175
184
  description: str | None = None,
176
185
  directives: Iterable[object] = (),
186
+ graphql_name_from: GraphqlEnumNameFrom = "key",
177
187
  ) -> EnumType: ...
178
188
 
179
189
 
@@ -184,6 +194,7 @@ def enum(
184
194
  name: str | None = None,
185
195
  description: str | None = None,
186
196
  directives: Iterable[object] = (),
197
+ graphql_name_from: GraphqlEnumNameFrom = "key",
187
198
  ) -> Callable[[EnumType], EnumType]: ...
188
199
 
189
200
 
@@ -193,18 +204,20 @@ def enum(
193
204
  name: str | None = None,
194
205
  description: str | None = None,
195
206
  directives: Iterable[object] = (),
207
+ graphql_name_from: GraphqlEnumNameFrom = "key",
196
208
  ) -> EnumType | Callable[[EnumType], EnumType]:
197
209
  """Annotates an Enum class a GraphQL enum.
198
210
 
199
211
  GraphQL enums only have names, while Python enums have names and values,
200
- Strawberry will use the names of the Python enum as the names of the
201
- GraphQL enum values.
212
+ Strawberry will by default use the names of the Python enum as the names of the
213
+ GraphQL enum values. You can use the values instead by using mode="value".
202
214
 
203
215
  Args:
204
216
  cls: The Enum class to be annotated.
205
217
  name: The name of the GraphQL enum.
206
218
  description: The description of the GraphQL enum.
207
219
  directives: The directives to attach to the GraphQL enum.
220
+ graphql_name_from: Whether to use the names (key) or values of the Python enums in GraphQL.
208
221
 
209
222
  Returns:
210
223
  The decorated Enum class.
@@ -235,7 +248,13 @@ def enum(
235
248
  """
236
249
 
237
250
  def wrap(cls: EnumType) -> EnumType:
238
- return _process_enum(cls, name, description, directives=directives)
251
+ return _process_enum(
252
+ cls,
253
+ name,
254
+ description,
255
+ directives=directives,
256
+ graphql_name_from=graphql_name_from,
257
+ )
239
258
 
240
259
  if not cls:
241
260
  return wrap
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: strawberry-graphql
3
- Version: 0.288.3
3
+ Version: 0.289.0
4
4
  Summary: A library for creating GraphQL APIs
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -31,9 +31,9 @@ Provides-Extra: quart
31
31
  Provides-Extra: sanic
32
32
  Requires-Dist: Django (>=3.2) ; extra == "django"
33
33
  Requires-Dist: aiohttp (>=3.7.4.post0,<4) ; extra == "aiohttp"
34
- Requires-Dist: asgiref (>=3.2,<4.0) ; extra == "channels"
35
- Requires-Dist: asgiref (>=3.2,<4.0) ; extra == "django"
36
- Requires-Dist: chalice (>=1.22,<2.0) ; extra == "chalice"
34
+ Requires-Dist: asgiref (>=3.2) ; extra == "channels"
35
+ Requires-Dist: asgiref (>=3.2) ; extra == "django"
36
+ Requires-Dist: chalice (>=1.22) ; extra == "chalice"
37
37
  Requires-Dist: channels (>=3.0.5) ; extra == "channels"
38
38
  Requires-Dist: cross-web (>=0.4.0)
39
39
  Requires-Dist: fastapi (>=0.65.2) ; extra == "fastapi"
@@ -47,8 +47,8 @@ Requires-Dist: opentelemetry-api (<2) ; extra == "opentelemetry"
47
47
  Requires-Dist: opentelemetry-sdk (<2) ; extra == "opentelemetry"
48
48
  Requires-Dist: packaging (>=23)
49
49
  Requires-Dist: pydantic (>1.6.1) ; extra == "pydantic"
50
+ Requires-Dist: pygments (>=2.3) ; extra == "cli"
50
51
  Requires-Dist: pygments (>=2.3) ; extra == "debug-server"
51
- Requires-Dist: pygments (>=2.3,<3.0) ; extra == "cli"
52
52
  Requires-Dist: pyinstrument (>=4.0.0) ; extra == "pyinstrument"
53
53
  Requires-Dist: python-dateutil (>=2.7)
54
54
  Requires-Dist: python-multipart (>=0.0.7) ; extra == "asgi"
@@ -189,7 +189,7 @@ strawberry/schema_codegen/__init__.py,sha256=HzgwI-rudoloXqJa5R9zyxXNTKLhdSXgSn7
189
189
  strawberry/schema_directive.py,sha256=H5tv1npCkEa-mUkzQ9nilNI3zTGEAhyagRcDwj5Rujw,2025
190
190
  strawberry/schema_directives.py,sha256=KGKFWCODjm1Ah9qNV_bBwbic7Mld4qLWnWQkev-PG8A,175
191
191
  strawberry/static/apollo-sandbox.html,sha256=2XzkbE0dqsFHqehE-jul9_J9TFOpwA6Ylrlo0Kdx_9w,973
192
- strawberry/static/graphiql.html,sha256=0e3pvTnAet-lNEqA_pgJ8Ak2CdMt34zPKMMMzpAkEVU,4257
192
+ strawberry/static/graphiql.html,sha256=czHhXGdLguz8k59237XKvWFIaMuUw91oe91nZ8fy6CI,6237
193
193
  strawberry/static/pathfinder.html,sha256=0DPx9AmJ2C_sJstFXnWOz9k5tVQHeHaK7qdVY4lAlmk,1547
194
194
  strawberry/streamable.py,sha256=8dqvKAv_Nhp8vEi4PUYyziCt3SUyCr6ZuqCNZ46Mqno,611
195
195
  strawberry/subscriptions/__init__.py,sha256=1VGmiCzFepqRFyCikagkUoHHdoTG3XYlFu9GafoQMws,170
@@ -210,7 +210,7 @@ strawberry/types/arguments.py,sha256=3Rt1WlVDMc0KKYmJOnMUckeTB0egJv96Uw7RMopM4DM
210
210
  strawberry/types/auto.py,sha256=4sDflIg-Kz-QpK7Qo7bCSFblw7VE-0752rgayukFznU,2954
211
211
  strawberry/types/base.py,sha256=Hubo7u6OsU1v1v-w-vBCwlNVTqHaNn4zPOJuX93WR5U,15699
212
212
  strawberry/types/cast.py,sha256=fx86MkLW77GIximBAwUk5vZxSGwDqUA6XicXvz8EXwQ,916
213
- strawberry/types/enum.py,sha256=Dc1emdlBi1m9pK9h6rdyq8VRaBLafQO7MQdKhVgYXvs,7286
213
+ strawberry/types/enum.py,sha256=sL7SMLx7W9h0-zxtKews6drfYtLUVZ1VorXuXp83mj4,8103
214
214
  strawberry/types/execution.py,sha256=z84AekAD_V_F4vGGHMPMGlAT0Htiw5JhEVvw1F9sGYQ,4019
215
215
  strawberry/types/field.py,sha256=-E5jfq7YXzI2CUepttfGzgmXFA1BTR2hmts44P-JpEk,20422
216
216
  strawberry/types/fields/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -238,8 +238,8 @@ strawberry/utils/logging.py,sha256=Dnivjd0ZhK_lAvjvuyCDkEWDhuURBoK9d3Kt_mIqbRg,7
238
238
  strawberry/utils/operation.py,sha256=Qs3ttbuC415xEVqmJ6YsWQpJNUo8CZJq9AoMB-yV65w,1215
239
239
  strawberry/utils/str_converters.py,sha256=-eH1Cl16IO_wrBlsGM-km4IY0IKsjhjnSNGRGOwQjVM,897
240
240
  strawberry/utils/typing.py,sha256=eE9NeMfASeXRstbjLnQFfOPymcSX8xwg3FGw_HCp95E,11828
241
- strawberry_graphql-0.288.3.dist-info/METADATA,sha256=3J3c_1M5jyi-DmVmNV0QVPWpgWG3OueKWrfp37AEhbM,7647
242
- strawberry_graphql-0.288.3.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
243
- strawberry_graphql-0.288.3.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
244
- strawberry_graphql-0.288.3.dist-info/licenses/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
245
- strawberry_graphql-0.288.3.dist-info/RECORD,,
241
+ strawberry_graphql-0.289.0.dist-info/METADATA,sha256=kS72_h2N1ZRutWs8b46_u8-eKJHscc495FQ56I_qNSE,7627
242
+ strawberry_graphql-0.289.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
243
+ strawberry_graphql-0.289.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
244
+ strawberry_graphql-0.289.0.dist-info/licenses/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
245
+ strawberry_graphql-0.289.0.dist-info/RECORD,,