strawberry

A GraphQL library for Python that leverages type annotations 🍓

MIT License

Downloads
1.1M
Stars
3.8K
Committers
260
strawberry - 🍓 0.65.0

Published by botberry over 3 years ago

This release extends the file upload support of all integrations to support the upload
of file lists.

Here is an example how this would work with the ASGI integration.

import typing
import strawberry
from strawberry.file_uploads import Upload


@strawberry.type
class Mutation:
    @strawberry.mutation
    async def read_files(self, files: typing.List[Upload]) -> typing.List[str]:
        contents = []
        for file in files:
            content = (await file.read()).decode()
            contents.append(content)
        return contents

Check out the documentation to learn how the same can be done with other integrations.

strawberry - 🍓 0.64.5

Published by botberry over 3 years ago

This release fixes that AIOHTTP subscription requests were not properly separated.
This could lead to subscriptions terminating each other.

strawberry - 🍓 0.64.4

Published by botberry over 3 years ago

  • Remove usages of undefined in favour of UNSET
  • Change the signature of StrawberryField to make it easier to instantiate
    directly. Also change default_value argument to default
  • Rename default_value to default in StrawberryArgument
strawberry - 🍓 0.64.3

Published by botberry over 3 years ago

This release integrates the strawberry-graphql-django package into Strawberry
core so that it's possible to use the Django extension package directly via the
strawberry.django namespace.

You still need to install strawberry-graphql-django if you want to use the
extended Django support.

See: https://github.com/strawberry-graphql/strawberry-graphql-django

strawberry - 🍓 0.64.2

Published by botberry over 3 years ago

This release fixes that enum values yielded from async generators were not resolved
properly.

strawberry - 🍓 0.64.1

Published by botberry over 3 years ago

This release fixes a max recursion depth error in the AIOHTTP subscription
implementation.

strawberry - 🍓 0.64.0

Published by botberry over 3 years ago

This release adds an extensions field to the GraphQLHTTPResponse type and also exposes it in the view's response.

This field gets populated by Strawberry extensions: https://strawberry.rocks/docs/guides/extensions#get-results

strawberry - 🍓 0.63.2

Published by botberry over 3 years ago

Add root_value to ExecutionContext type so that it can be accessed in
extensions.

Example:

import strawberry
from strawberry.extensions import Extension

class MyExtension(Extension):
    def on_request_end(self):
        root_value = self.execution_context.root_value
        # do something with the root_value
strawberry - 🍓 0.63.1

Published by botberry over 3 years ago

New deployment process to release new Strawberry releases

strawberry - Strawberry 0.63.0

Published by botberry over 3 years ago

This release adds extra values to the ExecutionContext object so that it can be
used by extensions and the Schema.process_errors function.

The full ExecutionContext object now looks like this:

from graphql import ExecutionResult as GraphQLExecutionResult
from graphql.error.graphql_error import GraphQLError
from graphql.language import DocumentNode as GraphQLDocumentNode

@dataclasses.dataclass
class ExecutionContext:
    query: str
    context: Any = None
    variables: Optional[Dict[str, Any]] = None
    operation_name: Optional[str] = None

    graphql_document: Optional[GraphQLDocumentNode] = None
    errors: Optional[List[GraphQLError]] = None
    result: Optional[GraphQLExecutionResult] = None

and can be accessed in any of the extension hooks:

from strawberry.extensions import Extension

class MyExtension(Extension):
    def on_request_end(self):
        result = self.execution_context.result
        # Do something with the result

schema = strawberry.Schema(query=Query, extensions=[MyExtension])

Note: This release also removes the creation of an ExecutionContext object in the web
framework views. If you were relying on overriding the get_execution_context
function then you should change it to get_request_data and use the
strawberry.http.parse_request_data function to extract the pieces of data
needed from the incoming request.

strawberry - Strawberry 0.62.1

Published by botberry over 3 years ago

This releases fixes an issue with the debug server that prevented the
usage of dataloaders, see: https://github.com/strawberry-graphql/strawberry/issues/940

