A GraphQL library for Python that leverages type annotations 🍓
MIT License
Bot releases are hidden (Show)
Published by botberry over 1 year ago
This release parses the input arguments to a field earlier so that Field
Extensions recieve instances of Input types rather than plain dictionaries.
Example:
import strawberry
from strawberry.extensions import FieldExtension
@strawberry.input
class MyInput:
foo: str
class MyFieldExtension(FieldExtension):
def resolve(self, next_: Callable[..., Any], source: Any, info: Info, **kwargs):
# kwargs["my_input"] is instance of MyInput
...
@strawberry.type
class Query:
@strawberry.field
def field(self, my_input: MyInput) -> str:
return "hi"
Releases contributed by @jkimbo via #2731
Published by botberry over 1 year ago
This release adds a missing parameter to get_context
when using subscriptions with ASGI.
Releases contributed by @patrick91 via #2739
Published by botberry over 1 year ago
Do not display graphiql view in fastapi doc if graphiql parameter is deactivated
Releases contributed by @yak-toto via #2736
Published by botberry over 1 year ago
This PR adds a MaxTokensLimiter extension which limits the number of tokens in a GraphQL document.
import strawberry
from strawberry.extensions import MaxTokensLimiter
schema = strawberry.Schema(
Query,
extensions=[
MaxTokensLimiter(max_token_count=1000),
],
)
Published by botberry over 1 year ago
This release bumps the version of typing_extensions to >= 4.0.0
to fix the
error: "cannot import Self from typing_extensions"
.
Releases contributed by @tienman via #2704
Published by botberry over 1 year ago
This releases adds an extension for PyInstrument. It allows to instrument your server and find slow code paths.
You can use it like this:
import strawberry
from strawberry.extensions import pyinstrument
schema = strawberry.Schema(
Query,
extensions=[
pyinstrument.PyInstrument(report_path="pyinstrument.html"),
],
)
Releases contributed by @Helithumper via #2727
Published by botberry over 1 year ago
This PR adds a MaxAliasesLimiter extension which limits the number of aliases in a GraphQL document.
import strawberry
from strawberry.extensions import MaxAliasesLimiter
schema = strawberry.Schema(
Query,
extensions=[
MaxAliasesLimiter(max_alias_count=15),
],
)
Releases contributed by @reka via #2726
Published by botberry over 1 year ago
This release adds missing annotations in class methods, improving
our type coverage.
Releases contributed by @benesgarage via #2721
Published by botberry over 1 year ago
graphql_transport_ws
: Cancelling a subscription no longer blocks the connection
while any subscription finalizers run.
Releases contributed by @kristjanvalur via #2718
Published by botberry over 1 year ago
This release fix the return value of enums when using a custom
name converter for them.
Releases contributed by @patrick91 via #2696
Published by botberry over 1 year ago
This release adds support for Mypy 1.2.0
Releases contributed by @patrick91 via #2693
Published by botberry over 1 year ago
This release add support for converting the enum value names
from NameConverter
. It looks like this:
from enum import Enum
import strawberry
from strawberry.enum import EnumDefinition, EnumValue
from strawberry.schema.config import StrawberryConfig
from strawberry.schema.name_converter import NameConverter
class EnumNameConverter(NameConverter):
def from_enum_value(self, enum: EnumDefinition, enum_value: EnumValue) -> str:
return f"{super().from_enum_value(enum, enum_value)}_enum_value"
@strawberry.enum
class MyEnum(Enum):
A = "a"
B = "b"
@strawberry.type
class Query:
a_enum: MyEnum
schema = strawberry.Schema(
query=Query,
config=StrawberryConfig(name_converter=EnumNameConverter()),
)
Releases contributed by @patrick91 via #2690
Published by botberry over 1 year ago
This release updates all* the HTTP integration to use the same base class,
which makes it easier to maintain and extend them in future releases.
While this doesn't provide any new features (other than settings headers in
Chalice and Sanic), it does make it easier to extend the HTTP integrations in
the future. So, expect some new features in the next releases!
New features:
Now both Chalice and Sanic integrations support setting headers in the response.
Bringing them to the same level as the other HTTP integrations.
Breaking changes:
Unfortunately, this release does contain some breaking changes, but they are
minimal and should be quick to fix.
get_root_value
and get_context
now receive the requestget_root_value
now receives the request and it is async* The only exception is the channels http integration, which will be updated in
a future release.
Releases contributed by @patrick91 via #2681
Published by botberry over 1 year ago
Fixes type hint for StrawberryTypeFromPydantic._pydantic_type to be a Type instead of an instance of the Pydantic model.
As it is a private API, we still highly discourage using it, but it's now typed correctly.
from pydantic import BaseModel
from typing import Type, List
import strawberry
from strawberry.experimental.pydantic.conversion_types import StrawberryTypeFromPydantic
class User(BaseModel):
name: str
@staticmethod
def foo() -> List[str]:
return ["Patrick", "Pietro", "Pablo"]
@strawberry.experimental.pydantic.type(model=User, all_fields=True)
class UserType:
@strawberry.field
def foo(self: StrawberryTypeFromPydantic[User]) -> List[str]:
# This is now inferred correctly as Type[User] instead of User
# We still highly discourage using this private API, but it's
# now typed correctly
pydantic_type: Type[User] = self._pydantic_type
return pydantic_type.foo()
def get_users() -> UserType:
user: User = User(name="Patrick")
return UserType.from_pydantic(user)
@strawberry.type
class Query:
user: UserType = strawberry.field(resolver=get_users)
schema = strawberry.Schema(query=Query)
Releases contributed by @thejaminator via #2683
Published by botberry over 1 year ago
This releases adds a new extra
group for Starlite, preventing it from being
installed by default.
Releases contributed by @patrick91 via #2664
Published by botberry over 1 year ago
This release adds support for starlite.
import strawberry
from starlite import Request, Starlite
from strawberry.starlite import make_graphql_controller
from strawberry.types.info import Info
def custom_context_getter(request: Request):
return {"custom": "context"}
@strawberry.type
class Query:
@strawberry.field
def hello(self, info: Info[object, None]) -> str:
return info.context["custom"]
schema = strawberry.Schema(Query)
GraphQLController = make_graphql_controller(
schema,
path="/graphql",
context_getter=custom_context_getter,
)
app = Starlite(
route_handlers=[GraphQLController],
)
Releases contributed by @gazorby via #2391
Published by botberry over 1 year ago
This release fixes and issue where you'd get a warning
about using Apollo Federation directives even when using
strawberry.federation.Schema
.
Releases contributed by @patrick91 via #2661
Published by botberry over 1 year ago
This releases adds more type annotations for public functions and methods.
No new changes have been added to the API.
Releases contributed by @JadHADDAD92 via #2627
Published by botberry over 1 year ago
This release adds a warning when using @strawberry.federation.type
but not using strawberry.federation.Schema
Releases contributed by @rubensoleao via #2572
Published by botberry over 1 year ago
Updates the MaskErrors
extension to the new extension API, which was missed previously.
Releases contributed by @N-Maas via #2655