repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
strawberry
strawberry/relay/exceptions.py
.py
from __future__ import annotations from functools import cached_property from typing import TYPE_CHECKING, cast from strawberry.exceptions.exception import StrawberryException from strawberry.exceptions.utils.source_finder import SourceFinder if TYPE_CHECKING: from collections.abc import Callable from straw...
113
4,017
strawberry
strawberry/relay/__init__.py
.py
from .fields import ConnectionExtension, NodeExtension, connection, node from .types import ( Connection, Edge, GlobalID, GlobalIDValueError, ListConnection, Node, NodeID, NodeType, PageInfo, ) from .utils import from_base64, to_base64 __all__ = [ "Connection", "ConnectionEx...
32
553
strawberry
strawberry/subscriptions/__init__.py
.py
GRAPHQL_TRANSPORT_WS_PROTOCOL = "graphql-transport-ws" GRAPHQL_WS_PROTOCOL = "graphql-ws" GRAPHQL_SSE_PROTOCOL = "graphql-sse" MULTIPART_SUBSCRIPTION_PROTOCOL = "multipart-subscription" __all__ = [ "GRAPHQL_SSE_PROTOCOL", "GRAPHQL_TRANSPORT_WS_PROTOCOL", "GRAPHQL_WS_PROTOCOL", "MULTIPART_SUBSCRIPTION_...
13
333
strawberry
strawberry/subscriptions/protocols/graphql_transport_ws/types.py
.py
from typing import Literal, TypeAlias, TypedDict from typing_extensions import NotRequired from graphql import GraphQLFormattedError class ConnectionInitMessage(TypedDict): """Direction: Client -> Server.""" type: Literal["connection_init"] payload: NotRequired[dict[str, object] | None] class Connecti...
102
2,137
strawberry
strawberry/subscriptions/protocols/graphql_transport_ws/__init__.py
.py
# Code 4406 is "Subprotocol not acceptable" WS_4406_PROTOCOL_NOT_ACCEPTABLE = 4406 __all__ = [ "WS_4406_PROTOCOL_NOT_ACCEPTABLE", ]
8
138
strawberry
strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py
.py
from __future__ import annotations import asyncio import logging from contextlib import suppress from typing import ( TYPE_CHECKING, Any, Generic, cast, ) from graphql import GraphQLError, GraphQLSyntaxError from strawberry.exceptions import ConnectionRejectionError from strawberry.http.exceptions im...
429
15,627
strawberry
strawberry/subscriptions/protocols/graphql_ws/types.py
.py
from typing import Literal, TypeAlias, TypedDict from typing_extensions import NotRequired from graphql import GraphQLFormattedError class ConnectionInitMessage(TypedDict): type: Literal["connection_init"] payload: NotRequired[dict[str, object]] class StartMessagePayload(TypedDict): query: str vari...
99
2,021
strawberry
strawberry/subscriptions/protocols/graphql_ws/handlers.py
.py
from __future__ import annotations import asyncio from collections.abc import AsyncGenerator from contextlib import suppress from typing import ( TYPE_CHECKING, Any, Generic, cast, ) from strawberry.exceptions import ConnectionRejectionError from strawberry.http.exceptions import NonTextMessageReceive...
258
9,051
strawberry
strawberry/utils/str_converters.py
.py
import re # Adapted from this response in Stackoverflow # http://stackoverflow.com/a/19053800/1072990 def to_camel_case(snake_str: str) -> str: components = snake_str.split("_") # We capitalize the first letter of each component except the first one # with the 'capitalize' method and join them together. ...
30
897
strawberry
strawberry/utils/logging.py
.py
from __future__ import annotations import logging from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from typing import Final from graphql.error import GraphQLError from strawberry.types import ExecutionContext class StrawberryLogger: logger: Final[logging.Logger] = logging.getLogger("strawbe...
29
733
strawberry
strawberry/utils/await_maybe.py
.py
import inspect from collections.abc import AsyncIterator, Awaitable, Iterator from typing import TypeAlias, TypeVar T = TypeVar("T") AwaitableOrValue: TypeAlias = Awaitable[T] | T AsyncIteratorOrIterator: TypeAlias = AsyncIterator[T] | Iterator[T] async def await_maybe(value: AwaitableOrValue[T]) -> T: if inspe...
19
463
strawberry
strawberry/utils/deprecations.py
.py
from __future__ import annotations import warnings from typing import Any class DeprecatedDescriptor: """A descriptor that emits a deprecation warning when accessed. Used to create deprecated attribute aliases that point to new attributes. Example: >>> @strawberry.type ... class MyType:...
42
1,201
strawberry
strawberry/utils/__init__.py
.py
from graphql.version import VersionInfo, version_info IS_GQL_33 = version_info >= VersionInfo.from_str("3.3.0a0") IS_GQL_32 = not IS_GQL_33 if IS_GQL_33 and version_info < VersionInfo.from_str("3.3.0a12"): raise ImportError( f"graphql-core {version_info} is not supported. " "Please upgrade to grap...
11
349
strawberry
strawberry/utils/inspect.py
.py
import asyncio import inspect from collections.abc import Callable from functools import lru_cache from typing import ( Any, Generic, Protocol, TypeVar, get_args, get_origin, ) import strawberry def in_async_context() -> bool: # Based on the way django checks if there's an event loop in t...
134
3,408
strawberry
strawberry/utils/aio.py
.py
import sys from collections.abc import ( AsyncGenerator, AsyncIterable, AsyncIterator, Awaitable, Callable, ) from contextlib import asynccontextmanager, suppress from typing import ( Any, TypeVar, cast, ) _T = TypeVar("_T") _R = TypeVar("_R") @asynccontextmanager async def aclosing(t...
95
2,201
strawberry
strawberry/utils/operation.py
.py
from __future__ import annotations from typing import TYPE_CHECKING from graphql.language import OperationDefinitionNode from strawberry.types.graphql import OperationType if TYPE_CHECKING: from graphql.language import DocumentNode def get_first_operation( graphql_document: DocumentNode, ) -> OperationDef...
45
1,215
strawberry
strawberry/utils/importer.py
.py
import importlib def import_module_symbol( selector: str, default_symbol_name: str | None = None ) -> object: if ":" in selector: module_name, symbol_name = selector.split(":", 1) elif default_symbol_name: module_name, symbol_name = selector, default_symbol_name else: raise Val...
24
598
strawberry
strawberry/utils/typing.py
.py
import ast import dataclasses import sys import typing from collections.abc import AsyncGenerator from functools import lru_cache from types import UnionType from typing import ( # type: ignore Annotated, Any, ClassVar, ForwardRef, Generic, TypeGuard, TypeVar, Union, _eval_type, ...
390
13,207
strawberry
strawberry/utils/locate_definition.py
.py
from __future__ import annotations from typing import TYPE_CHECKING from strawberry.exceptions.utils.source_finder import SourceFinder from strawberry.types.scalar import ScalarDefinition from strawberry.types.union import StrawberryUnion from strawberry.utils.str_converters import to_snake_case if TYPE_CHECKING: ...
47
1,429
strawberry
strawberry/cli/app.py
.py
import typer app = typer.Typer(no_args_is_help=True)
4
54
strawberry
strawberry/cli/__init__.py
.py
try: from .app import app from .commands.codegen import codegen as codegen from .commands.dev import dev as dev from .commands.export_schema import export_schema as export_schema from .commands.locate_definition import ( locate_definition as locate_definition, ) from .commands.schema...
21
653
strawberry
strawberry/cli/dev_server.py
.py
import os from typing import Any from starlette.applications import Starlette from starlette.middleware.cors import CORSMiddleware from starlette.routing import BaseRoute, Route, WebSocketRoute from strawberry import Schema from strawberry.asgi import GraphQL from strawberry.cli.constants import DEV_SERVER_SCHEMA_ENV...
29
952
strawberry
strawberry/cli/utils/__init__.py
.py
import sys import rich import typer from strawberry import Schema from strawberry.utils.importer import import_module_symbol def load_schema(schema: str, app_dir: str) -> Schema: sys.path.insert(0, app_dir) try: schema_symbol = import_module_symbol(schema, default_symbol_name="schema") except (...
35
987
strawberry
strawberry/cli/commands/codegen.py
.py
from __future__ import annotations import functools import importlib import inspect from pathlib import Path # noqa: TC003 from typing import cast import rich import typer from strawberry.cli.app import app from strawberry.cli.utils import load_schema from strawberry.codegen import ConsolePlugin, QueryCodegen, Quer...
144
3,788
strawberry
strawberry/cli/commands/export_schema.py
.py
from pathlib import Path import typer from strawberry.cli.app import app from strawberry.cli.utils import load_schema from strawberry.printer import print_schema @app.command(help="Exports the schema") def export_schema( schema: str, app_dir: str = typer.Option( ".", "--app-dir", sho...
39
1,049
strawberry
strawberry/cli/commands/schema_codegen.py
.py
from pathlib import Path import typer from strawberry.cli.app import app from strawberry.schema_codegen import codegen @app.command(help="Generate code from a query") def schema_codegen( schema: Path = typer.Argument(exists=True), output: Path | None = typer.Option( None, "-o", "--ou...
32
718
strawberry
strawberry/cli/commands/locate_definition.py
.py
import sys import typer from rich.console import Console from strawberry.cli.app import app from strawberry.cli.utils import load_schema from strawberry.utils.locate_definition import ( locate_definition as locate_definition_util, ) err_console = Console(stderr=True) @app.command(help="Locate a definition in t...
37
1,001
strawberry
strawberry/cli/commands/dev.py
.py
import os import sys from enum import Enum from typing import Annotated import rich import typer from strawberry.cli.app import app from strawberry.cli.constants import DEV_SERVER_SCHEMA_ENV_VAR_KEY from strawberry.cli.utils import load_schema class LogLevel(str, Enum): critical = "critical" error = "error"...
73
1,968
strawberry
strawberry/cli/commands/upgrade/__init__.py
.py
from __future__ import annotations import glob import pathlib # noqa: TC003 import sys import rich import typer from libcst.codemod import CodemodContext from strawberry.cli.app import app from strawberry.codemods.annotated_unions import ConvertUnionToAnnotatedUnion from strawberry.codemods.maybe_optional import Co...
94
2,932
strawberry
strawberry/cli/commands/upgrade/_run_codemod.py
.py
from __future__ import annotations import contextlib import os from importlib.metadata import version from multiprocessing import Pool, cpu_count from typing import TYPE_CHECKING, Any, TypeAlias from libcst.codemod._cli import ExecutionConfig, ExecutionResult, _execute_transform from rich.progress import Progress fr...
81
2,177
strawberry
strawberry/cli/commands/upgrade/_fake_progress.py
.py
from typing import Any from typing_extensions import Self from rich.progress import TaskID class FakeProgress: """A fake progress bar that does nothing. This is used when the user has only one file to process. """ def advance(self, task_id: TaskID) -> None: pass def add_task(self, *arg...
24
509
strawberry
strawberry/test/__init__.py
.py
from .client import BaseGraphQLTestClient, Body, Response __all__ = ["BaseGraphQLTestClient", "Body", "Response"]
4
115
strawberry
strawberry/test/client.py
.py
from __future__ import annotations import json from abc import ABC, abstractmethod from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Literal from typing_extensions import TypedDict if TYPE_CHECKING: from collections.abc import Coroutine from graphql import GraphQLFormattedError @data...
187
5,939
strawberry
strawberry/flask/views.py
.py
from __future__ import annotations from typing import ( TYPE_CHECKING, ClassVar, TypeGuard, ) from cross_web import ( AsyncFlaskHTTPRequestAdapter, FlaskHTTPRequestAdapter, HTTPException, ) from flask import Request, Response, render_template_string, request from flask.views import View from ...
144
4,534
strawberry
strawberry/federation/types.py
.py
from enum import Enum from typing import NewType from strawberry.types.enum import enum FieldSet = NewType("FieldSet", str) """Represents a selection set for federation @requires, @provides, @key directives.""" LinkImport = NewType("LinkImport", object) """Represents an import for the @link directive.""" @enum(nam...
20
472
strawberry
strawberry/federation/mutation.py
.py
from .field import field mutation = field __all__ = ["mutation"]
6
67
strawberry
strawberry/federation/enum.py
.py
from __future__ import annotations from typing import ( TYPE_CHECKING, Any, overload, ) from strawberry.types.enum import _process_enum from strawberry.types.enum import enum_value as base_enum_value if TYPE_CHECKING: from collections.abc import Callable, Iterable from strawberry.enum import Enu...
126
3,085
strawberry
strawberry/federation/field.py
.py
from __future__ import annotations import dataclasses from typing import ( TYPE_CHECKING, Any, TypeVar, overload, ) from typing_extensions import Unpack from strawberry.types.field import field as base_field from .params import FederationFieldParams, process_federation_field_directives if TYPE_CHECK...
133
4,309
strawberry
strawberry/federation/argument.py
.py
from collections.abc import Iterable from typing import Any from strawberry.types.arguments import StrawberryArgumentAnnotation def argument( # noqa: PLR0917 description: str | None = None, name: str | None = None, deprecation_reason: str | None = None, directives: Iterable[object] = (), inacces...
36
932
strawberry
strawberry/federation/schema_directives.py
.py
from dataclasses import dataclass from typing import ClassVar from strawberry import directive_field from strawberry.schema_directive import Location, schema_directive from strawberry.types.unset import UNSET from .types import ( FieldSet, LinkImport, LinkPurpose, ) from .versions import FederationVersion...
333
9,421
strawberry
strawberry/federation/object_type.py
.py
import builtins from collections.abc import Callable, Iterable, Sequence from typing import ( TypeVar, overload, ) from typing_extensions import Unpack, dataclass_transform from strawberry.types.field import StrawberryField from strawberry.types.field import field as base_field from strawberry.types.object_typ...
264
6,097
strawberry
strawberry/federation/__init__.py
.py
from .argument import argument from .enum import enum, enum_value from .field import field from .mutation import mutation from .object_type import input, interface, interface_object, type # noqa: A004 from .scalar import scalar from .schema import Schema from .schema_directive import schema_directive from .union impor...
26
549
strawberry
strawberry/federation/union.py
.py
from collections.abc import Iterable from strawberry.types.union import StrawberryUnion from strawberry.types.union import union as base_union def union( name: str, *, description: str | None = None, directives: Iterable[object] = (), inaccessible: bool = False, tags: Iterable[str] | None = (...
58
1,424
strawberry
strawberry/federation/schema_directive.py
.py
import dataclasses from collections.abc import Callable from typing import TypeVar from typing_extensions import dataclass_transform from strawberry.directive import directive_field from strawberry.schema_directive import Location, StrawberrySchemaDirective from strawberry.types.field import StrawberryField, field fro...
63
1,755
strawberry
strawberry/federation/params.py
.py
from __future__ import annotations from typing import TYPE_CHECKING from typing_extensions import TypedDict from strawberry.types.unset import UNSET from .types import FieldSet if TYPE_CHECKING: from collections.abc import Iterable, Sequence from .schema_directives import Key, Override class FederationFi...
172
4,182
strawberry
strawberry/federation/schema.py
.py
from collections import defaultdict from collections.abc import Callable, Iterable, Mapping from functools import cached_property from itertools import chain from typing import ( TYPE_CHECKING, Any, Literal, NewType, Optional, Union, cast, ) from strawberry.annotation import StrawberryAnnot...
444
15,686
strawberry
strawberry/federation/scalar.py
.py
from collections.abc import Callable, Iterable from typing import ( Any, NewType, TypeVar, overload, ) from graphql import ( GraphQLScalarLiteralParser, GraphQLScalarSerializer, GraphQLScalarValueParser, ) from strawberry.types.scalar import ScalarWrapper, _process_scalar _T = TypeVar("_T...
169
4,677
strawberry
strawberry/federation/versions.py
.py
# Type alias for federation version as (major, minor) tuple FederationVersion = tuple[int, int] # Mapping from version string (e.g., "2.5") to version tuple (e.g., (2, 5)) FEDERATION_VERSIONS: dict[str, FederationVersion] = { "2.0": (2, 0), "2.1": (2, 1), "2.2": (2, 2), "2.3": (2, 3), "2.4": (2, 4)...
30
807
strawberry
strawberry/schema_codegen/__init__.py
.py
from __future__ import annotations import dataclasses import keyword from collections import defaultdict from graphlib import TopologicalSorter from typing import TYPE_CHECKING, TypeAlias from typing_extensions import Protocol import libcst as cst from graphql import ( EnumTypeDefinitionNode, EnumValueDefinit...
948
28,675
strawberry
strawberry/field_extensions/input_mutation.py
.py
from __future__ import annotations from typing import Any import strawberry from strawberry.annotation import StrawberryAnnotation from strawberry.extensions.field_extension import FieldExtension from strawberry.types.arguments import StrawberryArgument from strawberry.types.field import StrawberryField from strawber...
62
2,264
strawberry
strawberry/field_extensions/__init__.py
.py
from .input_mutation import InputMutationExtension __all__ = [ "InputMutationExtension", ]
6
96
strawberry
strawberry/types/mutation.py
.py
from __future__ import annotations import dataclasses from typing import ( TYPE_CHECKING, Any, Literal, overload, ) from strawberry.types.field import ( _RESOLVER_TYPE, _RESOLVER_TYPE_ASYNC, _RESOLVER_TYPE_SYNC, StrawberryField, T, field, ) if TYPE_CHECKING: from collectio...
346
11,549
strawberry
strawberry/types/enum.py
.py
import dataclasses from collections.abc import Callable, Iterable, Mapping from enum import EnumMeta from typing import Any, Literal, TypeGuard, TypeVar, overload from strawberry.exceptions import ObjectIsNotAnEnumError from strawberry.types.base import ( StrawberryType, WithStrawberryDefinition, has_straw...
289
7,894
strawberry
strawberry/types/field.py
.py
from __future__ import annotations import contextlib import copy import dataclasses import sys from collections.abc import Awaitable, Callable, Coroutine, Mapping, Sequence from functools import cached_property from typing import ( TYPE_CHECKING, Any, NoReturn, TypeAlias, TypeVar, Union, ov...
578
20,441
strawberry
strawberry/types/arguments.py
.py
from __future__ import annotations import inspect from typing import ( TYPE_CHECKING, Annotated, Any, cast, get_args, get_origin, ) from strawberry.annotation import StrawberryAnnotation from strawberry.exceptions import MultipleStrawberryArgumentsError, UnsupportedTypeError from strawberry.sc...
358
11,752
strawberry
strawberry/types/nodes.py
.py
"""Abstraction layer for graphql-core field nodes. Call `convert_sections` on a list of GraphQL `FieldNode`s, such as in `info.field_nodes`. If a node has only one useful value, it's value is inlined. If a list of nodes have unique names, it's transformed into a mapping. Note Python dicts maintain ordering (for all ...
160
5,161
strawberry
strawberry/types/maybe.py
.py
import re import typing from typing import TYPE_CHECKING, Annotated, Any, Generic, TypeAlias, TypeVar T = TypeVar("T") class Some(Generic[T]): """A special value that can be used to represent an unset value in a field or argument. Similar to `undefined` in JavaScript, this value can be used to differentiate...
60
1,610
strawberry
strawberry/types/cast.py
.py
from __future__ import annotations from typing import Any, TypeVar, overload _T = TypeVar("_T", bound=object) TYPE_CAST_ATTRIBUTE = "__as_strawberry_type__" @overload def cast(type_: type, obj: None) -> None: ... @overload def cast(type_: type, obj: _T) -> _T: ... def cast(type_: type, obj: _T | None) -> _T | ...
36
916
strawberry
strawberry/types/info.py
.py
from __future__ import annotations import dataclasses from functools import cached_property from typing import ( TYPE_CHECKING, Any, Generic, ) from typing_extensions import TypeVar from .nodes import convert_selections if TYPE_CHECKING: from graphql import GraphQLResolveInfo, OperationDefinitionNode...
156
4,607
strawberry
strawberry/types/lazy_type.py
.py
import importlib import importlib.util import sys from dataclasses import dataclass from pathlib import Path from typing import ( Any, ForwardRef, Generic, TypeVar, Union, cast, ) TypeName = TypeVar("TypeName") Module = TypeVar("Module") Other = TypeVar("Other") @dataclass(frozen=True) class ...
140
4,558
strawberry
strawberry/types/object_type.py
.py
import builtins import copy import dataclasses import inspect import types from collections.abc import Callable, Sequence from typing import ( Any, TypeVar, cast, overload, ) from typing_extensions import dataclass_transform, get_annotations from strawberry.exceptions import ( InvalidSuperclassInte...
556
18,258
strawberry
strawberry/types/__init__.py
.py
from .base import get_object_definition, has_object_definition from .execution import ( ExecutionContext, ExecutionResult, StreamExecutionResult, SubscriptionExecutionResult, ) from .info import Info __all__ = [ "ExecutionContext", "ExecutionResult", "Info", "StreamExecutionResult", ...
19
412
strawberry
strawberry/types/union.py
.py
from __future__ import annotations import itertools import sys from itertools import chain from typing import ( TYPE_CHECKING, Annotated, Any, NoReturn, TypeVar, cast, get_origin, ) from graphql import GraphQLNamedType, GraphQLUnionType from strawberry.annotation import StrawberryAnnotati...
298
9,395
strawberry
strawberry/types/graphql.py
.py
from __future__ import annotations import enum from typing import TYPE_CHECKING if TYPE_CHECKING: from strawberry.http.types import HTTPMethod class OperationType(enum.Enum): QUERY = "query" MUTATION = "mutation" SUBSCRIPTION = "subscription" @staticmethod def from_http(method: HTTPMethod) ...
35
867
strawberry
strawberry/types/unset.py
.py
from typing import Any from typing_extensions import Self class UnsetType: __instance: Self | None = None def __new__(cls: type[Self]) -> Self: if cls.__instance is None: ret = super().__new__(cls) cls.__instance = ret return ret return cls.__instance ...
50
1,128
strawberry
strawberry/types/private.py
.py
from typing import Annotated, TypeVar from strawberry.utils.typing import type_has_annotation class StrawberryPrivate: ... T = TypeVar("T") Private = Annotated[T, StrawberryPrivate()] """Represents a field that won't be exposed in the GraphQL schema. Example: ```python import strawberry @strawberry.type class...
33
518
strawberry
strawberry/types/execution.py
.py
from __future__ import annotations import dataclasses from typing import ( TYPE_CHECKING, Any, TypeAlias, runtime_checkable, ) from typing_extensions import NotRequired, Protocol, TypedDict from graphql import specified_rules try: from graphql.execution import ( # type: ignore[attr-defined] ...
150
4,631
strawberry
strawberry/types/type_resolver.py
.py
from __future__ import annotations import copy import dataclasses import sys from typing import Annotated, Any, get_args, get_origin from strawberry.annotation import StrawberryAnnotation from strawberry.exceptions import ( FieldWithResolverAndDefaultFactoryError, FieldWithResolverAndDefaultValueError, Mu...
235
8,738
strawberry
strawberry/types/auto.py
.py
from __future__ import annotations from typing import Annotated, Any, cast, get_args, get_origin from strawberry.annotation import StrawberryAnnotation from strawberry.types.base import StrawberryType class StrawberryAutoMeta(type): """Metaclass for StrawberryAuto. This is used to make sure StrawberryAuto ...
97
2,954
strawberry
strawberry/types/scalar.py
.py
from __future__ import annotations import sys from dataclasses import dataclass from typing import ( TYPE_CHECKING, Any, NewType, Optional, TypeVar, overload, ) from strawberry.exceptions import InvalidUnionTypeError from strawberry.types.base import StrawberryType from strawberry.utils.str_co...
304
9,037
strawberry
strawberry/types/base.py
.py
from __future__ import annotations import dataclasses from abc import ABC, abstractmethod from typing import ( TYPE_CHECKING, Annotated, Any, ClassVar, Generic, Literal, TypeGuard, TypeVar, get_origin, overload, ) from typing_extensions import Protocol, Self from strawberry.uti...
494
15,564
strawberry
strawberry/types/fields/resolver.py
.py
from __future__ import annotations as _ import asyncio import inspect import sys from functools import cached_property from inspect import isasyncgenfunction from typing import ( TYPE_CHECKING, Annotated, Any, ForwardRef, Generic, NamedTuple, TypeVar, cast, get_origin, ) from typing...
434
15,597
strawberry
strawberry/ext/mypy_plugin.py
.py
from __future__ import annotations import re import warnings from decimal import Decimal from typing import ( TYPE_CHECKING, Any, cast, ) from mypy.nodes import ( ARG_OPT, ARG_POS, ARG_STAR2, MDEF, Argument, Block, CallExpr, CastExpr, FuncDef, IndexExpr, MemberE...
276
8,890
strawberry
strawberry/ext/dataclasses/dataclasses.py
.py
# # This code is licensed under the Python Software Foundation License Version 2 # from dataclasses import ( # type: ignore _FIELD_INITVAR, _HAS_DEFAULT_FACTORY, _POST_INIT_NAME, MISSING, _create_fn, _field_init, _init_param, ) from typing import Any def dataclass_init_fn( fields: li...
79
2,287
strawberry
strawberry/channels/__init__.py
.py
from .handlers.base import ChannelsConsumer from .handlers.http_handler import ( ChannelsRequest, GraphQLHTTPConsumer, SyncGraphQLHTTPConsumer, ) from .handlers.ws_handler import GraphQLWSConsumer from .router import GraphQLProtocolTypeRouter __all__ = [ "ChannelsConsumer", "ChannelsRequest", "...
18
433
strawberry
strawberry/channels/router.py
.py
"""GraphQLWebSocketRouter. This is a simple router class that might be better placed as part of Channels itself. It's a simple "SubProtocolRouter" that selects the websocket subprotocol based on preferences and client support. Then it hands off to the appropriate consumer. """ from __future__ import annotations from...
91
2,678
strawberry
strawberry/channels/testing.py
.py
from __future__ import annotations import uuid from typing import ( TYPE_CHECKING, Any, ) from channels.testing.websocket import WebsocketCommunicator from graphql import GraphQLError, GraphQLFormattedError from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL from strawberr...
177
6,512
strawberry
strawberry/channels/handlers/ws_handler.py
.py
from __future__ import annotations import asyncio import datetime import json from typing import ( TYPE_CHECKING, TypedDict, TypeGuard, ) from strawberry.http.async_base_view import AsyncBaseHTTPView, AsyncWebSocketAdapter from strawberry.http.exceptions import NonJsonMessageReceived, NonTextMessageReceiv...
195
6,276
strawberry
strawberry/channels/handlers/base.py
.py
import asyncio import contextlib from collections import defaultdict from collections.abc import AsyncGenerator, Awaitable, Callable, Sequence from typing import ( Any, Literal, ) from typing_extensions import Protocol, TypedDict from weakref import WeakSet from channels.consumer import AsyncConsumer from chan...
159
5,717
strawberry
strawberry/channels/handlers/http_handler.py
.py
from __future__ import annotations import dataclasses import json from functools import cached_property from io import BytesIO from typing import TYPE_CHECKING, Any, TypeGuard from typing_extensions import assert_never from urllib.parse import parse_qs from channels.db import database_sync_to_async from channels.gene...
411
12,991
strawberry
strawberry/schema/schema_converter.py
.py
from __future__ import annotations import dataclasses import inspect import sys import typing from functools import partial, reduce from typing import ( TYPE_CHECKING, Annotated, Any, Generic, TypeVar, cast, ) from typing_extensions import Protocol from graphql import ( GraphQLAbstractType...
1,341
50,281
strawberry
strawberry/schema/exceptions.py
.py
from strawberry.types.graphql import OperationType class CannotGetOperationTypeError(Exception): """Internal error raised when we cannot get the operation type from a GraphQL document.""" def __init__(self, operation_name: str | None) -> None: self.operation_name = operation_name def as_http_err...
36
1,105
strawberry
strawberry/schema/exception_handlers.py
.py
from __future__ import annotations import types import typing from collections.abc import Iterable from typing import ( TYPE_CHECKING, Any, Protocol, Union, get_args, get_origin, runtime_checkable, ) from typing_extensions import TypeVar if TYPE_CHECKING: from collections.abc import Aw...
174
6,153
strawberry
strawberry/schema/_graphql_core.py
.py
from typing import Any, TypeAlias, Union try: from graphql.execution import ExecutionContext as GraphQLExecutionContext _execution_context_class_arg = "execution_context_class" except ImportError: from graphql.execution import ( # type: ignore[attr-defined,no-redef] Executor as GraphQLExecutionCo...
99
3,489
strawberry
strawberry/schema/schema.py
.py
from __future__ import annotations import asyncio import warnings from asyncio import ensure_future from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Iterable from functools import lru_cache from inspect import isawaitable from typing import ( TYPE_CHECKING, Any, NamedTuple, ...
1,257
50,196
strawberry
strawberry/schema/compat.py
.py
from __future__ import annotations from typing import TYPE_CHECKING from strawberry.scalars import is_scalar as is_strawberry_scalar from strawberry.types.base import ( StrawberryType, has_object_definition, ) # TypeGuard is only available in typing_extensions => 3.10, we don't want # to force updates to the...
63
1,701
strawberry
strawberry/schema/name_converter.py
.py
from __future__ import annotations from typing import TYPE_CHECKING, cast from typing_extensions import Protocol from strawberry.directive import StrawberryDirective from strawberry.schema_directive import StrawberrySchemaDirective from strawberry.types.base import ( StrawberryList, StrawberryObjectDefinition...
201
6,909
strawberry
strawberry/schema/config.py
.py
from __future__ import annotations from dataclasses import InitVar, dataclass, field from typing import TYPE_CHECKING, Any, TypedDict from strawberry.types.info import Info from .name_converter import NameConverter if TYPE_CHECKING: from collections.abc import Callable, Mapping from strawberry.types.scalar...
63
2,330
strawberry
strawberry/schema/base.py
.py
from __future__ import annotations from abc import abstractmethod from typing import TYPE_CHECKING, Any from typing_extensions import Protocol from strawberry.utils.logging import StrawberryLogger if TYPE_CHECKING: from collections.abc import Iterable from graphql import GraphQLError from strawberry.di...
143
4,621
strawberry
strawberry/schema/validation_rules/maybe_null.py
.py
from typing import Any from graphql import ( ArgumentNode, GraphQLError, GraphQLNamedType, ObjectValueNode, ValidationContext, ValidationRule, get_named_type, ) from strawberry.types.base import StrawberryMaybe, StrawberryOptional from strawberry.utils.str_converters import to_camel_case ...
137
5,624
strawberry
strawberry/schema/validation_rules/one_of.py
.py
from typing import Any from graphql import ( ExecutableDefinitionNode, GraphQLError, GraphQLNamedType, ObjectValueNode, ValidationContext, ValidationRule, VariableDefinitionNode, get_named_type, ) class OneOfInputValidationRule(ValidationRule): def __init__(self, validation_contex...
84
2,629
strawberry
strawberry/schema/types/concrete_type.py
.py
from __future__ import annotations import dataclasses from typing import TYPE_CHECKING, TypeAlias from graphql import GraphQLField, GraphQLInputField, GraphQLType if TYPE_CHECKING: from strawberry.types.base import StrawberryObjectDefinition from strawberry.types.enum import StrawberryEnumDefinition from...
32
801
strawberry
strawberry/schema/types/__init__.py
.py
from .concrete_type import ConcreteType __all__ = ["ConcreteType"]
4
68
strawberry
strawberry/schema/types/base_scalars.py
.py
import datetime import decimal import uuid from collections.abc import Callable from operator import methodcaller import dateutil.parser from graphql import GraphQLError from strawberry.types.scalar import ScalarDefinition def wrap_parser( parser: Callable[[str], object], type_: str, exceptions: tuple[t...
131
3,520
strawberry
strawberry/schema/types/scalar.py
.py
import base64 as base64_lib import datetime import decimal from uuid import UUID from graphql import ( GraphQLBoolean, GraphQLFloat, GraphQLID, GraphQLInt, GraphQLScalarType, GraphQLString, ) from strawberry.file_uploads.scalars import Upload, UploadDefinition from strawberry.scalars import ID...
108
3,884
strawberry
tests/test_dataloaders.py
.py
import asyncio from asyncio.futures import Future from collections.abc import Awaitable, Callable from typing import Any, Optional, cast import pytest from pytest_mock import MockerFixture from strawberry.dataloader import AbstractCache, DataLoader from strawberry.exceptions import WrongNumberOfResultsReturned IDXTy...
655
18,492
strawberry
tests/test_type.py
.py
import dataclasses from typing import Optional from typing_extensions import assert_type import pytest import strawberry from strawberry.types.base import StrawberryObjectDefinition, get_object_definition def test_get_object_definition(): @strawberry.type class Fruit: name: str obj_definition =...
50
1,206
strawberry
tests/test_repr.py
.py
from enum import Enum import strawberry def test_repr_type(): @strawberry.type class MyType: s: str i: int b: bool f: float id: strawberry.ID assert ( repr(MyType(s="a", i=1, b=True, f=3.2, id="123")) == "test_repr_type.<locals>.MyType(s='a', i=1, ...
29
506
strawberry
tests/c.py
.py
from __future__ import annotations import strawberry @strawberry.type class C: id: strawberry.ID
9
104
strawberry
tests/test_info.py
.py
from typing import Any import pytest import strawberry def test_can_use_info_with_two_arguments(): CustomInfo = strawberry.Info[int, str] assert CustomInfo.__args__ == (int, str) def test_can_use_info_with_one_argument(): CustomInfo = strawberry.Info[int] assert CustomInfo.__args__ == (int, Any)...
26
579