strawberry

A GraphQL library for Python that leverages type annotations 🍓

MIT License

Downloads
1.1M
Stars
3.8K
Committers
260
strawberry - Strawberry 0.32.3

Published by botberry about 4 years ago

This release fixes another issue with extending types.

strawberry - Strawberry 0.32.2

Published by botberry about 4 years ago

This releases fixes an issue when extending types, now
fields should work as they were working before even
when extending an exising type.

strawberry - Strawberry 0.32.1

Published by botberry about 4 years ago

Improves tooling by adding flake8-eradicate to flake8 pre-commit hook..

strawberry - Strawberry 0.32.0

Published by botberry about 4 years ago

Previously, strawberry.field had redundant arguments for the resolver, one for
when strawberry.field was used as a decorator, and one for when it was used as
a function. These are now combined into a single argument.

The f argument of strawberry.field no longer exists. This is a
backwards-incompatible change, but should not affect many users. The f
argument was the first argument for strawberry.field and its use was only
documented without the keyword. The fix is very straight-forward: replace any
f= kwarg with resolver=.

@strawberry.type
class Query:
    
    my_int: int = strawberry.field(f=lambda: 5)
    # becomes
    my_int: int = strawberry.field(resolver=lambda: 5)

    # no change
    @strawberry.field
    def my_float(self) -> float:
        return 5.5

Other (minor) breaking changes

  • MissingArgumentsAnnotationsError's message now uses the original Python
    field name instead of the GraphQL field name. The error can only be thrown while
    instantiating a strawberry.field, so the Python field name should be more
    helpful.
  • As a result, strawberry.arguments.get_arguments_from_resolver() now only
    takes one field -- the resolver Callable.
  • MissingFieldAnnotationError is now thrown when a strawberry.field is not
    type-annotated but also has no resolver to determine its type
strawberry - Strawberry 0.31.1

Published by botberry about 4 years ago

This release fixes the Flask view that was returning 400 when there were errors
in the GraphQL results. Now it always returns 200.

strawberry - Strawberry 0.31.0

Published by botberry about 4 years ago

Add process_result to views for Django, Flask and ASGI. They can be overriden
to provide a custom response and also to process results and errors.

It also removes request from Flask view's get_root_value and get_context
since request in Flask is a global.

Django example:

# views.py
from django.http import HttpRequest
from strawberry.django.views import GraphQLView as BaseGraphQLView
from strawberry.http import GraphQLHTTPResponse
from strawberry.schema import ExecutionResult

class GraphQLView(BaseGraphQLView):
    def process_result(self, request: HttpRequest, result: ExecutionResult) -> GraphQLHTTPResponse:
        return {"data": result.data, "errors": result.errors or []}

Flask example:

# views.py
from strawberry.flask.views import GraphQLView as BaseGraphQLView
from strawberry.http import GraphQLHTTPResponse
from strawberry.schema import ExecutionResult

class GraphQLView(BaseGraphQLView):
    def process_result(self, result: ExecutionResult) -> GraphQLHTTPResponse:
        return {"data": result.data, "errors": result.errors or []}

ASGI example:

from strawberry.asgi import GraphQL as BaseGraphQL
from strawberry.http import GraphQLHTTPResponse
from strawberry.schema import ExecutionResult
from starlette.requests import Request

from .schema import schema

class GraphQL(BaseGraphQLView):
    async def process_result(self, request: Request, result: ExecutionResult) -> GraphQLHTTPResponse:
        return {"data": result.data, "errors": result.errors or []}

strawberry - Strawberry 0.30.1

Published by botberry about 4 years ago

This releases fixes the check for unset values.

strawberry - Strawberry 0.30.0

Published by botberry about 4 years ago

Add functions get_root_value and get_context to views for Django, Flask and
ASGI. They can be overriden to provide custom values per request.

Django example:

# views.py
from strawberry.django.views import GraphQLView as BaseGraphQLView

