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.165.0

Published by botberry over 1 year ago

Add full support for forward references, specially when using
from __future__ import annotations.

Before the following would fail on python versions older than 3.10:

from __future__ import annotations

import strawberry


@strawberry.type
class Query:
    foo: str | None

Also, this would fail in any python versions:

from __future__ import annotations

from typing import Annotated

import strawberry


@strawberry.type
class Query:
    foo: Annotated[str, "some annotation"]

Now both of these cases are supported.
Please open an issue if you find any edge cases that are still not supported.

Releases contributed by @bellini666 via #2592

strawberry - 🍓 0.164.1

Published by botberry over 1 year ago

Fix interface duplication leading to schema compilation error in multiple
inheritance scenarios (i.e. "Diamond Problem" inheritance)

Thank you @mzhu22 for the thorough bug report!

Releases contributed by @skilkis via #2647

strawberry - 🍓 0.164.0

Published by botberry over 1 year ago

This release introduces a breaking change to make pydantic default behavior consistent with normal strawberry types.
This changes the schema generated for pydantic types, that are required, and have default values.
Previously pydantic type with a default, would get converted to a strawberry type that is not required.
This is now fixed, and the schema will now correctly show the type as required.

import pydantic
import strawberry


class UserPydantic(pydantic.BaseModel):
    name: str = "James"


@strawberry.experimental.pydantic.type(UserPydantic, all_fields=True)
class User:
    ...


@strawberry.type
class Query:
    a: User = strawberry.field()

    @strawberry.field
    def a(self) -> User:
        return User()

The schema is now

type Query {
  a: User!
}

type User {
  name: String! // String! rather than String previously
}

Releases contributed by @thejaminator via #2623

strawberry - 🍓 0.163.2

Published by botberry over 1 year ago

This release covers an edge case where the following would not give a nice error.

some_field: "Union[list[str], SomeType]]"

Fixes #2591

Releases contributed by @nrbnlulu via #2593

strawberry - 🍓 0.163.1

Published by botberry over 1 year ago

Provide close reason to ASGI websocket as specified by ASGI 2.3

Releases contributed by @kristjanvalur via #2639

strawberry - 🍓 0.163.0

Published by botberry over 1 year ago

This release adds support for list arguments in operation directives.

The following is now supported:

@strawberry.directive(locations=[DirectiveLocation.FIELD])
def append_names(
    value: DirectiveValue[str], names: List[str]
):  # note the usage of List here
    return f"{value} {', '.join(names)}"

Releases contributed by @hot123s via #2632

strawberry - 🍓 0.162.0

Published by botberry over 1 year ago

Adds support for a custom field using the approach specified in issue #2168.
Field Extensions may be used to change the way how fields work and what they return.
Use cases might include pagination, permissions or other behavior modifications.

from strawberry.extensions import FieldExtension


class UpperCaseExtension(FieldExtension):
    async def resolve_async(
        self, next: Callable[..., Awaitable[Any]], source: Any, info: Info, **kwargs
    ):
        result = await next(source, info, **kwargs)
        return str(result).upper()


@strawberry.type
class Query:
    @strawberry.field(extensions=[UpperCaseExtension()])
    async def string(self) -> str:
        return "This is a test!!"
query {
    string
}
{
  "string": "THIS IS A TEST!!"
}

Releases contributed by @erikwrede via #2567

strawberry - 🍓 0.161.1

Published by botberry over 1 year ago

Ensure that no other messages follow a "complete" or "error" message
for an operation in the graphql-transport-ws protocol.

Releases contributed by @kristjanvalur via #2600

strawberry - 🍓 0.161.0

Published by botberry over 1 year ago

Calling ChannelsConsumer.channel_listen multiple times will now pass
along the messages being listened for to multiple callers, rather than
only one of the callers, which was the old behaviour.

This resolves an issue where creating multiple GraphQL subscriptions
using a single websocket connection could result in only one of those
subscriptions (in a non-deterministic order) being triggered if they
are listening for channel layer messages of the same type.

Releases contributed by @jthorniley via #2525

strawberry - 🍓 0.160.0

Published by botberry over 1 year ago

Rename Extension to SchemaExtension to pave the way for FieldExtensions.
Importing Extension from strawberry.extensions will now raise a deprecation
warning.

Before:

from strawberry.extensions import Extension

After:

from strawberry.extensions import SchemaExtension

Releases contributed by @jkimbo via #2574

strawberry - 🍓 0.159.1

Published by botberry over 1 year ago

This releases adds support for Mypy 1.1.1

Releases contributed by @patrick91 via #2616

strawberry - 🍓 0.159.0

Published by botberry over 1 year ago

This release changes how extension hooks are defined. The new style hooks are
more flexible and allow to run code before and after the execution.

The old style hooks are still supported but will be removed in future releases.

Before:

def on_executing_start(self):  # Called before the execution start
    ...


def on_executing_end(self):  # Called after the execution ends
    ...

After

def on_execute(self):
    #  This part is called before the execution start
    yield
    #  This part is called after the execution ends

Releases contributed by @nrbnlulu via #2428

strawberry - 🍓 0.158.2

Published by botberry over 1 year ago

Add a type annotation to strawberry.fastapi.BaseContext's __init__ method so that
it can be used without mypy raising an error.

Releases contributed by @SaturnFromTitan via #2581

strawberry - 🍓 0.158.1

Published by botberry over 1 year ago

Version 1.5.10 of GraphiQL disabled introspection for deprecated
arguments because it wasn't supported by all GraphQL server versions.
This PR enables it so that deprecated arguments show up again in
GraphiQL.

Releases contributed by @jkimbo via #2575

strawberry - 🍓 0.158.0

Published by botberry over 1 year ago

Throw proper exceptions when Unions are created with invalid types

Previously, using Lazy types inside of Unions would raise unexpected, unhelpful errors.

Releases contributed by @BryceBeagle via #2540

strawberry - 🍓 0.157.0

Published by botberry over 1 year ago

This releases adds support for Apollo Federation 2.1, 2.2 and 2.3.

This includes support for @composeDirective and @interfaceObject,
we expose directives for both, but we also have shortcuts, for example
to use @composeDirective with a custom schema directive, you can do
the following:

@strawberry.federation.schema_directive(
    locations=[Location.OBJECT], name="cacheControl", compose=True
)
class CacheControl:
    max_age: int

The compose=True makes so that this directive is included in the supergraph
schema.

For @interfaceObject we introduced a new @strawberry.federation.interface_object
decorator. This works like @strawberry.federation.type, but it adds, the appropriate
directive, for example:

@strawberry.federation.interface_object(keys=["id"])
class SomeInterface:
    id: strawberry.ID

generates the following type:

type SomeInterface @key(fields: "id") @interfaceObject {
  id: ID!
}

Releases contributed by @patrick91 via #2549

strawberry - 🍓 0.156.4

Published by botberry over 1 year ago

This release fixes a regression introduce in version 0.156.2 that
would make Mypy throw an error in the following code:

import strawberry


@strawberry.type
class Author:
    name: str


@strawberry.type
class Query:
    @strawberry.field
    async def get_authors(self) -> list[Author]:
        return [Author(name="Michael Crichton")]

Releases contributed by @patrick91 via #2535

strawberry - 🍓 0.156.3

Published by botberry over 1 year ago

This release adds support for Mypy 1.0

Releases contributed by @patrick91 via #2516

strawberry - 🍓 0.156.2

Published by botberry over 1 year ago

This release updates the typing for the resolver argument in
strawberry.fieldi to support async resolvers.
This means that now you won't get any type
error from Pyright when using async resolver, like the following example:

import strawberry


async def get_user_age() -> int:
    return 0


@strawberry.type
class User:
    name: str
    age: int = strawberry.field(resolver=get_user_age)

Releases contributed by @patrick91 via #2528

strawberry - 🍓 0.156.1

Published by botberry over 1 year ago

Add GraphQLWebsocketCommunicator for testing websockets on channels.
i.e:

import pytest
from strawberry.channels.testing import GraphQLWebsocketCommunicator
from myapp.asgi import application


@pytest.fixture
async def gql_communicator():
    async with GraphQLWebsocketCommunicator(
        application=application, path="/graphql"
    ) as client:
        yield client


async def test_subscribe_echo(gql_communicator):
    async for res in gql_communicator.subscribe(
        query='subscription { echo(message: "Hi") }'
    ):
        assert res.data == {"echo": "Hi"}

Releases contributed by @nrbnlulu via #2458

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