strawberry - Strawberry 0.62.0

Published by botberry over 3 years ago

This release adds support for GraphQL subscriptions to the AIOHTTP integration.
Subscription support works out of the box and does not require any additional
configuration.

Here is an example how to get started with subscriptions in general. Note that by
specification GraphQL schemas must always define a query, even if only subscriptions
are used.

import asyncio
import typing
import strawberry


@strawberry.type
class Subscription:
    @strawberry.subscription
    async def count(self, target: int = 100) -> typing.AsyncGenerator[int, None]:
        for i in range(target):
            yield i
            await asyncio.sleep(0.5)


@strawberry.type
class Query:
    @strawberry.field
    def _unused(self) -> str:
        return ""


schema = strawberry.Schema(subscription=Subscription, query=Query)
strawberry - Strawberry 0.61.3

Published by botberry over 3 years ago

Fix @requires(fields: ["email"]) and @provides(fields: ["name"]) usage on a Federation field

You can use @requires to specify which fields you need to resolve a field

import strawberry

@strawberry.federation.type(keys=["id"], extend=True)
class Product:
    id: strawberry.ID = strawberry.federation.field(external=True)
    code: str = strawberry.federation.field(external=True)

    @classmethod
    def resolve_reference(cls, id: strawberry.ID, code: str):
        return cls(id=id, code=code)

    @strawberry.federation.field(requires=["code"])
    def my_code(self) -> str:
        return self.code

@provides can be used to specify what fields are going to be resolved
by the service itself without having the Gateway to contact the external service
to resolve them.

strawberry - Strawberry 0.61.2

Published by botberry over 3 years ago

This release adds support for the info param in resolve_reference:

@strawberry.federation.type(keys=["upc"])
class Product:
    upc: str
    info: str

    @classmethod
    def resolve_reference(cls, info, upc):
        return Product(upc, info)

Note: resolver reference is used when using Federation, similar to Apollo server's __resolveReference

strawberry - Strawberry 0.61.1

Published by botberry over 3 years ago

This release extends the strawberry server command to allow the specification
of a schema symbol name within a module:

strawberry server mypackage.mymodule:myschema

The schema symbol name defaults to schema making this change backwards compatible.

strawberry - Strawberry 0.61.0

Published by botberry over 3 years ago

This release adds file upload support to the Sanic
integration. No additional configuration is required to enable file upload support.

The following example shows how a file upload based mutation could look like:

import strawberry
from strawberry.file_uploads import Upload


@strawberry.type
class Mutation:
    @strawberry.mutation
    def read_text(self, text_file: Upload) -> str:
        return text_file.read().decode()
strawberry - Strawberry 0.60.0

Published by botberry over 3 years ago

This release adds an export-schema command to the Strawberry CLI.
Using the command you can print your schema definition to your console.
Pipes and redirection can be used to store the schema in a file.

Example usage:

strawberry export-schema mypackage.mymodule:myschema > schema.graphql
strawberry - Strawberry 0.59.1

Published by botberry over 3 years ago

This release fixes an issue that prevented using source as name of an argument

strawberry - Strawberry 0.59.0

Published by botberry over 3 years ago

This release adds an aiohttp integration for
Strawberry. The integration provides a GraphQLView class which can be used to
integrate Strawberry with aiohttp:

import strawberry
from aiohttp import web
from strawberry.aiohttp.views import GraphQLView


@strawberry.type
class Query:
    pass


schema = strawberry.Schema(query=Query)

app = web.Application()

app.router.add_route("*", "/graphql", GraphQLView(schema=schema))
strawberry - Strawberry 0.58.0

Published by botberry over 3 years ago

This release adds a function called create_type to create a Strawberry type from a list of fields.

import strawberry
from strawberry.tools import create_type

@strawberry.field
def hello(info) -> str:
    return "World"

def get_name(info) -> str:
    return info.context.user.name

my_name = strawberry.field(name="myName", resolver=get_name)

Query = create_type("Query", [hello, my_name])

schema = strawberry.Schema(query=Query)
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