macss-modular-api-graphql-client 0.6.0__tar.gz → 0.7.1__tar.gz

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.
Files changed (14) hide show
  1. {macss_modular_api_graphql_client-0.6.0 → macss_modular_api_graphql_client-0.7.1}/PKG-INFO +2 -1
  2. macss_modular_api_graphql_client-0.7.1/pyproject.toml +85 -0
  3. {macss_modular_api_graphql_client-0.6.0 → macss_modular_api_graphql_client-0.7.1}/src/macss_modular_api_graphql_client.egg-info/PKG-INFO +2 -1
  4. {macss_modular_api_graphql_client-0.6.0 → macss_modular_api_graphql_client-0.7.1}/src/macss_modular_api_graphql_client.egg-info/SOURCES.txt +1 -0
  5. {macss_modular_api_graphql_client-0.6.0 → macss_modular_api_graphql_client-0.7.1}/src/macss_modular_api_graphql_client.egg-info/requires.txt +1 -0
  6. {macss_modular_api_graphql_client-0.6.0 → macss_modular_api_graphql_client-0.7.1}/src/modular_api_graphql_client/client.py +45 -32
  7. macss_modular_api_graphql_client-0.7.1/src/modular_api_graphql_client/py.typed +0 -0
  8. {macss_modular_api_graphql_client-0.6.0 → macss_modular_api_graphql_client-0.7.1}/tests/test_graphql_client.py +3 -2
  9. macss_modular_api_graphql_client-0.6.0/pyproject.toml +0 -46
  10. {macss_modular_api_graphql_client-0.6.0 → macss_modular_api_graphql_client-0.7.1}/README.md +0 -0
  11. {macss_modular_api_graphql_client-0.6.0 → macss_modular_api_graphql_client-0.7.1}/setup.cfg +0 -0
  12. {macss_modular_api_graphql_client-0.6.0 → macss_modular_api_graphql_client-0.7.1}/src/macss_modular_api_graphql_client.egg-info/dependency_links.txt +0 -0
  13. {macss_modular_api_graphql_client-0.6.0 → macss_modular_api_graphql_client-0.7.1}/src/macss_modular_api_graphql_client.egg-info/top_level.txt +0 -0
  14. {macss_modular_api_graphql_client-0.6.0 → macss_modular_api_graphql_client-0.7.1}/src/modular_api_graphql_client/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: macss-modular-api-graphql-client
3
- Version: 0.6.0
3
+ Version: 0.7.1
4
4
  Summary: Official MACSS outbound GraphQL client for Python.
5
5
  Author: ccisne.dev
6
6
  License-Expression: MIT
@@ -20,6 +20,7 @@ Classifier: Typing :: Typed
20
20
  Requires-Python: >=3.11
21
21
  Description-Content-Type: text/markdown
22
22
  Provides-Extra: dev
23
+ Requires-Dist: pyright>=1.1.400; extra == "dev"
23
24
  Requires-Dist: pytest>=8.0; extra == "dev"
24
25
 
25
26
  # macss-modular-api-graphql-client
