strawberry-graphql 0.235.1.dev1719337273__py3-none-any.whl → 0.236.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.
- strawberry/__init__.py +17 -11
- strawberry/aiohttp/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/aiohttp/handlers/graphql_ws_handler.py +3 -0
- strawberry/aiohttp/test/client.py +3 -0
- strawberry/aiohttp/views.py +3 -0
- strawberry/annotation.py +19 -22
- strawberry/asgi/__init__.py +3 -3
- strawberry/asgi/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/asgi/handlers/graphql_ws_handler.py +3 -0
- strawberry/asgi/test/client.py +3 -0
- strawberry/chalice/views.py +12 -3
- strawberry/channels/handlers/__init__.py +0 -0
- strawberry/channels/handlers/base.py +5 -5
- strawberry/channels/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/channels/handlers/graphql_ws_handler.py +3 -0
- strawberry/channels/handlers/http_handler.py +5 -2
- strawberry/channels/handlers/ws_handler.py +4 -1
- strawberry/channels/router.py +9 -5
- strawberry/channels/testing.py +11 -4
- strawberry/cli/commands/upgrade/__init__.py +13 -5
- strawberry/cli/commands/upgrade/_fake_progress.py +2 -1
- strawberry/cli/commands/upgrade/_run_codemod.py +18 -1
- strawberry/codegen/exceptions.py +8 -0
- strawberry/codegen/query_codegen.py +16 -7
- strawberry/codegen/types.py +32 -1
- strawberry/codemods/update_imports.py +136 -0
- strawberry/dataloader.py +13 -0
- strawberry/directive.py +52 -4
- strawberry/django/context.py +4 -1
- strawberry/django/test/client.py +3 -0
- strawberry/django/views.py +3 -0
- strawberry/exceptions/__init__.py +5 -5
- strawberry/exceptions/duplicated_type_name.py +1 -1
- strawberry/exceptions/invalid_argument_type.py +3 -3
- strawberry/exceptions/invalid_union_type.py +5 -6
- strawberry/exceptions/missing_arguments_annotations.py +1 -1
- strawberry/exceptions/missing_dependencies.py +10 -2
- strawberry/exceptions/missing_return_annotation.py +1 -1
- strawberry/exceptions/permission_fail_silently_requires_optional.py +3 -3
- strawberry/exceptions/scalar_already_registered.py +1 -1
- strawberry/exceptions/unresolved_field_type.py +2 -2
- strawberry/exceptions/utils/source_finder.py +5 -2
- strawberry/experimental/pydantic/conversion.py +5 -5
- strawberry/experimental/pydantic/conversion_types.py +4 -2
- strawberry/experimental/pydantic/error_type.py +2 -2
- strawberry/experimental/pydantic/fields.py +2 -2
- strawberry/experimental/pydantic/object_type.py +11 -7
- strawberry/experimental/pydantic/utils.py +4 -5
- strawberry/ext/dataclasses/dataclasses.py +2 -1
- strawberry/ext/mypy_plugin.py +10 -8
- strawberry/extensions/add_validation_rules.py +27 -23
- strawberry/extensions/base_extension.py +6 -4
- strawberry/extensions/directives.py +4 -1
- strawberry/extensions/disable_validation.py +15 -12
- strawberry/extensions/field_extension.py +11 -5
- strawberry/extensions/mask_errors.py +3 -0
- strawberry/extensions/max_aliases.py +21 -19
- strawberry/extensions/max_tokens.py +14 -16
- strawberry/extensions/parser_cache.py +22 -19
- strawberry/extensions/pyinstrument.py +4 -8
- strawberry/extensions/query_depth_limiter.py +22 -23
- strawberry/extensions/runner.py +3 -0
- strawberry/extensions/tracing/apollo.py +3 -0
- strawberry/extensions/tracing/datadog.py +7 -2
- strawberry/extensions/tracing/opentelemetry.py +3 -0
- strawberry/extensions/tracing/sentry.py +3 -0
- strawberry/extensions/tracing/utils.py +3 -0
- strawberry/extensions/utils.py +3 -0
- strawberry/extensions/validation_cache.py +23 -20
- strawberry/fastapi/context.py +3 -0
- strawberry/fastapi/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/fastapi/handlers/graphql_ws_handler.py +3 -0
- strawberry/fastapi/router.py +3 -0
- strawberry/federation/argument.py +4 -1
- strawberry/federation/enum.py +5 -3
- strawberry/federation/field.py +6 -3
- strawberry/federation/mutation.py +2 -0
- strawberry/federation/object_type.py +7 -4
- strawberry/federation/scalar.py +43 -20
- strawberry/federation/schema.py +12 -9
- strawberry/federation/schema_directive.py +2 -2
- strawberry/federation/schema_directives.py +19 -1
- strawberry/federation/types.py +5 -2
- strawberry/federation/union.py +27 -8
- strawberry/field_extensions/input_mutation.py +5 -2
- strawberry/file_uploads/scalars.py +3 -1
- strawberry/file_uploads/utils.py +3 -0
- strawberry/flask/views.py +8 -2
- strawberry/http/__init__.py +9 -0
- strawberry/http/async_base_view.py +4 -3
- strawberry/http/base.py +5 -7
- strawberry/http/exceptions.py +3 -0
- strawberry/http/ides.py +3 -0
- strawberry/http/sync_base_view.py +4 -3
- strawberry/http/temporal_response.py +3 -0
- strawberry/http/types.py +5 -2
- strawberry/http/typevars.py +3 -0
- strawberry/litestar/controller.py +6 -0
- strawberry/litestar/handlers/__init__.py +0 -0
- strawberry/litestar/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/litestar/handlers/graphql_ws_handler.py +3 -0
- strawberry/parent.py +27 -21
- strawberry/permission.py +70 -27
- strawberry/printer/ast_from_value.py +4 -1
- strawberry/printer/printer.py +8 -5
- strawberry/quart/views.py +3 -0
- strawberry/relay/exceptions.py +7 -0
- strawberry/relay/fields.py +70 -45
- strawberry/relay/types.py +78 -78
- strawberry/relay/utils.py +10 -1
- strawberry/resolvers.py +3 -0
- strawberry/sanic/context.py +3 -0
- strawberry/sanic/utils.py +10 -8
- strawberry/sanic/views.py +5 -9
- strawberry/scalars.py +6 -2
- strawberry/schema/base.py +7 -4
- strawberry/schema/compat.py +12 -2
- strawberry/schema/config.py +3 -0
- strawberry/schema/exceptions.py +3 -0
- strawberry/schema/execute.py +3 -0
- strawberry/schema/name_converter.py +12 -9
- strawberry/schema/schema.py +46 -9
- strawberry/schema/schema_converter.py +16 -14
- strawberry/schema/types/base_scalars.py +3 -1
- strawberry/schema/types/concrete_type.py +4 -4
- strawberry/schema/types/scalar.py +8 -1
- strawberry/schema/validation_rules/one_of.py +3 -0
- strawberry/schema_codegen/__init__.py +3 -0
- strawberry/schema_directive.py +2 -2
- strawberry/starlite/controller.py +3 -0
- strawberry/starlite/handlers/__init__.py +0 -0
- strawberry/starlite/handlers/graphql_transport_ws_handler.py +3 -0
- strawberry/starlite/handlers/graphql_ws_handler.py +3 -0
- strawberry/subscriptions/__init__.py +6 -0
- strawberry/subscriptions/protocols/graphql_transport_ws/__init__.py +5 -0
- strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +12 -17
- strawberry/subscriptions/protocols/graphql_transport_ws/types.py +21 -25
- strawberry/subscriptions/protocols/graphql_ws/__init__.py +14 -0
- strawberry/subscriptions/protocols/graphql_ws/handlers.py +8 -5
- strawberry/subscriptions/protocols/graphql_ws/types.py +11 -0
- strawberry/test/client.py +44 -29
- strawberry/tools/create_type.py +27 -8
- strawberry/tools/merge_types.py +5 -3
- strawberry/types/__init__.py +8 -1
- strawberry/{arguments.py → types/arguments.py} +44 -13
- strawberry/{auto.py → types/auto.py} +21 -3
- strawberry/types/{types.py → base.py} +234 -10
- strawberry/{enum.py → types/enum.py} +69 -9
- strawberry/types/execution.py +3 -0
- strawberry/{field.py → types/field.py} +46 -23
- strawberry/types/fields/resolver.py +2 -2
- strawberry/types/graphql.py +3 -0
- strawberry/types/info.py +50 -7
- strawberry/{lazy_type.py → types/lazy_type.py} +50 -0
- strawberry/types/mutation.py +351 -0
- strawberry/types/nodes.py +4 -2
- strawberry/{object_type.py → types/object_type.py} +108 -29
- strawberry/{private.py → types/private.py} +13 -6
- strawberry/{custom_scalar.py → types/scalar.py} +39 -23
- strawberry/types/type_resolver.py +21 -16
- strawberry/{union.py → types/union.py} +24 -9
- strawberry/{unset.py → types/unset.py} +20 -0
- strawberry/utils/aio.py +8 -0
- strawberry/utils/await_maybe.py +3 -0
- strawberry/utils/dataclasses.py +3 -0
- strawberry/utils/debug.py +5 -2
- strawberry/utils/deprecations.py +3 -0
- strawberry/utils/graphql_lexer.py +3 -0
- strawberry/utils/importer.py +3 -0
- strawberry/utils/inspect.py +39 -30
- strawberry/utils/logging.py +3 -0
- strawberry/utils/operation.py +3 -0
- strawberry/utils/str_converters.py +3 -0
- strawberry/utils/typing.py +33 -16
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/METADATA +1 -1
- strawberry_graphql-0.236.0.dist-info/RECORD +255 -0
- strawberry/mutation.py +0 -8
- strawberry/type.py +0 -232
- strawberry_graphql-0.235.1.dev1719337273.dist-info/RECORD +0 -252
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/LICENSE +0 -0
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/WHEEL +0 -0
- {strawberry_graphql-0.235.1.dev1719337273.dist-info → strawberry_graphql-0.236.0.dist-info}/entry_points.txt +0 -0
strawberry/relay/types.py
CHANGED
@@ -26,14 +26,17 @@ from typing import (
|
|
26
26
|
)
|
27
27
|
from typing_extensions import Annotated, Literal, Self, TypeAlias, get_args, get_origin
|
28
28
|
|
29
|
-
from strawberry.field import field
|
30
|
-
from strawberry.lazy_type import LazyType
|
31
|
-
from strawberry.object_type import interface, type
|
32
|
-
from strawberry.private import StrawberryPrivate
|
33
29
|
from strawberry.relay.exceptions import NodeIDAnnotationError
|
34
|
-
from strawberry.
|
30
|
+
from strawberry.types.base import (
|
31
|
+
StrawberryContainer,
|
32
|
+
StrawberryObjectDefinition,
|
33
|
+
get_object_definition,
|
34
|
+
)
|
35
|
+
from strawberry.types.field import field
|
35
36
|
from strawberry.types.info import Info # noqa: TCH001
|
36
|
-
from strawberry.types.
|
37
|
+
from strawberry.types.lazy_type import LazyType
|
38
|
+
from strawberry.types.object_type import interface, type
|
39
|
+
from strawberry.types.private import StrawberryPrivate
|
37
40
|
from strawberry.utils.aio import aenumerate, aislice, resolve_awaitable
|
38
41
|
from strawberry.utils.inspect import in_async_context
|
39
42
|
from strawberry.utils.typing import eval_type, is_classvar
|
@@ -319,9 +322,14 @@ class NodeIDPrivate(StrawberryPrivate):
|
|
319
322
|
The `Node` interface will automatically create and resolve GlobalIDs
|
320
323
|
based on the field annotated with `NodeID`. e.g:
|
321
324
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
+
```python
|
326
|
+
import strawberry
|
327
|
+
|
328
|
+
|
329
|
+
@strawberry.type
|
330
|
+
class Fruit(Node):
|
331
|
+
code: NodeID[str]
|
332
|
+
```
|
325
333
|
|
326
334
|
In this case, `code` will be used to generate a global ID in the
|
327
335
|
format `Fruit:<code>` and will be exposed as `id: GlobalID!` in the
|
@@ -352,17 +360,20 @@ class Node:
|
|
352
360
|
single node id.
|
353
361
|
|
354
362
|
Example:
|
363
|
+
```python
|
364
|
+
import strawberry
|
365
|
+
|
355
366
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
...
|
361
|
-
... @classmethod
|
362
|
-
... def resolve_nodes(cls, *, info, node_ids, required=False):
|
363
|
-
... # Return an iterable of fruits in here
|
364
|
-
... ...
|
367
|
+
@strawberry.type
|
368
|
+
class Fruit(strawberry.relay.Node):
|
369
|
+
id: strawberry.relay.NodeID[int]
|
370
|
+
name: str
|
365
371
|
|
372
|
+
@classmethod
|
373
|
+
def resolve_nodes(cls, *, info, node_ids, required=False):
|
374
|
+
# Return an iterable of fruits in here
|
375
|
+
...
|
376
|
+
```
|
366
377
|
"""
|
367
378
|
|
368
379
|
_id_attr: ClassVar[Optional[str]] = None
|
@@ -467,10 +478,8 @@ class Node:
|
|
467
478
|
You can override this method to provide a custom implementation.
|
468
479
|
|
469
480
|
Args:
|
470
|
-
info:
|
471
|
-
|
472
|
-
root:
|
473
|
-
The node to resolve
|
481
|
+
info: The strawberry execution info resolve the type name from.
|
482
|
+
root: The node to resolve.
|
474
483
|
|
475
484
|
Returns:
|
476
485
|
The resolved id (which is expected to be str)
|
@@ -535,12 +544,9 @@ class Node:
|
|
535
544
|
returned as `None`.
|
536
545
|
|
537
546
|
Args:
|
538
|
-
info:
|
539
|
-
|
540
|
-
node_ids
|
541
|
-
List of node ids that should be returned
|
542
|
-
required:
|
543
|
-
If `True`, all `node_ids` requested must exist. If they don't,
|
547
|
+
info: The strawberry execution info resolve the type name from.
|
548
|
+
node_ids: List of node ids that should be returned.
|
549
|
+
required: If `True`, all `node_ids` requested must exist. If they don't,
|
544
550
|
an error must be raised. If `False`, missing nodes should be
|
545
551
|
returned as `None`. It only makes sense when passing a list of
|
546
552
|
`node_ids`, otherwise it will should ignored.
|
@@ -595,18 +601,14 @@ class Node:
|
|
595
601
|
a single node id.
|
596
602
|
|
597
603
|
Args:
|
598
|
-
info:
|
599
|
-
|
600
|
-
|
601
|
-
The id of the node to be retrieved
|
602
|
-
required:
|
603
|
-
if the node is required or not to exist. If not, then None
|
604
|
+
info: The strawberry execution info resolve the type name from.
|
605
|
+
node_id: The id of the node to be retrieved.
|
606
|
+
required: if the node is required or not to exist. If not, then None
|
604
607
|
should be returned if it doesn't exist. Otherwise an exception
|
605
608
|
should be raised.
|
606
609
|
|
607
610
|
Returns:
|
608
611
|
The resolved node or None if it was not found
|
609
|
-
|
610
612
|
"""
|
611
613
|
retval = cls.resolve_nodes(info=info, node_ids=[node_id], required=required)
|
612
614
|
|
@@ -629,7 +631,6 @@ class PageInfo:
|
|
629
631
|
When paginating backwards, the cursor to continue
|
630
632
|
end_cursor:
|
631
633
|
When paginating forwards, the cursor to continue
|
632
|
-
|
633
634
|
"""
|
634
635
|
|
635
636
|
has_next_page: bool = field(
|
@@ -655,15 +656,10 @@ class Edge(Generic[NodeType]):
|
|
655
656
|
A cursor for use in pagination
|
656
657
|
node:
|
657
658
|
The item at the end of the edge
|
658
|
-
|
659
659
|
"""
|
660
660
|
|
661
|
-
cursor: str = field(
|
662
|
-
|
663
|
-
)
|
664
|
-
node: NodeType = field(
|
665
|
-
description="The item at the end of the edge",
|
666
|
-
)
|
661
|
+
cursor: str = field(description="A cursor for use in pagination")
|
662
|
+
node: NodeType = field(description="The item at the end of the edge")
|
667
663
|
|
668
664
|
@classmethod
|
669
665
|
def resolve_edge(cls, node: NodeType, *, cursor: Any = None) -> Self:
|
@@ -682,11 +678,9 @@ class Connection(Generic[NodeType]):
|
|
682
678
|
|
683
679
|
"""
|
684
680
|
|
685
|
-
page_info: PageInfo = field(
|
686
|
-
description="Pagination data for this connection",
|
687
|
-
)
|
681
|
+
page_info: PageInfo = field(description="Pagination data for this connection")
|
688
682
|
edges: List[Edge[NodeType]] = field(
|
689
|
-
description="Contains the nodes in this connection"
|
683
|
+
description="Contains the nodes in this connection"
|
690
684
|
)
|
691
685
|
|
692
686
|
@classmethod
|
@@ -702,9 +696,11 @@ class Connection(Generic[NodeType]):
|
|
702
696
|
Args:
|
703
697
|
node:
|
704
698
|
The resolved node which should return an instance of this
|
705
|
-
connection's `NodeType
|
699
|
+
connection's `NodeType`.
|
706
700
|
info:
|
707
|
-
The strawberry execution info resolve the type name from
|
701
|
+
The strawberry execution info resolve the type name from.
|
702
|
+
**kwargs:
|
703
|
+
Additional arguments passed to the resolver.
|
708
704
|
|
709
705
|
"""
|
710
706
|
return node
|
@@ -727,18 +723,13 @@ class Connection(Generic[NodeType]):
|
|
727
723
|
on `first`/`last`/`before`/`after` arguments.
|
728
724
|
|
729
725
|
Args:
|
730
|
-
info:
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
Returns the items in the list that come after the specified cursor
|
738
|
-
first:
|
739
|
-
Returns the first n items from the list
|
740
|
-
last:
|
741
|
-
Returns the items in the list that come after the specified cursor
|
726
|
+
info: The strawberry execution info resolve the type name from.
|
727
|
+
nodes: An iterable/iteretor of nodes to paginate.
|
728
|
+
before: Returns the items in the list that come before the specified cursor.
|
729
|
+
after: Returns the items in the list that come after the specified cursor.
|
730
|
+
first: Returns the first n items from the list.
|
731
|
+
last: Returns the items in the list that come after the specified cursor.
|
732
|
+
kwargs: Additional arguments passed to the resolver.
|
742
733
|
|
743
734
|
Returns:
|
744
735
|
The resolved `Connection`
|
@@ -759,11 +750,9 @@ class ListConnection(Connection[NodeType]):
|
|
759
750
|
|
760
751
|
"""
|
761
752
|
|
762
|
-
page_info: PageInfo = field(
|
763
|
-
description="Pagination data for this connection",
|
764
|
-
)
|
753
|
+
page_info: PageInfo = field(description="Pagination data for this connection")
|
765
754
|
edges: List[Edge[NodeType]] = field(
|
766
|
-
description="Contains the nodes in this connection"
|
755
|
+
description="Contains the nodes in this connection"
|
767
756
|
)
|
768
757
|
|
769
758
|
@classmethod
|
@@ -783,25 +772,19 @@ class ListConnection(Connection[NodeType]):
|
|
783
772
|
This uses the described Relay Pagination algorithm_
|
784
773
|
|
785
774
|
Args:
|
786
|
-
info:
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
Returns the items in the list that come after the specified cursor
|
794
|
-
first:
|
795
|
-
Returns the first n items from the list
|
796
|
-
last:
|
797
|
-
Returns the items in the list that come after the specified cursor
|
775
|
+
info: The strawberry execution info resolve the type name from.
|
776
|
+
nodes: An iterable/iteretor of nodes to paginate.
|
777
|
+
before: Returns the items in the list that come before the specified cursor.
|
778
|
+
after: Returns the items in the list that come after the specified cursor.
|
779
|
+
first: Returns the first n items from the list.
|
780
|
+
last: Returns the items in the list that come after the specified cursor.
|
781
|
+
kwargs: Additional arguments passed to the resolver.
|
798
782
|
|
799
783
|
Returns:
|
800
784
|
The resolved `Connection`
|
801
785
|
|
802
786
|
.. _Relay Pagination algorithm:
|
803
787
|
https://relay.dev/graphql/connections.htm#sec-Pagination-algorithm
|
804
|
-
|
805
788
|
"""
|
806
789
|
slice_metadata = SliceMetadata.from_arguments(
|
807
790
|
info,
|
@@ -949,3 +932,20 @@ class ListConnection(Connection[NodeType]):
|
|
949
932
|
has_next_page=has_next_page,
|
950
933
|
),
|
951
934
|
)
|
935
|
+
|
936
|
+
|
937
|
+
__all__ = [
|
938
|
+
"GlobalID",
|
939
|
+
"GlobalIDValueError",
|
940
|
+
"Node",
|
941
|
+
"NodeID",
|
942
|
+
"NodeIDAnnotationError",
|
943
|
+
"NodeIDPrivate",
|
944
|
+
"NodeIterableType",
|
945
|
+
"NodeType",
|
946
|
+
"PREFIX",
|
947
|
+
"Connection",
|
948
|
+
"Edge",
|
949
|
+
"PageInfo",
|
950
|
+
"ListConnection",
|
951
|
+
]
|
strawberry/relay/utils.py
CHANGED
@@ -6,8 +6,8 @@ import sys
|
|
6
6
|
from typing import TYPE_CHECKING, Any, Tuple, Union
|
7
7
|
from typing_extensions import Self, assert_never
|
8
8
|
|
9
|
+
from strawberry.types.base import StrawberryObjectDefinition
|
9
10
|
from strawberry.types.nodes import InlineFragment, Selection
|
10
|
-
from strawberry.types.types import StrawberryObjectDefinition
|
11
11
|
|
12
12
|
if TYPE_CHECKING:
|
13
13
|
from strawberry.types.info import Info
|
@@ -86,6 +86,7 @@ def should_resolve_list_connection_edges(info: Info) -> bool:
|
|
86
86
|
|
87
87
|
def _check_selection(selection: Selection) -> bool:
|
88
88
|
"""Recursively inspect the selection to check if the user requested to resolve the `edges` field.
|
89
|
+
|
89
90
|
Args:
|
90
91
|
selection (Selection): The selection to check.
|
91
92
|
|
@@ -187,3 +188,11 @@ class SliceMetadata:
|
|
187
188
|
end=end,
|
188
189
|
expected=expected,
|
189
190
|
)
|
191
|
+
|
192
|
+
|
193
|
+
__all__ = [
|
194
|
+
"from_base64",
|
195
|
+
"to_base64",
|
196
|
+
"should_resolve_list_connection_edges",
|
197
|
+
"SliceMetadata",
|
198
|
+
]
|
strawberry/resolvers.py
CHANGED
strawberry/sanic/context.py
CHANGED
strawberry/sanic/utils.py
CHANGED
@@ -10,18 +10,17 @@ if TYPE_CHECKING:
|
|
10
10
|
|
11
11
|
|
12
12
|
def convert_request_to_files_dict(request: Request) -> Dict[str, Any]:
|
13
|
-
"""
|
14
|
-
|
13
|
+
"""Converts the request.files dictionary to a dictionary of BytesIO objects.
|
14
|
+
|
15
|
+
`request.files` has the following format, even if only a single file is uploaded:
|
15
16
|
|
17
|
+
```python
|
16
18
|
{
|
17
|
-
|
18
|
-
sanic.request.File(
|
19
|
-
type='text/plain',
|
20
|
-
body=b'strawberry',
|
21
|
-
name='textFile.txt'
|
22
|
-
)
|
19
|
+
"textFile": [
|
20
|
+
sanic.request.File(type="text/plain", body=b"strawberry", name="textFile.txt")
|
23
21
|
]
|
24
22
|
}
|
23
|
+
```
|
25
24
|
|
26
25
|
Note that the dictionary entries are lists.
|
27
26
|
"""
|
@@ -38,3 +37,6 @@ def convert_request_to_files_dict(request: Request) -> Dict[str, Any]:
|
|
38
37
|
files_dict[field_name] = BytesIO(file_list[0].body)
|
39
38
|
|
40
39
|
return files_dict
|
40
|
+
|
41
|
+
|
42
|
+
__all__ = ["convert_request_to_files_dict"]
|
strawberry/sanic/views.py
CHANGED
@@ -6,7 +6,6 @@ from typing import (
|
|
6
6
|
TYPE_CHECKING,
|
7
7
|
Any,
|
8
8
|
Dict,
|
9
|
-
List,
|
10
9
|
Mapping,
|
11
10
|
Optional,
|
12
11
|
Type,
|
@@ -43,12 +42,7 @@ class SanicHTTPRequestAdapter(AsyncHTTPRequestAdapter):
|
|
43
42
|
# the keys are the unique variable names and the values are lists
|
44
43
|
# of values for each variable name. To ensure consistency, we're
|
45
44
|
# enforcing the use of the first value in each list.
|
46
|
-
|
47
|
-
args = cast(
|
48
|
-
Dict[str, Optional[List[str]]],
|
49
|
-
self.request.get_args(keep_blank_values=True),
|
50
|
-
)
|
51
|
-
|
45
|
+
args = self.request.get_args(keep_blank_values=True)
|
52
46
|
return {k: args.get(k, None) for k in args}
|
53
47
|
|
54
48
|
@property
|
@@ -78,8 +72,7 @@ class GraphQLView(
|
|
78
72
|
AsyncBaseHTTPView[Request, HTTPResponse, TemporalResponse, Context, RootValue],
|
79
73
|
HTTPMethodView,
|
80
74
|
):
|
81
|
-
"""
|
82
|
-
Class based view to handle GraphQL HTTP Requests
|
75
|
+
"""Class based view to handle GraphQL HTTP Requests.
|
83
76
|
|
84
77
|
Args:
|
85
78
|
schema: strawberry.Schema
|
@@ -178,3 +171,6 @@ class GraphQLView(
|
|
178
171
|
return await self.run(request)
|
179
172
|
except HTTPException as e:
|
180
173
|
return HTTPResponse(e.reason, status=e.status_code)
|
174
|
+
|
175
|
+
|
176
|
+
__all__ = ["GraphQLView"]
|
strawberry/scalars.py
CHANGED
@@ -3,13 +3,14 @@ from __future__ import annotations
|
|
3
3
|
import base64
|
4
4
|
from typing import TYPE_CHECKING, Any, Dict, NewType, Union
|
5
5
|
|
6
|
-
from .
|
6
|
+
from strawberry.types.scalar import scalar
|
7
7
|
|
8
8
|
if TYPE_CHECKING:
|
9
|
-
from .
|
9
|
+
from strawberry.types.scalar import ScalarDefinition, ScalarWrapper
|
10
10
|
|
11
11
|
|
12
12
|
ID = NewType("ID", str)
|
13
|
+
"""Represent the GraphQL `ID` scalar type."""
|
13
14
|
|
14
15
|
JSON = scalar(
|
15
16
|
NewType("JSON", object), # mypy doesn't like `NewType("name", Any)`
|
@@ -62,3 +63,6 @@ def is_scalar(
|
|
62
63
|
return True
|
63
64
|
|
64
65
|
return hasattr(annotation, "_scalar_definition")
|
66
|
+
|
67
|
+
|
68
|
+
__all__ = ["ID", "JSON", "Base16", "Base32", "Base64", "is_scalar"]
|
strawberry/schema/base.py
CHANGED
@@ -10,14 +10,14 @@ from strawberry.utils.logging import StrawberryLogger
|
|
10
10
|
if TYPE_CHECKING:
|
11
11
|
from graphql import GraphQLError
|
12
12
|
|
13
|
-
from strawberry.custom_scalar import ScalarDefinition
|
14
13
|
from strawberry.directive import StrawberryDirective
|
15
|
-
from strawberry.enum import EnumDefinition
|
16
14
|
from strawberry.schema.schema_converter import GraphQLCoreConverter
|
17
15
|
from strawberry.types import ExecutionContext, ExecutionResult
|
16
|
+
from strawberry.types.base import StrawberryObjectDefinition
|
17
|
+
from strawberry.types.enum import EnumDefinition
|
18
18
|
from strawberry.types.graphql import OperationType
|
19
|
-
from strawberry.types.
|
20
|
-
from strawberry.union import StrawberryUnion
|
19
|
+
from strawberry.types.scalar import ScalarDefinition
|
20
|
+
from strawberry.types.union import StrawberryUnion
|
21
21
|
|
22
22
|
from .config import StrawberryConfig
|
23
23
|
|
@@ -113,3 +113,6 @@ class BaseSchema(Protocol):
|
|
113
113
|
) -> None:
|
114
114
|
for error in errors:
|
115
115
|
StrawberryLogger.error(error, execution_context)
|
116
|
+
|
117
|
+
|
118
|
+
__all__ = ["BaseSchema"]
|
strawberry/schema/compat.py
CHANGED
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
3
3
|
from typing import TYPE_CHECKING, Dict, Union
|
4
4
|
|
5
5
|
from strawberry.scalars import is_scalar as is_strawberry_scalar
|
6
|
-
from strawberry.
|
6
|
+
from strawberry.types.base import StrawberryType, has_object_definition
|
7
7
|
|
8
8
|
# TypeGuard is only available in typing_extensions => 3.10, we don't want
|
9
9
|
# to force updates to the typing_extensions package so we only use it when
|
@@ -12,7 +12,7 @@ from strawberry.type import StrawberryType, has_object_definition
|
|
12
12
|
if TYPE_CHECKING:
|
13
13
|
from typing_extensions import TypeGuard
|
14
14
|
|
15
|
-
from strawberry.
|
15
|
+
from strawberry.types.scalar import ScalarDefinition, ScalarWrapper
|
16
16
|
|
17
17
|
|
18
18
|
def is_input_type(type_: Union[StrawberryType, type]) -> TypeGuard[type]:
|
@@ -51,3 +51,13 @@ def is_graphql_generic(type_: Union[StrawberryType, type]) -> bool:
|
|
51
51
|
return type_.is_graphql_generic
|
52
52
|
|
53
53
|
return False
|
54
|
+
|
55
|
+
|
56
|
+
__all__ = [
|
57
|
+
"is_input_type",
|
58
|
+
"is_interface_type",
|
59
|
+
"is_scalar",
|
60
|
+
"is_enum",
|
61
|
+
"is_schema_directive",
|
62
|
+
"is_graphql_generic",
|
63
|
+
]
|
strawberry/schema/config.py
CHANGED
strawberry/schema/exceptions.py
CHANGED
strawberry/schema/execute.py
CHANGED
@@ -3,25 +3,25 @@ from __future__ import annotations
|
|
3
3
|
from typing import TYPE_CHECKING, List, Optional, Union, cast
|
4
4
|
from typing_extensions import Protocol
|
5
5
|
|
6
|
-
from strawberry.custom_scalar import ScalarDefinition
|
7
6
|
from strawberry.directive import StrawberryDirective
|
8
|
-
from strawberry.enum import EnumDefinition, EnumValue
|
9
|
-
from strawberry.lazy_type import LazyType
|
10
7
|
from strawberry.schema_directive import StrawberrySchemaDirective
|
11
|
-
from strawberry.
|
8
|
+
from strawberry.types.base import (
|
12
9
|
StrawberryList,
|
10
|
+
StrawberryObjectDefinition,
|
13
11
|
StrawberryOptional,
|
14
12
|
has_object_definition,
|
15
13
|
)
|
16
|
-
from strawberry.types.
|
17
|
-
from strawberry.
|
14
|
+
from strawberry.types.enum import EnumDefinition, EnumValue
|
15
|
+
from strawberry.types.lazy_type import LazyType
|
16
|
+
from strawberry.types.scalar import ScalarDefinition
|
17
|
+
from strawberry.types.union import StrawberryUnion
|
18
18
|
from strawberry.utils.str_converters import capitalize_first, to_camel_case
|
19
19
|
from strawberry.utils.typing import eval_type
|
20
20
|
|
21
21
|
if TYPE_CHECKING:
|
22
|
-
from strawberry.arguments import StrawberryArgument
|
23
|
-
from strawberry.
|
24
|
-
from strawberry.
|
22
|
+
from strawberry.types.arguments import StrawberryArgument
|
23
|
+
from strawberry.types.base import StrawberryType
|
24
|
+
from strawberry.types.field import StrawberryField
|
25
25
|
|
26
26
|
|
27
27
|
class HasGraphQLName(Protocol):
|
@@ -184,3 +184,6 @@ class NameConverter:
|
|
184
184
|
assert obj.python_name
|
185
185
|
|
186
186
|
return self.apply_naming_config(obj.python_name)
|
187
|
+
|
188
|
+
|
189
|
+
__all__ = ["NameConverter"]
|
strawberry/schema/schema.py
CHANGED
@@ -36,10 +36,9 @@ from strawberry.extensions.directives import (
|
|
36
36
|
)
|
37
37
|
from strawberry.schema.schema_converter import GraphQLCoreConverter
|
38
38
|
from strawberry.schema.types.scalar import DEFAULT_SCALAR_REGISTRY
|
39
|
-
from strawberry.type import has_object_definition
|
40
39
|
from strawberry.types import ExecutionContext
|
40
|
+
from strawberry.types.base import StrawberryObjectDefinition, has_object_definition
|
41
41
|
from strawberry.types.graphql import OperationType
|
42
|
-
from strawberry.types.types import StrawberryObjectDefinition
|
43
42
|
|
44
43
|
from ..printer import print_schema
|
45
44
|
from . import compat
|
@@ -51,14 +50,14 @@ if TYPE_CHECKING:
|
|
51
50
|
from graphql import ExecutionContext as GraphQLExecutionContext
|
52
51
|
from graphql import ExecutionResult as GraphQLExecutionResult
|
53
52
|
|
54
|
-
from strawberry.custom_scalar import ScalarDefinition, ScalarWrapper
|
55
53
|
from strawberry.directive import StrawberryDirective
|
56
|
-
from strawberry.enum import EnumDefinition
|
57
54
|
from strawberry.extensions import SchemaExtension
|
58
|
-
from strawberry.field import StrawberryField
|
59
|
-
from strawberry.type import StrawberryType
|
60
55
|
from strawberry.types import ExecutionResult
|
61
|
-
from strawberry.
|
56
|
+
from strawberry.types.base import StrawberryType
|
57
|
+
from strawberry.types.enum import EnumDefinition
|
58
|
+
from strawberry.types.field import StrawberryField
|
59
|
+
from strawberry.types.scalar import ScalarDefinition, ScalarWrapper
|
60
|
+
from strawberry.types.union import StrawberryUnion
|
62
61
|
|
63
62
|
DEFAULT_ALLOWED_OPERATION_TYPES = {
|
64
63
|
OperationType.QUERY,
|
@@ -81,10 +80,45 @@ class Schema(BaseSchema):
|
|
81
80
|
execution_context_class: Optional[Type[GraphQLExecutionContext]] = None,
|
82
81
|
config: Optional[StrawberryConfig] = None,
|
83
82
|
scalar_overrides: Optional[
|
84
|
-
Dict[object, Union[Type, ScalarWrapper, ScalarDefinition]]
|
83
|
+
Dict[object, Union[Type, ScalarWrapper, ScalarDefinition]],
|
85
84
|
] = None,
|
86
85
|
schema_directives: Iterable[object] = (),
|
87
86
|
) -> None:
|
87
|
+
"""Default Schema to be to be used in a Strawberry application.
|
88
|
+
|
89
|
+
A GraphQL Schema class used to define the structure and configuration
|
90
|
+
of GraphQL queries, mutations, and subscriptions.
|
91
|
+
|
92
|
+
This class allows the creation of a GraphQL schema by specifying the types
|
93
|
+
for queries, mutations, and subscriptions, along with various configuration
|
94
|
+
options such as directives, extensions, and scalar overrides.
|
95
|
+
|
96
|
+
Args:
|
97
|
+
query: The entry point for queries.
|
98
|
+
mutation: The entry point for mutations.
|
99
|
+
subscription: The entry point for subscriptions.
|
100
|
+
directives: A list of operation directives that clients can use.
|
101
|
+
The bult-in `@include` and `@skip` are included by default.
|
102
|
+
types: A list of additional types that will be included in the schema.
|
103
|
+
extensions: A list of Strawberry extensions.
|
104
|
+
execution_context_class: The execution context class.
|
105
|
+
config: The configuration for the schema.
|
106
|
+
scalar_overrides: A dictionary of overrides for scalars.
|
107
|
+
schema_directives: A list of schema directives for the schema.
|
108
|
+
|
109
|
+
Example:
|
110
|
+
```python
|
111
|
+
import strawberry
|
112
|
+
|
113
|
+
|
114
|
+
@strawberry.type
|
115
|
+
class Query:
|
116
|
+
name: str = "Patrick"
|
117
|
+
|
118
|
+
|
119
|
+
schema = strawberry.Schema(query=Query)
|
120
|
+
```
|
121
|
+
"""
|
88
122
|
self.query = query
|
89
123
|
self.mutation = mutation
|
90
124
|
self.subscription = subscription
|
@@ -395,7 +429,7 @@ class Schema(BaseSchema):
|
|
395
429
|
__str__ = as_str
|
396
430
|
|
397
431
|
def introspect(self) -> Dict[str, Any]:
|
398
|
-
"""Return the introspection query result for the current schema
|
432
|
+
"""Return the introspection query result for the current schema.
|
399
433
|
|
400
434
|
Raises:
|
401
435
|
ValueError: If the introspection query fails due to an invalid schema
|
@@ -405,3 +439,6 @@ class Schema(BaseSchema):
|
|
405
439
|
raise ValueError(f"Invalid Schema. Errors {introspection.errors!r}")
|
406
440
|
|
407
441
|
return introspection.data
|
442
|
+
|
443
|
+
|
444
|
+
__all__ = ["Schema"]
|