Skip to content

Commit

Permalink
Merge branch 'main' into add_http_extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Jul 24, 2024
2 parents e3afec3 + 581f508 commit 82708d7
Show file tree
Hide file tree
Showing 250 changed files with 4,008 additions and 1,922 deletions.
59 changes: 57 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,61 @@
CHANGELOG
=========

0.236.2 - 2024-07-23
--------------------

Update federation entity resolver exception handling to set the result to the original error instead of a `GraphQLError`, which obscured the original message and meta-fields.

Contributed by [Bradley Oesch](https://github.com/bradleyoesch) via [PR #3144](https://github.com/strawberry-graphql/strawberry/pull/3144/)


0.236.1 - 2024-07-23
--------------------

This release fixes an issue where optional lazy types using `| None` were
failing to be correctly resolved inside modules using future annotations, e.g.

```python
from __future__ import annotations

from typing import Annotated, TYPE_CHECKING

import strawberry

if TYPE_CHECKING:
from types import Group


@strawberry.type
class Person:
group: Annotated["Group", strawberry.lazy("types.group")] | None
```

This should now work as expected.

Contributed by [Thiago Bellini Ribeiro](https://github.com/bellini666) via [PR #3576](https://github.com/strawberry-graphql/strawberry/pull/3576/)


0.236.0 - 2024-07-17
--------------------

This release changes some of the internals of Strawberry, it shouldn't
be affecting most of the users, but since we have changed the structure
of the code you might need to update your imports.

Thankfully we also provide a codemod for this, you can run it with:

```bash
strawberry upgrade update-imports
```

This release also includes additional documentation to some of
the classes, methods and functions, this is in preparation for
having the API reference in the documentation ✨

Contributed by [Patrick Arminio](https://github.com/patrick91) via [PR #3546](https://github.com/strawberry-graphql/strawberry/pull/3546/)


0.235.2 - 2024-07-08
--------------------

Expand Down Expand Up @@ -1341,7 +1396,7 @@ class User:
@strawberry.field
@staticmethod
async def name(parent: strawberry.Parent[UserRow]) -> str:
return f"User Number {parent.id}"
return f"User Number {parent.id_}"


@strawberry.type
Expand Down Expand Up @@ -4197,7 +4252,7 @@ the original type was already used with that generic in the schema.

Example:

```python3
```python
@strawberry.type
class Query:
regular: Edge[User]
Expand Down
1 change: 1 addition & 0 deletions docs/breaking-changes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: List of breaking changes and deprecations

# List of breaking changes and deprecations

- [Version 0.236.0 - 17 July 2024](./breaking-changes/0.236.0.md)
- [Version 0.233.0 - 29 May 2024](./breaking-changes/0.233.0.md)
- [Version 0.217.0 - 18 December 2023](./breaking-changes/0.217.0.md)
- [Version 0.213.0 - 8 November 2023](./breaking-changes/0.213.0.md)
Expand Down
19 changes: 19 additions & 0 deletions docs/breaking-changes/0.236.0.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: 0.236.0 Breaking Changes
slug: breaking-changes/0.236.0
---

# v0.236.0 changes some of the imports

This release changes the location of some files in the codebase, this is to make
the codebase more organized and easier to navigate.

Technically most of these changes should not affect you, but if you were
importing some of the files directly you will need to update the imports.

We created a codemod to help you with that, feel free to try and submit bugs if
we missed something.

```bash
strawberry upgrade update-imports
```
2 changes: 1 addition & 1 deletion docs/guides/field-extensions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import time
import strawberry
from strawberry.extensions import FieldExtension
from strawberry.schema_directive import Location
from strawberry.field import StrawberryField
from strawberry.types.field import StrawberryField


@strawberry.schema_directive(locations=[Location.FIELD_DEFINITION])
Expand Down
1 change: 0 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def tests_typecheckers(session: Session) -> None:

session.install("pyright")
session.install("pydantic")
session.install("git+https://github.com/python/mypy.git#master")

session.run(
"pytest",
Expand Down
1,067 changes: 514 additions & 553 deletions poetry.lock

Large diffs are not rendered by default.

22 changes: 17 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "strawberry-graphql"
packages = [ { include = "strawberry" } ]
version = "0.235.2"
version = "0.236.2"
description = "A library for creating GraphQL APIs"
authors = ["Patrick Arminio <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -68,7 +68,7 @@ asgiref = "^3.2"
ddtrace = ">=1.6.4"
email-validator = {version = ">=1.1.3,<3.0.0", optional = false}
freezegun = "^1.2.1"
libcst = {version = ">=0.4.7", optional = false}
libcst = {version = ">=1.0.0", optional = false}
MarkupSafe = "2.1.3"
nox = "^2023.4.22"
nox-poetry = "^1.0.3"
Expand Down Expand Up @@ -235,9 +235,6 @@ ignore = [
"S102",
"S104",
"S324",
# maybe we can enable this in future
# we'd want to have consistent docstrings in future
"D",
"ANN101", # missing annotation for self?
# definitely enable these, maybe not in tests
"ANN102",
Expand Down Expand Up @@ -351,6 +348,17 @@ ignore = [
"FIX001",
"FIX002",
"FA100",

# Docstrings, maybe to enable later
"D100",
"D101",
"D102",
"D103",
"D104",
"D105",
"D106",
"D107",
"D412",
]

[tool.ruff.lint.per-file-ignores]
Expand All @@ -370,6 +378,7 @@ ignore = [
"S603",
"S607",
"B018",
"D",
]
"strawberry/extensions/tracing/__init__.py" = ["TCH004"]
"tests/http/clients/__init__.py" = ["F401"]
Expand All @@ -384,3 +393,6 @@ exclude =[
'tests/codegen/snapshots/',
'tests/cli/snapshots/'
]

[tool.ruff.lint.pydocstyle]
convention = "google"
28 changes: 17 additions & 11 deletions strawberry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
"""Strawberry is a Python library for GraphQL.
Strawberry is a Python library for GraphQL that aims to stay close to the GraphQL
specification and allow for a more natural way of defining GraphQL schemas.
"""

from . import experimental, federation, relay
from .arguments import argument
from .auto import auto
from .custom_scalar import scalar
from .directive import directive, directive_field
from .enum import enum, enum_value
from .field import field
from .lazy_type import LazyType, lazy
from .mutation import mutation, subscription
from .object_type import asdict, input, interface, type
from .parent import Parent
from .permission import BasePermission
from .private import Private
from .scalars import ID
from .schema import Schema
from .schema_directive import schema_directive
from .types.arguments import argument
from .types.auto import auto
from .types.enum import enum, enum_value
from .types.field import field
from .types.info import Info
from .union import union
from .unset import UNSET
from .types.lazy_type import LazyType, lazy
from .types.mutation import mutation, subscription
from .types.object_type import asdict, input, interface, type
from .types.private import Private
from .types.scalar import scalar
from .types.union import union
from .types.unset import UNSET

__all__ = [
"BasePermission",
Expand Down
3 changes: 3 additions & 0 deletions strawberry/aiohttp/handlers/graphql_transport_ws_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ async def handle_request(self) -> web.StreamResponse:
await self.shutdown()

return self._ws


__all__ = ["GraphQLTransportWSHandler"]
3 changes: 3 additions & 0 deletions strawberry/aiohttp/handlers/graphql_ws_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ async def handle_request(self) -> Any:
await self.cleanup_operation(operation_id)

return self._ws


__all__ = ["GraphQLWSHandler"]
3 changes: 3 additions & 0 deletions strawberry/aiohttp/test/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ async def request(
)

return response


__all__ = ["GraphQLTestClient"]
3 changes: 3 additions & 0 deletions strawberry/aiohttp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,6 @@ def create_response(
sub_response.content_type = "application/json"

return sub_response


__all__ = ["GraphQLView"]
38 changes: 19 additions & 19 deletions strawberry/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@
)
from typing_extensions import Annotated, Self, get_args, get_origin

from strawberry.custom_scalar import ScalarDefinition
from strawberry.enum import EnumDefinition
from strawberry.exceptions.not_a_strawberry_enum import NotAStrawberryEnumError
from strawberry.lazy_type import LazyType
from strawberry.private import is_private
from strawberry.type import (
from strawberry.types.base import (
StrawberryList,
StrawberryObjectDefinition,
StrawberryOptional,
StrawberryTypeVar,
get_object_definition,
has_object_definition,
)
from strawberry.types.types import StrawberryObjectDefinition
from strawberry.unset import UNSET
from strawberry.types.enum import EnumDefinition
from strawberry.types.lazy_type import LazyType
from strawberry.types.private import is_private
from strawberry.types.scalar import ScalarDefinition
from strawberry.types.unset import UNSET
from strawberry.utils.typing import eval_type, is_generic, is_type_var

if TYPE_CHECKING:
from strawberry.field import StrawberryField
from strawberry.type import StrawberryType
from strawberry.union import StrawberryUnion
from strawberry.types.base import StrawberryType
from strawberry.types.field import StrawberryField
from strawberry.types.union import StrawberryUnion


ASYNC_TYPES = (
Expand Down Expand Up @@ -226,7 +226,7 @@ def create_type_var(self, evaled_type: TypeVar) -> StrawberryTypeVar:

def create_union(self, evaled_type: Type[Any], args: list[Any]) -> StrawberryUnion:
# Prevent import cycles
from strawberry.union import StrawberryUnion
from strawberry.types.union import StrawberryUnion

# TODO: Deal with Forward References/origin
if isinstance(evaled_type, StrawberryUnion):
Expand Down Expand Up @@ -290,8 +290,7 @@ def _is_lazy_type(cls, annotation: Any) -> bool:

@classmethod
def _is_optional(cls, annotation: Any, args: List[Any]) -> bool:
"""Returns True if the annotation is Optional[SomeType]"""

"""Returns True if the annotation is Optional[SomeType]."""
# Optionals are represented as unions
if not cls._is_union(annotation, args):
return False
Expand All @@ -303,8 +302,7 @@ def _is_optional(cls, annotation: Any, args: List[Any]) -> bool:

@classmethod
def _is_list(cls, annotation: Any) -> bool:
"""Returns True if annotation is a List"""

"""Returns True if annotation is a List."""
annotation_origin = get_origin(annotation)
annotation_mro = getattr(annotation, "__mro__", [])
is_list = any(x is list for x in annotation_mro)
Expand All @@ -318,7 +316,7 @@ def _is_list(cls, annotation: Any) -> bool:
@classmethod
def _is_strawberry_type(cls, evaled_type: Any) -> bool:
# Prevent import cycles
from strawberry.union import StrawberryUnion
from strawberry.types.union import StrawberryUnion

if isinstance(evaled_type, EnumDefinition):
return True
Expand All @@ -344,8 +342,7 @@ def _is_strawberry_type(cls, evaled_type: Any) -> bool:

@classmethod
def _is_union(cls, annotation: Any, args: List[Any]) -> bool:
"""Returns True if annotation is a Union"""

"""Returns True if annotation is a Union."""
# this check is needed because unions declared with the new syntax `A | B`
# don't have a `__origin__` property on them, but they are instances of
# `UnionType`, which is only available in Python 3.10+
Expand All @@ -363,7 +360,7 @@ def _is_union(cls, annotation: Any, args: List[Any]) -> bool:
if annotation_origin is typing.Union:
return True

from strawberry.union import StrawberryUnion
from strawberry.types.union import StrawberryUnion

return any(isinstance(arg, StrawberryUnion) for arg in args)

Expand All @@ -386,3 +383,6 @@ def _is_input_type(type_: Any) -> bool:
return False

return type_.__strawberry_definition__.is_input


__all__ = ["StrawberryAnnotation"]
6 changes: 3 additions & 3 deletions strawberry/asgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ def __init__(
else:
self.graphql_ide = graphql_ide

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
async def __call__(self, scope: Request, receive: Receive, send: Send) -> None:
if scope["type"] == "http":
return await self.handle_http(scope, receive, send)
return await self.handle_http(scope, receive, send) # type: ignore

elif scope["type"] == "websocket":
ws = WebSocket(scope=scope, receive=receive, send=send)
ws = WebSocket(scope, receive=receive, send=send) # type: ignore
preferred_protocol = self.pick_preferred_protocol(ws)

if preferred_protocol == GRAPHQL_TRANSPORT_WS_PROTOCOL:
Expand Down
3 changes: 3 additions & 0 deletions strawberry/asgi/handlers/graphql_transport_ws_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ async def handle_request(self) -> None:
pass
finally:
await self.shutdown()


__all__ = ["GraphQLTransportWSHandler"]
3 changes: 3 additions & 0 deletions strawberry/asgi/handlers/graphql_ws_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ async def handle_request(self) -> Any:

for operation_id in list(self.subscriptions.keys()):
await self.cleanup_operation(operation_id)


__all__ = ["GraphQLWSHandler"]
3 changes: 3 additions & 0 deletions strawberry/asgi/test/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ def request(

def _decode(self, response: Any, type: Literal["multipart", "json"]) -> Any:
return response.json()


__all__ = ["GraphQLTestClient"]
Loading

0 comments on commit 82708d7

Please sign in to comment.