@@ -0,0 +1,85 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "macss-modular-api-graphql-client"
7
+ version = "0.7.1"
8
+ description = "Official MACSS outbound GraphQL client for Python."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.11"
12
+ authors = [{ name = "ccisne.dev" }]
13
+ keywords = ["macss", "graphql", "client"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
22
+ "Typing :: Typed",
23
+ ]
24
+ dependencies = []
25
+
26
+ [project.optional-dependencies]
27
+ dev = [
28
+ # Configured below at `typeCheckingMode = "strict"`. Declared here because a checker the
29
+ # repo configures and never installs is a checker that has never run.
30
+ "pyright>=1.1.400",
31
+ "pytest>=8.0",
32
+ ]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/macss-dev/modular_api"
36
+ Repository = "https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api_graphql_client"
37
+ Issues = "https://github.com/macss-dev/modular_api/issues"
38
+ Documentation = "https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api_graphql_client#readme"
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["src"]
42
+
43
+ [tool.pytest.ini_options]
44
+ testpaths = ["tests"]
45
+ pythonpath = ["src"]
46
+
47
+ [tool.pyright]
48
+ pythonVersion = "3.11"
49
+ # `src/` is checked at full strict, because it is what a consumer's own type checker sees: these
50
+ # packages ship `py.typed`, so every annotation here becomes part of the public contract.
51
+ typeCheckingMode = "strict"
52
+
53
+ # `tests/` is strict too, minus the family that means "annotate this expression". Test code binds
54
+ # only this repo, and most of those diagnostics come from incomplete third-party stubs — annotating
55
+ # around them adds noise to a test without making anything more correct. Everything that can indicate
56
+ # a real defect stays on.
57
+ [[tool.pyright.executionEnvironments]]
58
+ root = "tests"
59
+ reportUnknownMemberType = false
60
+ reportUnknownArgumentType = false
61
+ reportUnknownVariableType = false
62
+ reportUnknownParameterType = false
63
+ reportUnknownLambdaType = false
64
+ reportMissingParameterType = false
65
+ reportMissingTypeArgument = false
66
+ # A pytest fixture is called by name through collection, never by a reference the checker can see, so
67
+ # `reportUnusedFunction` reports every `autouse` fixture in this tree. That is the tool not modelling
68
+ # pytest, not dead code. `reportUnusedImport` and `reportUnusedVariable` stay on — those do find dead
69
+ # code, and they did.
70
+ reportUnusedFunction = false
71
+ reportUnusedClass = false
72
+ # Tests legitimately reach into internals to exercise them directly. In `src/` this rule found real
73
+ # coupling and it was fixed rather than silenced.
74
+ reportPrivateUsage = false
75
+ # `example/` is documentation a consumer copies, not a published typed surface — same relaxed family
76
+ # as `tests/`, and the same expectation that nothing which can indicate a real defect is silenced.
77
+ [[tool.pyright.executionEnvironments]]
78
+ root = "example"
79
+ reportUnknownMemberType = false
80
+ reportUnknownArgumentType = false
81
+ reportUnknownVariableType = false
82
+ reportUnknownParameterType = false
83
+ reportUnknownLambdaType = false
84
+ reportMissingParameterType = false
85
+ reportMissingTypeArgument = false
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: macss-modular-api-graphql-client
3
- Version: 0.6.0
3
+ Version: 0.7.1
4
4
  Summary: Official MACSS outbound GraphQL client for Python.
5
5
  Author: ccisne.dev
6
6
  License-Expression: MIT
@@ -20,6 +20,7 @@ Classifier: Typing :: Typed
20
20
  Requires-Python: >=3.11
21
21
  Description-Content-Type: text/markdown
22
22
  Provides-Extra: dev
23
+ Requires-Dist: pyright>=1.1.400; extra == "dev"
23
24
  Requires-Dist: pytest>=8.0; extra == "dev"
24
25
 
25
26
  # macss-modular-api-graphql-client
@@ -7,4 +7,5 @@ src/macss_modular_api_graphql_client.egg-info/requires.txt
7
7
  src/macss_modular_api_graphql_client.egg-info/top_level.txt
8
8
  src/modular_api_graphql_client/__init__.py
9
9
  src/modular_api_graphql_client/client.py
10
+ src/modular_api_graphql_client/py.typed
10
11
  tests/test_graphql_client.py
@@ -33,7 +33,7 @@ class ServiceClientConfig:
33
33
  service_id: str
34
34
  base_url: str
35
35
  redacted_summary: str
36
- default_headers: Mapping[str, str] = field(default_factory=dict)
36
+ default_headers: Mapping[str, str] = field(default_factory=dict[str, str])
37
37
  auth_provider: ServiceAuthProvider | None = None
