A GraphQL library for Python that leverages type annotations 🍓
MIT License
Published by botberry about 4 years ago
This release fixes another issue with extending types.
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.
Published by botberry about 4 years ago
Improves tooling by adding flake8-eradicate
to flake8
pre-commit
hook..
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 Pythonstrawberry.arguments.get_arguments_from_resolver()
now onlyresolver
Callable.MissingFieldAnnotationError
is now thrown when a strawberry.field is notPublished 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.
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 []}
Published by botberry about 4 years ago
This releases fixes the check for unset values.
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)
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
}
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()
Published by botberry about 4 years ago
Fix issue when reusing an interface
Published by botberry about 4 years ago
Fix issue when using generic types with federation
Published by botberry about 4 years ago
Add support for using lazy types inside generics.
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.
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
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.
Published by botberry over 4 years ago
Add websocket object to the subscription context.
Published by botberry over 4 years ago
This PR fixes a bug when declaring multiple non-named union types
Published by botberry over 4 years ago
Optimized signature reflection and added benchmarks.
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