class GraphQLView(BaseGraphQLView):
    def get_context(self, request):
        return {
            "request": request,
            "custom_context_value": "Hi!",
        }

    def get_root_value(self, request):
        return {
            "custom_root_value": "🍓",
        }


# urls.py
from django.urls import path

from .views import GraphQLView
from .schema import schema

urlpatterns = [
    path("graphql/", GraphQLView.as_view(schema=schema)),
]

Flask example:

# views.py
from strawberry.flask.views import GraphQLView as BaseGraphQLView

class GraphQLView(BaseGraphQLView):
    def get_context(self, request):
        return {
            "request": request,
            "custom_context_value": "Hi!",
        }

    def get_root_value(self, request):
        return {
            "custom_root_value": "🍓",
        }


# app.py
from flask import Flask

from .views import GraphQLView
from .schema import schema

app = Flask(__name__)

app.add_url_rule(
    "/graphql",
    view_func=GraphQLView.as_view("graphql_view", schema=schema),
)

ASGI example:

# app.py
from strawberry.asgi import GraphQL as BaseGraphQL

from .schema import schema

class GraphQL(BaseGraphQLView):
    async def get_context(self, request):
        return {
            "request": request,
            "custom_context_value": "Hi!",
        }

    async def get_root_value(self, request):
        return {
            "custom_root_value": "🍓",
        }


app = GraphQL(schema)
strawberry - Strawberry 0.29.1

Published by botberry about 4 years ago

Support for default_value on inputs.

Usage:

class MyInput:
    s: Optional[str] = None
    i: int = 0
input MyInput {
  s: String = null
  i: Int! = 0
}
strawberry - Strawberry 0.29.0

Published by botberry about 4 years ago

This release adds support for file uploads within Django.

We follow the following spec: https://github.com/jaydenseric/graphql-multipart-request-spec

Example:

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

Published by botberry about 4 years ago

Fix issue when reusing an interface

strawberry - Strawberry 0.28.4

Published by botberry about 4 years ago

Fix issue when using generic types with federation

strawberry - Strawberry 0.28.3

Published by botberry about 4 years ago

Add support for using lazy types inside generics.

strawberry - Strawberry 0.28.2

Published by botberry about 4 years ago

This releae add support for UUID as field types. They will be
represented as GraphQL ID in the GraphQL schema.

strawberry - Strawberry 0.28.1

Published by botberry about 4 years ago

This release fixes support for PEP-563, now you can safely use from __future__ import annotations,
like the following example:

from __future__ import annotations

@strawberry.type
class Query:
    me: MyType = strawberry.field(name="myself")

@strawberry.type
class MyType:
    id: strawberry.ID

strawberry - Strawberry 0.28.0

Published by botberry about 4 years ago

This releases brings a much needed internal refactor of how we generate
GraphQL types from class definitions. Hopefully this will make easier to
extend Strawberry in future.

There are some internal breaking changes, so if you encounter any issue
let us know and well try to help with the migration.

In addition to the internal refactor we also fixed some bugs and improved
the public api for the schema class. Now you can run queries directly
on the schema by running schema.execute, schema.execute_sync and
schema.subscribe on your schema.

strawberry - Strawberry 0.27.5

Published by botberry over 4 years ago

Add websocket object to the subscription context.

strawberry - Strawberry 0.27.4

Published by botberry over 4 years ago

This PR fixes a bug when declaring multiple non-named union types

strawberry - Strawberry 0.27.3

Published by botberry over 4 years ago

Optimized signature reflection and added benchmarks.

strawberry - Strawberry 0.27.2

Published by botberry over 4 years ago

This release fixes an issue when using named union types in generic types,
for example using an optional union. This is now properly supported:

@strawberry.type
class A:
    a: int

@strawberry.type
class B:
    b: int

Result = strawberry.union("Result", (A, B))

@strawberry.type
class Query:
    ab: Optional[Result] = None
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