Strawberry-graphql

Latest version: v0.235.0

Safety actively analyzes 638437 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 10 of 122

0.219.1

--------------------

- Improved error message when supplying in incorrect before or after argument with using relay and pagination.
- Add extra PR requirement in README.md

Contributed by [SD](https://github.com/sdobbelaere) via [PR #3361](https://github.com/strawberry-graphql/strawberry/pull/3361/)

0.219.0

--------------------

This release adds support for [litestar](https://litestar.dev/).

python
import strawberry
from litestar import Request, Litestar
from strawberry.litestar 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: strawberry.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 = Litestar(
route_handlers=[GraphQLController],
)


Contributed by [Matthieu MN](https://github.com/gazorby) via [PR #3213](https://github.com/strawberry-graphql/strawberry/pull/3213/)

0.218.1

--------------------

This release fixes a small issue in the GraphQL Transport websocket
where the connection would fail when receiving extra parameters
in the payload sent from the client.

This would happen when using Apollo Sandbox.

Contributed by [Patrick Arminio](https://github.com/patrick91) via [PR #3356](https://github.com/strawberry-graphql/strawberry/pull/3356/)

0.218.0

--------------------

This release adds a new method `get_fields` on the `Schema` class.
You can use `get_fields` to hide certain field based on some conditions,
for example:

python
strawberry.type
class User:
name: str
email: str = strawberry.field(metadata={"tags": ["internal"]})


strawberry.type
class Query:
user: User


def public_field_filter(field: StrawberryField) -> bool:
return "internal" not in field.metadata.get("tags", [])


class PublicSchema(strawberry.Schema):
def get_fields(
self, type_definition: StrawberryObjectDefinition
) -> List[StrawberryField]:
return list(filter(public_field_filter, type_definition.fields))


schema = PublicSchema(query=Query)


The schema here would only have the `name` field on the `User` type.

Contributed by [Patrick Arminio](https://github.com/patrick91) via [PR #3274](https://github.com/strawberry-graphql/strawberry/pull/3274/)

0.217.1

--------------------

This hotfix enables permission extensions to be used with AsyncGenerators.

Contributed by [Erik Wrede](https://github.com/erikwrede) via [PR #3318](https://github.com/strawberry-graphql/strawberry/pull/3318/)

0.217.0

--------------------

Permissions classes now use a `FieldExtension`. The new preferred way to add permissions
is to use the `PermissionsExtension` class:

python
import strawberry
from strawberry.permission import PermissionExtension, BasePermission


class IsAuthorized(BasePermission):
message = "User is not authorized"
error_extensions = {"code": "UNAUTHORIZED"}

def has_permission(self, source, info, **kwargs) -> bool:
return False


strawberry.type
class Query:
strawberry.field(extensions=[PermissionExtension(permissions=[IsAuthorized()])])
def name(self) -> str:
return "ABC"


The old way of adding permissions using `permission_classes` is still
supported via the automatic addition of a `PermissionExtension` on the field.

⚠️ Breaking changes

Previously the `kwargs` argument keys for the `has_permission` method were
using camel casing (depending on your schema configuration), now they will
always follow the python name defined in your resolvers.

python
class IsAuthorized(BasePermission):
message = "User is not authorized"

def has_permission(
self, source, info, **kwargs: typing.Any
) -> bool: pragma: no cover
kwargs will have a key called "a_key"
instead of `aKey`

return False


strawberry.type
class Query:
strawberry.field(permission_classes=[IsAuthorized])
def name(self, a_key: str) -> str: pragma: no cover
return "Erik"


Using the new `PermissionExtension` API, permissions support even more features:

Silent errors

To return `None` or `[]` instead of raising an error, the `fail_silently ` keyword
argument on `PermissionExtension` can be set to `True`.

Custom Error Extensions & classes

Permissions will now automatically add pre-defined error extensions to the error, and
can use a custom `GraphQLError` class. This can be configured by modifying
the `error_class` and `error_extensions` attributes on the `BasePermission` class.

Customizable Error Handling

To customize the error handling, the `on_unauthorized` method on
the `BasePermission` class can be used. Further changes can be implemented by
subclassing the `PermissionExtension` class.

Schema Directives

Permissions will automatically be added as schema directives to the schema. This
behavior can be altered by setting the `add_directives` to `False`
on `PermissionExtension`, or by setting the `_schema_directive` class attribute of the
permission to a custom directive.

Contributed by [Erik Wrede](https://github.com/erikwrede) via [PR #2570](https://github.com/strawberry-graphql/strawberry/pull/2570/)

Page 10 of 122

Links

Releases

Has known vulnerabilities

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.