strawberry

A GraphQL library for Python that leverages type annotations 🍓

MIT License

Downloads
1.1M
Stars
3.8K
Committers
260

Bot releases are hidden (Show)

strawberry - 🍓 0.176.0

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

strawberry - 🍓 0.175.1

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

strawberry - 🍓 0.175.0

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

strawberry - 🍓 0.174.0

Published by botberry over 1 year ago

This PR adds a MaxTokensLimiter extension which limits the number of tokens in a GraphQL document.

Usage example:

import strawberry
from strawberry.extensions import MaxTokensLimiter

schema = strawberry.Schema(
    Query,
    extensions=[
        MaxTokensLimiter(max_token_count=1000),
    ],
)
strawberry - 🍓 0.173.1

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

strawberry - 🍓 0.173.0

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

strawberry - 🍓 0.172.0

Published by botberry over 1 year ago

This PR adds a MaxAliasesLimiter extension which limits the number of aliases in a GraphQL document.

Usage example:

import strawberry
from strawberry.extensions import MaxAliasesLimiter

schema = strawberry.Schema(
    Query,
    extensions=[
        MaxAliasesLimiter(max_alias_count=15),
    ],
)

Releases contributed by @reka via #2726

strawberry - 🍓 0.171.3

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

strawberry - 🍓 0.171.2

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

strawberry - 🍓 0.171.1

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

strawberry - 🍓 0.171.0

Published by botberry over 1 year ago

This release adds support for Mypy 1.2.0

Releases contributed by @patrick91 via #2693

strawberry - 🍓 0.170.0

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

strawberry - 🍓 0.169.0

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.

  1. Flask get_root_value and get_context now receive the request
  2. Sanic get_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

strawberry - 🍓 0.168.2

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

strawberry - 🍓 0.168.1

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

strawberry - 🍓 0.168.0

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

strawberry - 🍓 0.167.1

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

strawberry - 🍓 0.167.0

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

strawberry - 🍓 0.166.0

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

strawberry - 🍓 0.165.1

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

Package Rankings
Top 1.15% on Pypi.org
Top 16.1% on Conda-forge.org
Badges
Extracted from project README
CircleCI Discord PyPI
Related Projects