graphql-complexity 1.0.0__tar.gz → 1.1.0__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 (21) hide show
  1. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/LICENSE +1 -1
  2. graphql_complexity-1.1.0/PKG-INFO +105 -0
  3. graphql_complexity-1.1.0/README.md +77 -0
  4. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/pyproject.toml +7 -7
  5. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/estimators/directive.py +2 -2
  6. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/evaluator/utils.py +1 -1
  7. graphql_complexity-1.0.0/PKG-INFO +0 -1129
  8. graphql_complexity-1.0.0/README.md +0 -1102
  9. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/__init__.py +0 -0
  10. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/config.py +0 -0
  11. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/estimators/__init__.py +0 -0
  12. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/estimators/arguments.py +0 -0
  13. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/estimators/base.py +0 -0
  14. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/estimators/simple.py +0 -0
  15. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/evaluator/__init__.py +0 -0
  16. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/evaluator/complexity.py +0 -0
  17. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/evaluator/explain.py +0 -0
  18. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/evaluator/nodes.py +0 -0
  19. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/evaluator/visitor.py +0 -0
  20. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/extensions/__init__.py +0 -0
  21. {graphql_complexity-1.0.0 → graphql_complexity-1.1.0}/src/graphql_complexity/extensions/strawberry_graphql.py +0 -0
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Checho3388
3
+ Copyright (c) 2026 Checho3388
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.4
2
+ Name: graphql_complexity
3
+ Version: 1.1.0
4
+ Summary: A python library that provides complexity calculation helpers for GraphQL
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Keywords: graphql,complexity,query,mutation,subscription
8
+ Author: Checho3388
9
+ Author-email: ezequiel.grondona@gmail.com
10
+ Requires-Python: >=3.10,<4.0
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: 3.15
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Provides-Extra: strawberry-graphql
23
+ Requires-Dist: graphql-core (>=3.2.3,<4.0.0)
24
+ Requires-Dist: strawberry-graphql (>=0.291.3,<0.335.0) ; extra == "strawberry-graphql"
25
+ Project-URL: Repository, https://github.com/Checho3388/graphql-complexity
26
+ Description-Content-Type: text/markdown
27
+
28
+ [![GraphQL Complexity Logo](https://github.com/Checho3388/graphql-complexity/raw/main/.github/logo.png)](https://github.com/Checho3388/graphql-complexity/raw/main/.github/logo.png)
29
+
30
+ # GraphQL Complexity
31
+
32
+ [![Build](https://github.com/Checho3388/graphql-complexity/actions/workflows/python-build.yml/badge.svg)](https://github.com/Checho3388/graphql-complexity/actions/workflows/python-build.yml)
33
+ [![PyPI](https://img.shields.io/pypi/v/graphql-complexity?label=pypi%20package)](https://pypi.org/project/graphql-complexity/)
34
+ [![codecov](https://codecov.io/gh/Checho3388/graphql-complexity/graph/badge.svg?token=4LH7AVN119)](https://codecov.io/gh/Checho3388/graphql-complexity)
35
+ [![Downloads](https://static.pepy.tech/badge/graphql-complexity)](https://pepy.tech/project/graphql-complexity)
36
+ [![Python Version](https://img.shields.io/pypi/pyversions/graphql-complexity)](https://pypi.org/project/graphql-complexity/)
37
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
38
+
39
+ Python library to compute the complexity of a GraphQL operation. Protect your API from expensive queries and potential DoS attacks by calculating complexity before execution.
40
+
41
+ 🎮 **Try it live:** [graphql-complexity playground](https://graphql-complexity-playground-production.up.railway.app/)
42
+ 📖 **Full docs:** [graphql-complexity.readthedocs.io](https://graphql-complexity.readthedocs.io)
43
+
44
+ ---
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ pip install graphql-complexity
50
+
51
+ # With Strawberry GraphQL support
52
+ pip install graphql-complexity[strawberry-graphql]
53
+ ```
54
+
55
+ ## Quick Start
56
+
57
+ ```python
58
+ from graphql_complexity import get_complexity, SimpleEstimator
59
+ from graphql import build_schema
60
+
61
+ schema = build_schema("""
62
+ type User {
63
+ id: ID!
64
+ name: String!
65
+ }
66
+ type Query {
67
+ user: User
68
+ }
69
+ """)
70
+
71
+ complexity = get_complexity(
72
+ query="query { user { id name } }",
73
+ schema=schema,
74
+ estimator=SimpleEstimator(complexity=1),
75
+ )
76
+
77
+ if complexity > 10:
78
+ raise Exception(f"Query is too complex: {complexity}")
79
+ ```
80
+
81
+ ## Estimators
82
+
83
+ | Estimator | Description |
84
+ |---|---|
85
+ | `SimpleEstimator` | Assigns a constant cost to every field |
86
+ | `DirectivesEstimator` | Reads cost from `@complexity(value: N)` schema directives |
87
+ | `ArgumentsEstimator` | Multiplies cost by a numeric/list argument (e.g. `limit`, `ids`) |
88
+ | Custom | Subclass `ComplexityEstimator` and implement `get_field_complexity` |
89
+
90
+ See the [estimators docs](https://graphql-complexity.readthedocs.io/en/latest/guides/estimators.html) for full reference and examples.
91
+
92
+ ## Integrations
93
+
94
+ See the [integrations docs](https://graphql-complexity.readthedocs.io/en/latest/guides/integrations.html) for examples
95
+ about how this library integrates with `strawberry`, `FastAPI`, `Flask` and `graphene-django`.
96
+
97
+
98
+ ## Credits
99
+
100
+ Estimators idea was heavily inspired by [graphql-query-complexity](https://github.com/slicknode/graphql-query-complexity).
101
+
102
+ ## License
103
+
104
+ [MIT](LICENSE)
105
+
@@ -0,0 +1,77 @@
1
+ [![GraphQL Complexity Logo](https://github.com/Checho3388/graphql-complexity/raw/main/.github/logo.png)](https://github.com/Checho3388/graphql-complexity/raw/main/.github/logo.png)
2
+
3
+ # GraphQL Complexity
4
+
5
+ [![Build](https://github.com/Checho3388/graphql-complexity/actions/workflows/python-build.yml/badge.svg)](https://github.com/Checho3388/graphql-complexity/actions/workflows/python-build.yml)
6
+ [![PyPI](https://img.shields.io/pypi/v/graphql-complexity?label=pypi%20package)](https://pypi.org/project/graphql-complexity/)
7
+ [![codecov](https://codecov.io/gh/Checho3388/graphql-complexity/graph/badge.svg?token=4LH7AVN119)](https://codecov.io/gh/Checho3388/graphql-complexity)
8
+ [![Downloads](https://static.pepy.tech/badge/graphql-complexity)](https://pepy.tech/project/graphql-complexity)
9
+ [![Python Version](https://img.shields.io/pypi/pyversions/graphql-complexity)](https://pypi.org/project/graphql-complexity/)
10
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
11
+
12
+ Python library to compute the complexity of a GraphQL operation. Protect your API from expensive queries and potential DoS attacks by calculating complexity before execution.
13
+
14
+ 🎮 **Try it live:** [graphql-complexity playground](https://graphql-complexity-playground-production.up.railway.app/)
15
+ 📖 **Full docs:** [graphql-complexity.readthedocs.io](https://graphql-complexity.readthedocs.io)
16
+
17
+ ---
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install graphql-complexity
23
+
24
+ # With Strawberry GraphQL support
25
+ pip install graphql-complexity[strawberry-graphql]
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ```python
31
+ from graphql_complexity import get_complexity, SimpleEstimator
32
+ from graphql import build_schema
33
+
34
+ schema = build_schema("""
35
+ type User {
36
+ id: ID!
37
+ name: String!
38
+ }
39
+ type Query {
40
+ user: User
41
+ }
42
+ """)
43
+
44
+ complexity = get_complexity(
45
+ query="query { user { id name } }",
46
+ schema=schema,
47
+ estimator=SimpleEstimator(complexity=1),
48
+ )
49
+
50
+ if complexity > 10:
51
+ raise Exception(f"Query is too complex: {complexity}")
52
+ ```
53
+
54
+ ## Estimators
55
+
56
+ | Estimator | Description |
57
+ |---|---|
58
+ | `SimpleEstimator` | Assigns a constant cost to every field |
59
+ | `DirectivesEstimator` | Reads cost from `@complexity(value: N)` schema directives |
60
+ | `ArgumentsEstimator` | Multiplies cost by a numeric/list argument (e.g. `limit`, `ids`) |
61
+ | Custom | Subclass `ComplexityEstimator` and implement `get_field_complexity` |
62
+
63
+ See the [estimators docs](https://graphql-complexity.readthedocs.io/en/latest/guides/estimators.html) for full reference and examples.
64
+
65
+ ## Integrations
66
+
67
+ See the [integrations docs](https://graphql-complexity.readthedocs.io/en/latest/guides/integrations.html) for examples
68
+ about how this library integrates with `strawberry`, `FastAPI`, `Flask` and `graphene-django`.
69
+
70
+
71
+ ## Credits
72
+
73
+ Estimators idea was heavily inspired by [graphql-query-complexity](https://github.com/slicknode/graphql-query-complexity).
74
+
75
+ ## License
76
+
77
+ [MIT](LICENSE)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "graphql_complexity"
3
- version = "1.0.0"
3
+ version = "1.1.0"
4
4
  description = "A python library that provides complexity calculation helpers for GraphQL"
5
5
  authors = ["Checho3388 <ezequiel.grondona@gmail.com>"]
6
6
  packages = [
@@ -25,18 +25,18 @@ keywords = ["graphql", "complexity", "query", "mutation", "subscription"]
25
25
  [tool.poetry.dependencies]
26
26
  python = "^3.10"
27
27
  graphql-core = "^3.2.3"
28
- strawberry-graphql = "^0.291.3"
28
+ strawberry-graphql = ">=0.291.3,<0.335.0"
29
29
 
30
30
  [tool.poetry.extras]
31
31
  strawberry-graphql = ["strawberry-graphql"]
32
32
 
33
33
  [tool.poetry.group.dev.dependencies]
34
- pytest = "^8.0.0"
35
- mypy = "^1.8.0"
36
- black = "^24.2.0"
37
- pytest-cov = "^4.1.0"
34
+ pytest = ">=8.1,<10"
35
+ mypy = ">=1.8,<3.0"
36
+ black = ">=24.2,<27.0"
37
+ pytest-cov = ">=4.1,<8.0"
38
38
  flake8 = "^7.0.0"
39
- pytest-benchmark = "^4.0.0"
39
+ pytest-benchmark = ">=4,<6"
40
40
 
41
41
  [build-system]
42
42
  requires = ["poetry-core"]
@@ -16,11 +16,11 @@ class DirectivesVisitor(Visitor):
16
16
  super().__init__()
17
17
 
18
18
  def enter_field_definition(self, node, key, parent, path, ancestors):
19
- for directive in node.directives:
19
+ for directive in node.directives or ():
20
20
  if directive.name.value == self.directive_name:
21
21
  complexity = next(
22
22
  arg.value.value
23
- for arg in directive.arguments
23
+ for arg in directive.arguments or ()
24
24
  if arg.name.value == DIRECTIVE_ESTIMATOR_FIELD_COMPLEXITY_NAME
25
25
  )
26
26
  self._collector[node.name.value] = int(complexity)
@@ -14,7 +14,7 @@ if TYPE_CHECKING:
14
14
 
15
15
  def get_node_argument_value(node: FieldNode | DirectiveNode, arg_name: str, variables: dict[str, Any]) -> Any:
16
16
  """Returns the value of the argument given by parameter."""
17
- arg = next((arg for arg in node.arguments if arg.name.value == arg_name), None)
17
+ arg = next((arg for arg in node.arguments or () if arg.name.value == arg_name), None)
18
18
  if not arg:
19
19
  raise ValueError(f"Value for {arg_name!r} not found in {node.name.value!r} arguments")
20
20