A GraphQL library for Python that leverages type annotations 🍓
MIT License
Bot releases are hidden (Show)
Published by botberry over 2 years ago
Allow to add alias to fields generated from pydantic with strawberry.field(name="ageAlias")
.
class User(pydantic.BaseModel):
age: int
@strawberry.experimental.pydantic.type(User)
class UserType:
age: strawberry.auto = strawberry.field(name="ageAlias")
Published by botberry over 2 years ago
This release fixes an issue that required installing opentelemetry when
trying to use the ApolloTracing extension
Published by botberry over 2 years ago
Fix regression caused by the new resolver argument handling mechanism
introduced in v0.115.0. This release restores the ability to use unhashable
default values in resolvers such as dict and list. See example below:
@strawberry.type
class Query:
@strawberry.field
def field(
self, x: List[str] = ["foo"], y: JSON = {"foo": 42} # noqa: B006
) -> str:
return f"{x} {y}"
Thanks to @coady for the regression report!
Published by botberry over 2 years ago
This release fixes the following error when trying to use Strawberry
with Apollo Federation:
Error: A valid schema couldn't be composed. The following composition errors were found:
[burro-api] Unknown type _FieldSet
Published by botberry over 2 years ago
Reimplement StrawberryResolver.annotations
property after removal in v0.115.
Library authors who previously relied on the public annotations
property
can continue to do so after this fix.
Published by botberry over 2 years ago
This release fixes a breaking internal error in mypy plugin for the following case.
strawberry.field()
or strawberry.mutation()
failed: str = strawberry.field(resolver)
successed: str = strawberry.field(resolver=resolver)
now mypy returns an error with "field()" or "mutation()" only takes keyword arguments
message
rather than an internal error.
Published by botberry over 2 years ago
This release adds a link from generated GraphQLCore types to the Strawberry type
that generated them.
From a GraphQLCore type you can now access the Strawberry type by doing:
strawberry_type: TypeDefinition = graphql_core_type.extensions[GraphQLCoreConverter.DEFINITION_BACKREF]
Published by botberry over 2 years ago
This release changes how we declare the info
argument in resolvers and the
value
argument in directives.
Previously we'd use the name of the argument to determine its value. Now we use
the type annotation of the argument to determine its value.
Here's an example of how the old syntax works:
def some_resolver(info) -> str:
return info.context.get("some_key", "default")
@strawberry.type
class Example:
a_field: str = strawberry.resolver(some_resolver)
and here's an example of how the new syntax works:
from strawberry.types import Info
def some_resolver(info: Info) -> str:
return info.context.get("some_key", "default")
@strawberry.type
class Example:
a_field: str = strawberry.resolver(some_resolver)
This means that you can now use a different name for the info
argument in your
resolver and the value
argument in your directive.
Here's an example that uses a custom name for both the value and the info
parameter in directives:
from strawberry.types import Info
from strawberry.directive import DirectiveLocation, DirectiveValue
@strawberry.type
class Cake:
frosting: Optional[str] = None
flavor: str = "Chocolate"
@strawberry.type
class Query:
@strawberry.field
def cake(self) -> Cake:
return Cake()
@strawberry.directive(
locations=[DirectiveLocation.FIELD],
description="Add frosting with ``value`` to a cake.",
)
def add_frosting(value: str, v: DirectiveValue[Cake], my_info: Info):
# Arbitrary argument name when using `DirectiveValue` is supported!
assert isinstance(v, Cake)
if value in my_info.context["allergies"]: # Info can now be accessed from directives!
raise AllergyError("You are allergic to this frosting!")
else:
v.frosting = value # Value can now be used as a GraphQL argument name!
return v
Note: the old way of passing arguments by name is deprecated and will be
removed in future releases of Strawberry.
Published by botberry over 2 years ago
Allow use of implicit Any
in strawberry.Private
annotated Generic types.
For example the following is now supported:
from __future__ import annotations
from typing import Generic, Sequence, TypeVar
import strawberry
T = TypeVar("T")
@strawberry.type
class Foo(Generic[T]):
private_field: strawberry.Private[Sequence] # instead of Sequence[Any]
@strawberry.type
class Query:
@strawberry.field
def foo(self) -> Foo[str]:
return Foo(private_field=[1, 2, 3])
See Issue #1938
for details.
Published by botberry over 2 years ago
The federation decorator now allows for a list of additional arbitrary schema
directives extending the key/shareable directives used for federation.
Example Python:
import strawberry
from strawberry.schema.config import StrawberryConfig
from strawberry.schema_directive import Location
@strawberry.schema_directive(locations=[Location.OBJECT])
class CacheControl:
max_age: int
@strawberry.federation.type(
keys=["id"], shareable=True, extend=True, directives=[CacheControl(max_age=42)]
)
class FederatedType:
id: strawberry.ID
schema = strawberry.Schema(
query=Query, config=StrawberryConfig(auto_camel_case=False)
)
Resulting GQL Schema:
directive @CacheControl(max_age: Int!) on OBJECT
directive @key(fields: _FieldSet!, resolvable: Boolean) on OBJECT | INTERFACE
directive @shareable on FIELD_DEFINITION | OBJECT
extend type FederatedType
@key(fields: "id")
@shareable
@CacheControl(max_age: 42) {
id: ID!
}
type Query {
federatedType: FederatedType!
}
Published by botberry over 2 years ago
This release adds support in Mypy for using strawberry.mutation
while passing a resolver, the following now doesn't make Mypy return
an error:
import strawberry
def set_name(self, name: str) -> None:
self.name = name
@strawberry.type
class Mutation:
set_name: None = strawberry.mutation(resolver=set_name)
Published by botberry over 2 years ago
This release fixes the type annotation of Response.errors
used in the GraphQLTestClient
to be a List
of GraphQLFormattedError
.
Published by botberry over 2 years ago
This release fixes the type annotation of Response.errors
used in the GraphQLTestClient
to be a List
of GraphQLError
.
Published by botberry over 2 years ago
This release fixes an issue in the GraphQLTestClient
when using both variables and files together.
Published by botberry over 2 years ago
Fix crash in Django's HttpResponse.__repr__
by handling status_code=None
in TemporalHttpResponse.__repr__
.
Published by botberry over 2 years ago
Improve schema directives typing and printing after latest refactor.
strawberry.field
, strawberry.type
, etc)StrawberrySchemaDirective
, which is now an internal type.Published by botberry over 2 years ago
This release adds support for Starlette 0.18 to 0.20
It also removes upper bound dependencies limit for starlette,
allowing you to install the latest version without having to
wait for a new release of Strawberry.
This release was contributed by @TimPansino in https://github.com/strawberry-graphql/strawberry/pull/1594
Published by botberry over 2 years ago
This release adds a new flask view to allow for aysnc dispatching of requests.
This is especially useful when using dataloaders with flask.
from strawberry.flask.views import AsyncGraphQLView
...
app.add_url_rule("/graphql", view_func=AsyncGraphQLView.as_view("graphql_view", schema=schema, **kwargs))
Release contributed by @scottweitzner in #1907
Published by botberry over 2 years ago
This release fixes resolvers using functions with generic type variables raising a MissingTypesForGenericError
error.
For example a resolver factory like the below can now be used:
import strawberry
from typing import Type, TypeVar
T = TypeVar("T") # or TypeVar("T", bound=StrawberryType) etc
def resolver_factory(strawberry_type: Type[T]):
def resolver(id: strawberry.ID) -> T:
# some actual logic here
return strawberry_type(...)
return resolver
Release contributed by @invokermain in #1891
Published by botberry over 2 years ago
Rename internal variable custom_getter
in FastAPI router implementation.
Releases contributed by @garyd203 via #1875