A GraphQL library for Python that leverages type annotations 🍓
MIT License
Published by botberry about 3 years ago
This releases fixes a MyPy issue that prevented from using types created with
create_type
as base classes. This is now allowed and doesn't throw any error:
import strawberry
from strawberry.tools import create_type
@strawberry.field
def name() -> str:
return "foo"
MyType = create_type("MyType", [name])
class Query(MyType):
...
Published by botberry about 3 years ago
This release fixes an import error when trying to import create_type
without having opentelemetry
installed.
Published by botberry about 3 years ago
This release adds support for the latest version of the optional opentelemetry dependency.
Published by botberry about 3 years ago
This release adds support for the latest version of the optional opentelemetry dependency.
Published by botberry about 3 years ago
This release allows background tasks to be set with the ASGI integration. Tasks can be set on the response in the context, and will then get run after the query result is returned.
from starlette.background import BackgroundTask
@strawberry.mutation
def create_flavour(self, info: Info) -> str:
info.context["response"].background = BackgroundTask(...)
Published by botberry about 3 years ago
This release caches attributes on the Info
type which aren't delegated to the core info object.
Published by botberry about 3 years ago
This releases fixes an issue where you were not allowed
to use duck typing and return a different type that the
type declared on the field when the type was implementing
an interface. Now this works as long as you return a type
that has the same shape as the field type.
Published by botberry about 3 years ago
This release improves execution performance significantly by lazy loading
attributes on the Info
type 🏎
Published by botberry about 3 years ago
This release adds support for asynchronous hooks to the Strawberry extension-system.
All available hooks can now be implemented either synchronously or asynchronously.
It's also possible to mix both synchronous and asynchronous hooks within one extension.
from strawberry.extensions import Extension
class MyExtension(Extension):
async def on_request_start(self):
print("GraphQL request start")
def on_request_end(self):
print("GraphQL request end")
Published by botberry about 3 years ago
This release refactors the reload feature of the built-in debug server. The refactor
made the debug server more responsive and allowed us to remove hupper
from the
dependencies.
Published by botberry about 3 years ago
This releases pins graphql-core to only accept patch versions in order to prevent breaking changes since graphql-core doesn't properly follow semantic versioning.
Published by botberry about 3 years ago
This release improves the default logging format for errors to include more information about the errors. For example it will show were an error was originated in a request:
GraphQL request:2:5
1 | query {
2 | example
| ^
3 | }
Published by botberry about 3 years ago
This release adds support for asynchronous permission classes. The only difference to
their synchronous counterpart is that the has_permission
method is asynchronous.
from strawberry.permission import BasePermission
class IsAuthenticated(BasePermission):
message = "User is not authenticated"
async def has_permission(self, source, info, **kwargs):
return True
Published by botberry about 3 years ago
Get a field resolver correctly when extending from a pydantic model
Published by botberry about 3 years ago
This release adds asgi
as an extra dependencies group for Strawberry. Now
you can install the required dependencies needed to use Strawberry with
ASGI by running:
pip install strawberry[asgi]
Published by botberry about 3 years ago
This releases adds selected_fields
on the info
objects and it
allows to introspect the fields that have been selected in a GraphQL
operation.
This can become useful to run optimisation based on the queried fields.
Published by botberry about 3 years ago
This release adds a query depth limit validation rule so that you can guard
against malicious queries:
import strawberry
from strawberry.schema import default_validation_rules
from strawberry.tools import depth_limit_validator
# Add the depth limit validator to the list of default validation rules
validation_rules = (
default_validation_rules + [depth_limit_validator(3)]
)
result = schema.execute_sync(
"""
query MyQuery {
user {
pets {
owner {
pets {
name
}
}
}
}
}
""",
validation_rules=validation_rules,
)
)
assert len(result.errors) == 1
assert result.errors[0].message == "'MyQuery' exceeds maximum operation depth of 3"
Published by botberry about 3 years ago
Addition of app.add_websocket_route("/subscriptions", graphql_app)
to FastAPI example docs
Published by botberry about 3 years ago
This release changes how we map Pydantic fields to types
to allow using older version of Pydantic.
Published by botberry about 3 years ago
This release makes the strawberry server
command inform the user about missing
dependencies required by the builtin debug server.
Also hupper
a package only used by said command has been made optional.