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 | tests/typecheckers/test_maybe.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
@strawberry.type
class SomeType:
... | 79 | 1,875 |
strawberry | tests/typecheckers/test_private.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
@strawberry.type
class User:
name... | 103 | 2,602 |
strawberry | tests/typecheckers/test_fields_resolver_async.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
async def get_user_age() -> int:
re... | 121 | 3,365 |
strawberry | tests/typecheckers/test_directives.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
from strawberry.directive import Direct... | 61 | 1,435 |
strawberry | tests/typecheckers/test_federation_fields.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
def some_resolver(root: "User") -> str:... | 181 | 5,424 |
strawberry | tests/typecheckers/test_info.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
def test_with_params():
CODE = """
import strawberry
def exampl... | 160 | 4,093 |
strawberry | tests/typecheckers/test_union.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
from typing_extensions import TypeAlias... | 83 | 1,952 |
strawberry | tests/typecheckers/test_federation.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
def get_user_age() -> int:
return ... | 355 | 9,555 |
strawberry | tests/typecheckers/test_params.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
@strawberry.type(name="User")
class Us... | 95 | 2,439 |
strawberry | tests/typecheckers/test_pydantic.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy]
MYPY_PLUGINS = ["pydantic.mypy", "strawberry.ext.mypy_plugin"]
CODE = """
import pydantic
impo... | 81 | 2,174 |
strawberry | tests/typecheckers/test_federation_params.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
@strawberry.federation.type(name="Use... | 63 | 1,490 |
strawberry | tests/typecheckers/test_relay.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
from typing import (
Any,
AsyncIterator,
Asyn... | 498 | 16,228 |
strawberry | tests/typecheckers/test_interface.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
@strawberry.interface
class Node:
... | 101 | 2,124 |
strawberry | tests/typecheckers/test_auto.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
@strawberry.type
class SomeType:
... | 83 | 2,093 |
strawberry | tests/typecheckers/test_scalars.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
from strawberry.scalars import ID, JSON... | 367 | 9,458 |
strawberry | tests/typecheckers/test_fields.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
@strawberry.type
class User:
name... | 102 | 2,672 |
strawberry | tests/typecheckers/test_fields_keyword.py | .py | from inline_snapshot import snapshot
from .utils.marks import requires_mypy, requires_pyright, requires_ty, skip_on_windows
from .utils.typecheck import Result, typecheck
pytestmark = [skip_on_windows, requires_pyright, requires_mypy, requires_ty]
CODE = """
import strawberry
@strawberry.type
class User:
name... | 81 | 1,975 |
strawberry | tests/typecheckers/utils/marks.py | .py | import shutil
import sys
import pytest
def pyright_exist() -> bool:
return shutil.which("pyright") is not None
def mypy_exists() -> bool:
return shutil.which("mypy") is not None
def ty_exists() -> bool:
return shutil.which("ty") is not None
skip_on_windows = pytest.mark.skipif(
sys.platform == ... | 38 | 699 |
strawberry | tests/typecheckers/utils/pyright.py | .py | from __future__ import annotations
import json
import os
import subprocess
import tempfile
from typing import TypedDict, cast
from .result import Result, ResultType
class PyrightCLIResult(TypedDict):
version: str
time: str
generalDiagnostics: list[GeneralDiagnostic]
summary: Summary
class GeneralD... | 74 | 1,718 |
strawberry | tests/typecheckers/utils/ty.py | .py | from __future__ import annotations
import os
import pathlib
import re
import subprocess
import tempfile
from typing import cast
from .result import Result, ResultType
def run_ty(code: str, strict: bool = True) -> list[Result]:
# ty uses concise output format which includes revealed type info
# Format: <file... | 89 | 2,723 |
strawberry | tests/typecheckers/utils/result.py | .py | from dataclasses import dataclass
from typing import Literal
ResultType = Literal[
"error",
"information",
"note",
]
@dataclass
class Result:
type: ResultType
message: str
line: int
column: int
| 17 | 225 |
strawberry | tests/typecheckers/utils/mypy.py | .py | from __future__ import annotations
import json
import os
import pathlib
import subprocess
import tempfile
from typing import TypedDict
from .result import Result
class PyrightCLIResult(TypedDict):
version: str
time: str
generalDiagnostics: list[GeneralDiagnostic]
summary: Summary
class GeneralDiag... | 100 | 2,480 |
strawberry | tests/typecheckers/utils/typecheck.py | .py | from __future__ import annotations
import concurrent.futures
from dataclasses import dataclass
from .mypy import run_mypy
from .pyright import run_pyright
from .result import Result
from .ty import run_ty
@dataclass
class TypecheckResult:
pyright: list[Result]
mypy: list[Result]
ty: list[Result]
def t... | 34 | 968 |
strawberry | tests/views/schema.py | .py | import asyncio
import contextlib
from collections.abc import AsyncGenerator
from enum import Enum
from typing import Any
from graphql import GraphQLError
from graphql.version import VersionInfo, version_info
import strawberry
from strawberry.extensions import SchemaExtension
from strawberry.file_uploads import Upload... | 342 | 10,065 |
strawberry | tests/federation/test_entities.py | .py | from graphql import located_error
import strawberry
from strawberry.types import Info
def test_fetch_entities():
@strawberry.federation.type(keys=["upc"])
class Product:
upc: str
@classmethod
def resolve_reference(cls, upc) -> "Product":
return Product(upc=upc)
@stra... | 498 | 12,949 |
strawberry | tests/federation/test_version_validation.py | .py | import pytest
import strawberry
from strawberry.federation.schema_directives import Context, Cost, ListSize, Policy
@pytest.mark.parametrize(
("directive_name", "minimum_version", "valid_version", "invalid_version"),
[
("policy", "2.6", "2.6", "2.5"),
("context", "2.8", "2.8", "2.7"),
... | 171 | 5,048 |
strawberry | tests/federation/test_types.py | .py | import strawberry
def test_type():
@strawberry.federation.type(keys=["id"])
class Location:
id: strawberry.ID
assert Location(id=strawberry.ID("1")).id == "1"
def test_type_and_override():
@strawberry.federation.type(keys=["id"])
class Location:
id: strawberry.ID
address... | 35 | 836 |
strawberry | tests/federation/test_schema.py | .py | import textwrap
import warnings
from typing import Generic, TypeVar
import pytest
import strawberry
def test_entities_type_when_no_type_has_keys():
@strawberry.federation.type()
class Product:
upc: str
name: str | None
price: int | None
weight: int | None
@strawberry.fed... | 370 | 7,994 |
strawberry | tests/federation/printer/test_policy.py | .py | import textwrap
from enum import Enum
from typing import Annotated
import strawberry
def test_field_policy_printed_correctly():
@strawberry.federation.interface(
policy=[["client", "poweruser"], ["admin"], ["productowner"]]
)
class SomeInterface:
id: strawberry.ID
@strawberry.federat... | 132 | 3,426 |
strawberry | tests/federation/printer/test_compose_directive.py | .py | import textwrap
import strawberry
from strawberry.schema_directive import Location
def test_schema_directives_and_compose_schema():
@strawberry.federation.schema_directive(
locations=[Location.OBJECT],
name="cacheControl",
compose=True,
)
class CacheControl:
max_age: int
... | 132 | 3,452 |
strawberry | tests/federation/printer/test_entities.py | .py | # type: ignore
import textwrap
import strawberry
def test_entities_type_when_no_type_has_keys():
global Review
@strawberry.federation.type
class User:
username: str
@strawberry.federation.type(extend=True)
class Product:
upc: str = strawberry.federation.field(external=True)
... | 135 | 2,880 |
strawberry | tests/federation/printer/test_provides.py | .py | # type: ignore
import textwrap
import strawberry
from strawberry.schema.config import StrawberryConfig
def test_field_provides_are_printed_correctly_camel_case_on():
global Review
@strawberry.federation.type
class User:
username: str
@strawberry.federation.type(keys=["upc"], extend=True)
... | 149 | 3,625 |
strawberry | tests/federation/printer/test_inaccessible.py | .py | import textwrap
from enum import Enum
from typing import Annotated
import pytest
import strawberry
def test_field_inaccessible_printed_correctly():
@strawberry.federation.interface(inaccessible=True)
class AnInterface:
id: strawberry.ID
@strawberry.interface
class SomeInterface:
id:... | 317 | 7,262 |
strawberry | tests/federation/printer/test_additional_directives.py | .py | # type: ignore
import textwrap
import strawberry
from strawberry.schema.config import StrawberryConfig
from strawberry.schema_directive import Location
def test_additional_schema_directives_printed_correctly_object():
@strawberry.schema_directive(locations=[Location.OBJECT])
class CacheControl:
max_... | 111 | 2,787 |
strawberry | tests/federation/printer/test_link.py | .py | import textwrap
import strawberry
from strawberry.federation.schema_directives import Link
from tests.conftest import skip_if_gql_32
def test_link_directive():
@strawberry.type
class Query:
hello: str
schema = strawberry.federation.Schema(
query=Query,
schema_directives=[
... | 345 | 7,143 |
strawberry | tests/federation/printer/test_one_of.py | .py | import textwrap
import strawberry
def test_prints_one_of_directive():
@strawberry.federation.input(one_of=True, tags=["myTag", "anotherTag"])
class Input:
a: str | None = strawberry.UNSET
b: int | None = strawberry.UNSET
@strawberry.federation.type
class Query:
hello: str
... | 43 | 935 |
strawberry | tests/federation/printer/test_tag.py | .py | import textwrap
from enum import Enum
from typing import Annotated
import strawberry
def test_field_tag_printed_correctly():
@strawberry.federation.interface(tags=["myTag", "anotherTag"])
class SomeInterface:
id: strawberry.ID
@strawberry.federation.type(tags=["myTag", "anotherTag"])
class P... | 243 | 5,643 |
strawberry | tests/federation/printer/test_shareable.py | .py | # type: ignore
import textwrap
import strawberry
def test_field_shareable_printed_correctly():
@strawberry.interface
class SomeInterface:
id: strawberry.ID
@strawberry.federation.type(keys=["upc"], extend=True, shareable=True)
class Product(SomeInterface):
upc: str = strawberry.fede... | 55 | 1,346 |
strawberry | tests/federation/printer/test_interface.py | .py | import textwrap
import strawberry
def test_entities_extending_interface():
@strawberry.interface
class SomeInterface:
id: strawberry.ID
@strawberry.federation.type(keys=["upc"], extend=True)
class Product(SomeInterface):
upc: str = strawberry.federation.field(external=True)
@str... | 53 | 1,257 |
strawberry | tests/federation/printer/test_keys.py | .py | # type: ignore
import textwrap
import strawberry
from strawberry.federation.schema_directives import Key
def test_keys_federation_2():
global Review
@strawberry.federation.type
class User:
username: str
@strawberry.federation.type(keys=[Key(fields="upc", resolvable=True)], extend=True)
... | 73 | 1,662 |
strawberry | tests/federation/printer/test_requires.py | .py | # type: ignore
import textwrap
import strawberry
def test_fields_requires_are_printed_correctly():
global Review
@strawberry.federation.type
class User:
username: str
@strawberry.federation.type(keys=["upc"], extend=True)
class Product:
upc: str = strawberry.federation.field(ex... | 81 | 2,006 |
strawberry | tests/federation/printer/test_requires_scopes.py | .py | import textwrap
from enum import Enum
from typing import Annotated
import strawberry
def test_field_requires_scopes_printed_correctly():
@strawberry.federation.interface(
requires_scopes=[["client", "poweruser"], ["admin"], ["productowner"]]
)
class SomeInterface:
id: strawberry.ID
@... | 132 | 3,567 |
strawberry | tests/federation/printer/test_authenticated.py | .py | import textwrap
from enum import Enum
from typing import Annotated
import strawberry
def test_field_authenticated_printed_correctly():
@strawberry.federation.interface(authenticated=True)
class SomeInterface:
id: strawberry.ID
@strawberry.federation.type(authenticated=True)
class Product(Som... | 122 | 2,850 |
strawberry | tests/federation/printer/test_interface_object.py | .py | import textwrap
import strawberry
def test_interface_object():
@strawberry.federation.interface_object(keys=["id"])
class SomeInterface:
id: strawberry.ID
schema = strawberry.federation.Schema(types=[SomeInterface])
expected = """
schema @link(url: "https://specs.apollo.dev/federati... | 37 | 810 |
strawberry | tests/federation/printer/test_override.py | .py | # type: ignore
import textwrap
import strawberry
from strawberry.federation.schema_directives import Override
def test_field_override_printed_correctly():
@strawberry.interface
class SomeInterface:
id: strawberry.ID
@strawberry.federation.type(keys=["upc"], extend=True)
class Product(SomeIn... | 108 | 2,802 |
strawberry | tests/schema_codegen/test_names.py | .py | import keyword
import textwrap
import pytest
from strawberry.schema_codegen import codegen
@pytest.mark.parametrize(
"name",
[keyword for keyword in keyword.kwlist if keyword not in ("False", "True", "None")],
)
def test_handles_keywords(name: str):
schema = f"""
type Example {{
{name}: Stri... | 57 | 1,174 |
strawberry | tests/schema_codegen/test_enum.py | .py | import textwrap
from strawberry.schema_codegen import codegen
def test_enum():
schema = """
enum AuthStateNameEnum {
AUTH_BROWSER_LAUNCHED
AUTH_COULD_NOT_LAUNCH_BROWSER
AUTH_ERROR_DURING_LOGIN
}
"""
expected = textwrap.dedent(
"""
from __future__ import an... | 61 | 1,439 |
strawberry | tests/schema_codegen/test_scalar.py | .py | import textwrap
from strawberry.schema_codegen import codegen
def test_scalar():
schema = """
scalar LocalDate @specifiedBy(url: "https://scalars.graphql.org/andimarek/local-date.html")
"""
expected = textwrap.dedent(
"""
from __future__ import annotations
import strawberry
... | 84 | 2,064 |
strawberry | tests/schema_codegen/test_descriptions.py | .py | import ast
import textwrap
from pathlib import Path
from pytest_snapshot.plugin import Snapshot
from strawberry.schema_codegen import codegen
HERE = Path(__file__).parent
def test_long_descriptions(snapshot: Snapshot):
snapshot.snapshot_dir = HERE / "snapshots"
schema = '''
"""A connection to a list o... | 74 | 2,193 |
strawberry | tests/schema_codegen/test_order.py | .py | import textwrap
from strawberry.schema_codegen import codegen
def test_generates_used_interface_before():
schema = """
type Human implements Being {
id: ID!
name: String!
friends: [Human]
}
type Cat implements Being {
id: ID!
name: String!
livesLeft: I... | 131 | 3,385 |
strawberry | tests/schema_codegen/test_root_types_extend.py | .py | import textwrap
from strawberry.schema_codegen import codegen
def test_extend_query():
schema = """
extend type Query {
world: String!
}
"""
expected = textwrap.dedent(
"""
from __future__ import annotations
import strawberry
@strawberry.type
clas... | 73 | 1,349 |
strawberry | tests/schema_codegen/test_union.py | .py | import textwrap
from strawberry.schema_codegen import codegen
def test_union():
schema = """
union User = Admin | Client
type Admin {
name: String!
}
type Client {
name: String!
}
"""
expected = textwrap.dedent(
"""
from __future__ import annotations... | 38 | 670 |
strawberry | tests/schema_codegen/test_federation.py | .py | import textwrap
from strawberry.schema_codegen import codegen
def test_support_for_key_directive():
schema = """
extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key"])
type User @key(fields: "id") {
id: ID!
username: String!
}
"""
expected = t... | 236 | 6,120 |
strawberry | tests/schema_codegen/test_input_types.py | .py | import textwrap
from strawberry.schema_codegen import codegen
def test_codegen_input_type():
schema = """
input Example {
a: Int!
b: Float!
c: Boolean!
d: String!
e: ID!
f: [Int!]!
g: [Float!]!
h: [Boolean!]!
i: [String!]!
j: [ID... | 331 | 7,029 |
strawberry | tests/schema_codegen/test_types.py | .py | import textwrap
from strawberry.schema_codegen import codegen
def test_codegen_object_type():
schema = """
type Example {
a: Int!
b: Float!
c: Boolean!
d: String!
e: ID!
f: [Int!]!
g: [Float!]!
h: [Boolean!]!
i: [String!]!
j: [ID... | 110 | 2,276 |
strawberry | tests/schema_codegen/test_schema.py | .py | import textwrap
from strawberry.schema_codegen import codegen
def test_adds_schema_if_schema_is_defined():
schema = """
type Root {
hello: String!
}
type RootMutation {
hello: String!
}
type RootSubscription {
hello: String!
}
schema {
query: Root
... | 118 | 2,220 |
strawberry | tests/schema_codegen/snapshots/long_descriptions.py | .py | from __future__ import annotations
import strawberry
@strawberry.type(description="A connection to a list of items.")
class FilmCharactersConnection:
page_info: PageInfo = strawberry.field(description="Information to aid in pagination.")
edges: list[FilmCharactersEdge | None] | None = strawberry.field(descript... | 22 | 1,184 |
strawberry | tests/types/test_convert_to_dictionary.py | .py | from enum import Enum
import strawberry
from strawberry import asdict
def test_convert_simple_type_to_dictionary():
@strawberry.type
class People:
name: str
age: int
lorem = People(name="Alex", age=30)
assert asdict(lorem) == {
"name": "Alex",
"age": 30,
}
def ... | 65 | 1,347 |
strawberry | tests/types/test_resolver_types.py | .py | from enum import Enum
from typing import Optional, TypeVar, Union
from asgiref.sync import sync_to_async
import strawberry
from strawberry.types.fields.resolver import StrawberryResolver
def test_enum():
@strawberry.enum
class Language(Enum):
ENGLISH = "english"
ITALIAN = "italian"
J... | 108 | 2,382 |
strawberry | tests/types/test_argument_types.py | .py | import warnings
from enum import Enum
from typing import Optional, TypeVar
import pytest
import strawberry
from strawberry.types.info import Info
def test_enum():
@strawberry.enum
class Locale(Enum):
UNITED_STATES = "en_US"
UK = "en_UK"
AUSTRALIA = "en_AU"
@strawberry.mutation
... | 131 | 2,966 |
strawberry | tests/types/test_parent_type_future_annotations.py | .py | from __future__ import annotations
import textwrap
import strawberry
def test_parent_type():
global User
try:
def get_full_name(user: strawberry.Parent[User]) -> str:
return f"{user.first_name} {user.last_name}"
@strawberry.type
class User:
first_name: str
... | 55 | 1,343 |
strawberry | tests/types/test_execution.py | .py | import strawberry
from strawberry.extensions import SchemaExtension
@strawberry.type
class Query:
@strawberry.field
def ping(self) -> str:
return "pong"
def test_execution_context_operation_name_and_type():
operation_name = None
operation_type = None
class MyExtension(SchemaExtension):
... | 172 | 4,884 |
strawberry | tests/types/test_lazy_types_future_annotations.py | .py | from __future__ import annotations
import textwrap
from typing import TYPE_CHECKING, Annotated, Optional
import strawberry
if TYPE_CHECKING:
from tests.schema.test_lazy.type_a import TypeA
from tests.schema.test_lazy.type_c import TypeC
# Module-level Annotated alias. With `from __future__ import annotatio... | 245 | 5,647 |
strawberry | tests/types/test_field_types.py | .py | from enum import Enum
from typing import Optional, TypeVar
import strawberry
from strawberry.annotation import StrawberryAnnotation
from strawberry.types.field import StrawberryField
from strawberry.types.union import StrawberryUnion
def test_enum():
@strawberry.enum
class Egnum(Enum):
a = "A"
... | 96 | 2,166 |
strawberry | tests/types/test_union_type_resolver.py | .py | """Unit tests for StrawberryUnion.get_type_resolver and the resolver it returns.
Directly tests the _resolve_union_type inner function, covering:
- Correct type name returned for a strawberry-typed object.
- Fallback to is_type_of when the object has no strawberry definition.
- WrongReturnTypeForUnion raised when neit... | 186 | 5,218 |
strawberry | tests/types/test_asdict.py | .py | from enum import Enum
import strawberry
from strawberry import UNSET, Maybe, Some, asdict
def test_simple_type():
@strawberry.type
class User:
name: str
age: int
assert asdict(User(name="Alex", age=30)) == {"name": "Alex", "age": 30}
def test_input_type():
@strawberry.input
cla... | 353 | 8,162 |
strawberry | tests/types/test_annotation.py | .py | import itertools
from enum import Enum
from typing import Optional, TypeVar
import pytest
import strawberry
from strawberry.annotation import StrawberryAnnotation
from strawberry.types.unset import UnsetType
class Bleh:
pass
@strawberry.enum
class NumaNuma(Enum):
MA = "ma"
I = "i" # noqa: E741
A ... | 76 | 1,637 |
strawberry | tests/types/test_lazy_types.py | .py | # type: ignore
import enum
import textwrap
from typing import Annotated, Generic, TypeAlias, TypeVar
import strawberry
from strawberry.annotation import StrawberryAnnotation
from strawberry.types.base import get_object_definition
from strawberry.types.field import StrawberryField
from strawberry.types.fields.resolver ... | 243 | 6,857 |
strawberry | tests/types/test_object_types.py | .py | # type: ignore
import dataclasses
import re
from enum import Enum
from typing import Annotated, Optional, TypeVar
import pytest
import strawberry
from strawberry.exceptions import MultipleStrawberryFieldsError
from strawberry.types.base import get_object_definition, has_object_definition
from strawberry.types.field i... | 499 | 12,706 |
strawberry | tests/types/test_lazy_type_cache.py | .py | """Regression tests for lazy type resolution to prevent duplicate type errors.
The fix relies on importlib.import_module() using sys.modules, which caches
imported modules and ensures the same module object is returned on subsequent
imports (unless explicitly reloaded).
"""
import importlib
import sys
import types
fr... | 162 | 4,726 |
strawberry | tests/types/test_deferred_annotations.py | .py | from sys import modules
from types import ModuleType
import strawberry
deferred_module_source = """
from __future__ import annotations
import strawberry
@strawberry.type
class User:
username: str
email: str
@strawberry.interface
class UserContent:
created_by: User
"""
def test_deferred_other_module()... | 38 | 736 |
strawberry | tests/types/test_parent_type.py | .py | import textwrap
from typing import ForwardRef
import pytest
import strawberry
from strawberry.parent import resolve_parent_forward_arg
def test_parent_type():
global User
try:
def get_full_name(user: strawberry.Parent["User"]) -> str:
return f"{user.first_name} {user.last_name}"
... | 71 | 1,921 |
strawberry | tests/types/test_cast.py | .py | import strawberry
from strawberry.types.cast import get_strawberry_type_cast
def test_cast():
@strawberry.type
class SomeType: ...
class OtherType: ...
obj = OtherType
assert get_strawberry_type_cast(obj) is None
cast_obj = strawberry.cast(SomeType, obj)
assert cast_obj is obj
asser... | 29 | 631 |
strawberry | tests/types/cross_module_resolvers/a_mod.py | .py | import strawberry
def a_resolver() -> list["AObject"]:
return []
@strawberry.type
class ABase:
a_name: str
@strawberry.type
class AObject(ABase):
a_age: int
@strawberry.field
def a_is_of_full_age(self) -> bool:
return self.a_age >= 18
| 20 | 270 |
strawberry | tests/types/cross_module_resolvers/c_mod.py | .py | import strawberry
from . import a_mod, b_mod, x_mod
from .a_mod import AObject as C_AObject
from .b_mod import BObject as C_BObject
def c_inheritance_resolver() -> list["CInheritance"]:
pass
def c_composition_resolver() -> list["CComposition"]:
pass
def c_composition_by_name_resolver() -> list["CComposit... | 61 | 1,426 |
strawberry | tests/types/cross_module_resolvers/test_cross_module_resolvers.py | .py | """The following tests ensure that the types are resolved using the correct
module. Concrete types should be non-problematic and are only included
here for completeness. A problematic case is when a type is a string
(forward reference) and can only be resolved at schema construction.
"""
import strawberry
from . impo... | 155 | 4,448 |
strawberry | tests/types/cross_module_resolvers/x_mod.py | .py | def typeless_resolver() -> list: # pragma: no cover
return []
| 3 | 67 |
strawberry | tests/types/cross_module_resolvers/b_mod.py | .py | import strawberry
def b_resolver() -> list["BObject"]:
return []
@strawberry.type
class BBase:
b_name: str = strawberry.field()
@strawberry.type
class BObject(BBase):
b_age: int = strawberry.field()
@strawberry.field
def b_is_of_full_age(self) -> bool:
return self.b_age >= 18
| 20 | 312 |
strawberry | tests/types/resolving/test_optionals.py | .py | from typing import Optional, Union
import strawberry
from strawberry.annotation import StrawberryAnnotation
from strawberry.types.base import StrawberryOptional
from strawberry.types.unset import UnsetType
def test_basic_optional():
annotation = StrawberryAnnotation(Optional[str])
resolved = annotation.resol... | 209 | 5,984 |
strawberry | tests/types/resolving/test_generics.py | .py | from enum import Enum
from typing import Generic, Optional, TypeVar, Union
import pytest
import strawberry
from strawberry.annotation import StrawberryAnnotation
from strawberry.types.base import (
StrawberryList,
StrawberryObjectDefinition,
StrawberryOptional,
StrawberryTypeVar,
get_object_defini... | 146 | 3,828 |
strawberry | tests/types/resolving/test_unions.py | .py | from typing import Annotated, Generic, TypeVar, Union
import pytest
import strawberry
from strawberry.annotation import StrawberryAnnotation
from strawberry.exceptions import InvalidUnionTypeError
from strawberry.types.base import get_object_definition
from strawberry.types.union import StrawberryUnion, union
def t... | 135 | 3,369 |
strawberry | tests/types/resolving/test_union_pipe.py | .py | import datetime
import typing
from typing import Union
import pytest
import strawberry
from strawberry.annotation import StrawberryAnnotation
from strawberry.exceptions.invalid_union_type import InvalidUnionTypeError
from strawberry.types.base import StrawberryOptional
from strawberry.types.union import StrawberryUni... | 108 | 2,605 |
strawberry | tests/types/resolving/test_literals.py | .py | from typing import Optional, Union
from strawberry.annotation import StrawberryAnnotation
def test_bool():
annotation = StrawberryAnnotation(bool)
resolved = annotation.resolve()
assert resolved is bool
def test_float():
annotation = StrawberryAnnotation(float)
resolved = annotation.resolve()
... | 46 | 925 |
strawberry | tests/types/resolving/test_enums.py | .py | from enum import Enum
import strawberry
from strawberry.annotation import StrawberryAnnotation
def test_basic():
@strawberry.enum
class NumaNuma(Enum):
MA = "ma"
I = "i" # noqa: E741
A = "a"
HI = "hi"
annotation = StrawberryAnnotation(NumaNuma)
resolved = annotation.... | 20 | 468 |
strawberry | tests/types/resolving/test_forward_references.py | .py | import pytest
import strawberry
from strawberry.annotation import StrawberryAnnotation
def test_forward_reference():
global ForwardClass
annotation = StrawberryAnnotation("ForwardClass", namespace=globals())
@strawberry.type
class ForwardClass:
backward: bool
resolved = annotation.reso... | 40 | 837 |
strawberry | tests/types/resolving/test_string_annotations.py | .py | from typing import Optional, TypeVar
import strawberry
from strawberry.annotation import StrawberryAnnotation
from strawberry.types.base import (
StrawberryList,
StrawberryOptional,
StrawberryTypeVar,
)
def test_basic_string():
annotation = StrawberryAnnotation("str")
resolved = annotation.resolv... | 200 | 4,883 |
strawberry | tests/types/resolving/test_lists.py | .py | from collections.abc import Sequence
from typing import Optional, Union
import strawberry
from strawberry.annotation import StrawberryAnnotation
from strawberry.types.base import StrawberryList
def test_basic_list():
annotation = StrawberryAnnotation(list[str])
resolved = annotation.resolve()
assert isi... | 168 | 4,565 |
strawberry | tests/plugins/strawberry_exceptions.py | .py | import contextlib
import os
import re
from collections import defaultdict
from collections.abc import Generator
from dataclasses import dataclass
from pathlib import Path
import pytest
import rich
import rich.console
from _pytest.nodes import Item
from pluggy._result import _Result
from rich.traceback import Traceback... | 175 | 5,343 |
strawberry | tests/channels/test_testing.py | .py | from __future__ import annotations
from collections.abc import AsyncGenerator
from typing import TYPE_CHECKING, Any
import pytest
from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL
from tests.views.schema import schema
if TYPE_CHECKING:
from strawberry.channels.testing impor... | 57 | 1,810 |
strawberry | tests/channels/test_layers.py | .py | from __future__ import annotations
import asyncio
from collections.abc import AsyncGenerator
from typing import TYPE_CHECKING
import pytest
from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL
from strawberry.subscriptions.protocols.graphql_transport_ws.types import (
CompleteMessage,
Connectio... | 441 | 14,756 |
strawberry | tests/channels/test_router.py | .py | from unittest import mock
import pytest
from strawberry.subscriptions import (
GRAPHQL_SSE_PROTOCOL,
GRAPHQL_TRANSPORT_WS_PROTOCOL,
GRAPHQL_WS_PROTOCOL,
)
from tests.views.schema import schema
def _fake_asgi():
return lambda: None
@mock.patch("strawberry.channels.router.GraphQLHTTPConsumer.as_asgi... | 111 | 3,429 |
strawberry | tests/schema/test_schema_generation.py | .py | import pytest
from graphql import (
GraphQLField,
GraphQLNonNull,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
)
from graphql import print_schema as graphql_core_print_schema
import strawberry
def test_generates_schema():
@strawberry.type
class Query:
example: str
schema ... | 58 | 1,400 |
strawberry | tests/schema/test_dataloaders.py | .py | from dataclasses import dataclass
import pytest
import strawberry
from strawberry.dataloader import DataLoader
@pytest.mark.asyncio
async def test_can_use_dataloaders(mocker):
@dataclass
class User:
id: str
async def idx(keys) -> list[User]:
return [User(key) for key in keys]
mock_... | 46 | 921 |
strawberry | tests/schema/test_input.py | .py | import re
import textwrap
import pytest
import strawberry
from strawberry.exceptions import InvalidSuperclassInterfaceError
from strawberry.printer import print_schema
from tests.conftest import skip_if_gql_32
def test_renaming_input_fields():
@strawberry.input
class FilterInput:
in_: str | None = s... | 144 | 3,624 |
strawberry | tests/schema/test_generics.py | .py | import textwrap
from enum import Enum
from typing import Any, Generic, TypeVar
from typing_extensions import Self
import strawberry
def test_supports_generic_simple_type():
T = TypeVar("T")
@strawberry.type
class Edge(Generic[T]):
cursor: strawberry.ID
node_field: T
@strawberry.type... | 1,267 | 25,841 |
strawberry | tests/schema/test_execution_errors.py | .py | import pytest
import strawberry
from strawberry.schema.config import StrawberryConfig
def test_runs_parsing():
@strawberry.type
class Query:
name: str
schema = strawberry.Schema(query=Query)
query = """
query {
example
"""
result = schema.execute_sync(query)
... | 135 | 2,923 |
strawberry | tests/schema/test_execution.py | .py | import textwrap
from textwrap import dedent
from unittest.mock import patch
import pytest
from graphql import GraphQLError, ValidationRule, validate
import strawberry
from strawberry.extensions import (
AddValidationRules,
DisableValidation,
SchemaExtension,
)
from strawberry.utils import IS_GQL_32
@pyt... | 489 | 11,092 |
strawberry | tests/schema/test_stream.py | .py | from collections.abc import AsyncGenerator
import pytest
from graphql import GraphQLError
import strawberry
from strawberry.extensions import MaxTokensLimiter, SchemaExtension
from strawberry.schema._graphql_core import GraphQLIncrementalExecutionResults
from strawberry.schema.config import StrawberryConfig
from stra... | 325 | 10,186 |
strawberry | tests/schema/test_enum.py | .py | from enum import Enum
from textwrap import dedent
from typing import Annotated
import pytest
import strawberry
from strawberry.types.lazy_type import lazy
def test_enum_resolver():
@strawberry.enum
class IceCreamFlavour(Enum):
VANILLA = "vanilla"
STRAWBERRY = "strawberry"
CHOCOLATE =... | 519 | 12,870 |
strawberry | tests/schema/test_maybe.py | .py | from textwrap import dedent
from typing import Annotated
import pytest
import strawberry
@pytest.fixture
def maybe_schema() -> strawberry.Schema:
@strawberry.type
class User:
name: str
phone: str | None
user = User(name="Patrick", phone=None)
@strawberry.type
class Query:
... | 1,305 | 36,216 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.