38
38
  timeout: float | None = None
39
39
  retry_policy: ServiceRetryPolicy | None = None
@@ -45,7 +45,7 @@ class ServiceClientConfig:
45
45
  class ServiceOperation:
46
46
  transport_id: str
47
47
  operation_id: str
48
- headers: Mapping[str, str] = field(default_factory=dict)
48
+ headers: Mapping[str, str] = field(default_factory=dict[str, str])
49
49
  method: str | None = None
50
50
  path: str | None = None
51
51
  query: Mapping[str, object] | None = None
@@ -165,8 +165,8 @@ class GraphqlErrorLocation:
165
165
  @dataclass(frozen=True, slots=True)
166
166
  class GraphqlError:
167
167
  message: str
168
- path: list[object] = field(default_factory=list)
169
- locations: list[GraphqlErrorLocation] = field(default_factory=list)
168
+ path: list[object] = field(default_factory=list[object])
169
+ locations: list[GraphqlErrorLocation] = field(default_factory=list[GraphqlErrorLocation])
170
170
  extensions: dict[str, object] | None = None
171
171
 
172
172
 
@@ -199,7 +199,7 @@ class GraphqlClient:
199
199
  decoder: GraphqlDecoder[T] | None = None,
200
200
  ) -> ServiceResult[GraphqlResponse[T]]:
201
201
  if self._closed:
202
- return ServiceResult.from_failure(
202
+ return ServiceResult[GraphqlResponse[T]].from_failure(
203
203
  ServiceFailure(
204
204
  category=ServiceFailureCategory.UNEXPECTED,
205
205
  code="client_closed",
@@ -210,7 +210,7 @@ class GraphqlClient:
210
210
  )
211
211
 
212
212
  if _is_mutation_document(request.document or ""):
213
- return ServiceResult.from_failure(
213
+ return ServiceResult[GraphqlResponse[T]].from_failure(
214
214
  ServiceFailure(
215
215
  category=ServiceFailureCategory.GRAPHQL,
216
216
  code="mutation_not_supported",
@@ -247,13 +247,13 @@ class GraphqlClient:
247
247
  header_map = _headers_to_record(response.headers)
248
248
  envelope = _decode_envelope(response_text, response.headers.get_content_type())
249
249
  if isinstance(envelope, ServiceFailure):
250
- result = ServiceResult.from_failure(envelope)
250
+ result = ServiceResult[GraphqlResponse[T]].from_failure(envelope)
251
251
  else:
252
252
  decoded = _decode_data(envelope.get("data"), decoder)
253
253
  if isinstance(decoded, ServiceFailure):
254
- result = ServiceResult.from_failure(decoded)
254
+ result = ServiceResult[GraphqlResponse[T]].from_failure(decoded)
255
255
  else:
256
- result = ServiceResult.success(
256
+ result = ServiceResult[GraphqlResponse[T]].success(
257
257
  GraphqlResponse(
258
258
  data=decoded,
259
259
  errors=_parse_errors(envelope.get("errors")),
@@ -269,7 +269,7 @@ class GraphqlClient:
269
269
  )
270
270
  except urllib.error.HTTPError as error:
271
271
  details = error.read().decode("utf-8")
272
- result = ServiceResult.from_failure(
272
+ result = ServiceResult[GraphqlResponse[T]].from_failure(
273
273
  ServiceFailure(
274
274
  category=_category_for_status(error.code),
275
275
  code=_code_for_status(error.code),
@@ -283,7 +283,7 @@ class GraphqlClient:
283
283
  except urllib.error.URLError as error:
284
284
  reason = error.reason
285
285
  if isinstance(reason, (TimeoutError, socket.timeout)):
286
- result = ServiceResult.from_failure(
286
+ result = ServiceResult[GraphqlResponse[T]].from_failure(
287
287
  ServiceFailure(
288
288
  category=ServiceFailureCategory.TIMEOUT,
289
289
  code="timeout",
@@ -294,7 +294,7 @@ class GraphqlClient:
294
294
  )
295
295
  )
296
296
  else:
297
- result = ServiceResult.from_failure(
297
+ result = ServiceResult[GraphqlResponse[T]].from_failure(
298
298
  ServiceFailure(
299
299
  category=ServiceFailureCategory.TRANSPORT,
300
300
  code="transport_error",
@@ -305,7 +305,7 @@ class GraphqlClient:
305
305
  )
306
306
  )
307
307
  except (TimeoutError, socket.timeout) as error:
308
- result = ServiceResult.from_failure(
308
+ result = ServiceResult[GraphqlResponse[T]].from_failure(
309
309
  ServiceFailure(
310
310
  category=ServiceFailureCategory.TIMEOUT,
311
311
  code="timeout",
@@ -316,7 +316,7 @@ class GraphqlClient:
316
316
  )
317
317
  )
318
318
  except Exception as error: # noqa: BLE001
319
- result = ServiceResult.from_failure(
319
+ result = ServiceResult[GraphqlResponse[T]].from_failure(
320
320
  ServiceFailure(
321
321
  category=ServiceFailureCategory.UNEXPECTED,
322
322
  code="unexpected_error",
@@ -333,7 +333,7 @@ class GraphqlClient:
333
333
 
334
334
  def close(self) -> ServiceResult[None]:
335
335
  self._closed = True
336
- return ServiceResult.success(None)
336
+ return ServiceResult[None].success(None)
337
337
 
338
338
  def _build_headers(self, request: GraphqlRequest) -> dict[str, str]:
339
339
  headers = {
@@ -459,33 +459,46 @@ def _decode_data(
459
459
 
460
460
 
461
461
  def _parse_errors(value: object | None) -> list[GraphqlError]:
462
+ """Parses the ``errors`` array of a GraphQL response.
463
+
464
+ Every value here arrives from JSON, so nothing may be assumed about its shape. The narrowing was
465
+ already correct — each access sat behind an ``isinstance`` — but a bare ``isinstance(x, dict)``
466
+ narrows only to ``dict[Unknown, Unknown]``, so the checker still could not see what came out. The
467
+ casts below carry the shape the guard has already established; they add no runtime behaviour and
468
+ replace four redundant re-checks of a condition the loop had already decided.
469
+ """
462
470
  if not isinstance(value, list):
463
471
  return []
464
472
 
465
473
  errors: list[GraphqlError] = []
466
- for entry in value:
467
- error = entry if isinstance(entry, dict) else {}
468
- raw_locations = error.get("locations") if isinstance(error, dict) else None
474
+ for entry in cast("list[object]", value):
475
+ if not isinstance(entry, dict):
476
+ continue
477
+ error = cast("dict[str, object]", entry)
478
+
469
479
  locations: list[GraphqlErrorLocation] = []
480
+ raw_locations = error.get("locations")
470
481
  if isinstance(raw_locations, list):
471
- for location in raw_locations:
472
- if isinstance(location, dict):
473
- line = location.get("line")
474
- column = location.get("column")
475
- locations.append(
476
- GraphqlErrorLocation(
477
- line=line if isinstance(line, int) else 0,
478
- column=column if isinstance(column, int) else 0,
479
- )
482
+ for raw_location in cast("list[object]", raw_locations):
483
+ if not isinstance(raw_location, dict):
484
+ continue
485
+ location = cast("dict[str, object]", raw_location)
486
+ line = location.get("line")
487
+ column = location.get("column")
488
+ locations.append(
489
+ GraphqlErrorLocation(
490
+ line=line if isinstance(line, int) else 0,
491
+ column=column if isinstance(column, int) else 0,
480
492
  )
493
+ )
481
494
 
482
- message = error.get("message", "Unknown GraphQL error") if isinstance(error, dict) else "Unknown GraphQL error"
495
+ raw_path = error.get("path")
483
496
  errors.append(
484
497
  GraphqlError(
485
- message=str(message),
486
- path=list(error.get("path", [])) if isinstance(error, dict) and isinstance(error.get("path"), list) else [],
498
+ message=str(error.get("message", "Unknown GraphQL error")),
499
+ path=list(cast("list[object]", raw_path)) if isinstance(raw_path, list) else [],
487
500
  locations=locations,
488
- extensions=_parse_extensions(error.get("extensions")) if isinstance(error, dict) else None,
501
+ extensions=_parse_extensions(error.get("extensions")),
489
502
  )
490
503
  )
491
504
 
@@ -495,7 +508,7 @@ def _parse_errors(value: object | None) -> list[GraphqlError]:
495
508
  def _parse_extensions(value: object | None) -> dict[str, object] | None:
496
509
  if not isinstance(value, dict):
497
510
  return None
498
- return {str(key): item for key, item in value.items()}
511
+ return {str(key): item for key, item in cast("dict[object, object]", value).items()}
499
512
 
500
513
 
501
514
  def _is_mutation_document(document: str) -> bool:
@@ -5,6 +5,7 @@ import threading
5
5
  import time
6
6
  from dataclasses import dataclass
7
7
  from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
8
+ from typing import Any, cast
8
9
 
9
10
  from modular_api_graphql_client import (
10
11
  GraphqlClient,
@@ -69,7 +70,7 @@ def test_graphql_client_sends_a_post_request_and_decodes_the_envelope() -> None:
69
70
  variables={"limit": 10},
70
71
  headers={"x-request": "test"},
71
72
  ),
72
- decoder=lambda value: dict(value or {}),
73
+ decoder=lambda value: dict(cast("dict[str, Any]", value or {})),
73
74
  )
74
75
 
75
76
  assert result.is_success is True
@@ -150,7 +151,7 @@ def test_graphql_client_injects_auth_headers_from_the_auth_provider() -> None:
150
151
  operation_id="users.auth",
151
152
  document="query Viewer { viewer { id } }",
152
153
  ),
153
- decoder=lambda value: dict(value or {}),
154
+ decoder=lambda value: dict(cast("dict[str, Any]", value or {})),
154
155
  )
155
156
 
156
157
  assert result.is_success is True
@@ -1,46 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=68", "wheel"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "macss-modular-api-graphql-client"
7
- version = "0.6.0"
8
- description = "Official MACSS outbound GraphQL client for Python."
9
- readme = "README.md"
10
- license = "MIT"
11
- requires-python = ">=3.11"
12
- authors = [{ name = "ccisne.dev" }]
13
- keywords = ["macss", "graphql", "client"]
14
- classifiers = [
15
- "Development Status :: 4 - Beta",
16
- "Intended Audience :: Developers",
17
- "Programming Language :: Python :: 3",
18
- "Programming Language :: Python :: 3.11",
19
- "Programming Language :: Python :: 3.12",
20
- "Programming Language :: Python :: 3.13",
21
- "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
22
- "Typing :: Typed",
23
- ]
24
- dependencies = []
25
-
26
- [project.optional-dependencies]
27
- dev = [
28
- "pytest>=8.0",
29
- ]
30
-
31
- [project.urls]
32
- Homepage = "https://github.com/macss-dev/modular_api"
33
- Repository = "https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api_graphql_client"
34
- Issues = "https://github.com/macss-dev/modular_api/issues"
35
- Documentation = "https://github.com/macss-dev/modular_api/tree/main/code/py/modular_api_graphql_client#readme"
36
-
37
- [tool.setuptools.packages.find]
38
- where = ["src"]
39
-
40
- [tool.pytest.ini_options]
41
- testpaths = ["tests"]
42
- pythonpath = ["src"]
43
-
44
- [tool.pyright]
45
- pythonVersion = "3.11"
46
- typeCheckingMode = "strict"