A GraphQL library for Python that leverages type annotations 🍓
MIT License
Bot releases are hidden (Show)
Published by botberry about 3 years ago
This release fixes the merge_types
type signature.
Published by botberry about 3 years ago
This release adds support for FastAPI integration using APIRouter.
import strawberry
from fastapi import FastAPI
from strawberry.fastapi import GraphQLRouter
@strawberry.type
class Query:
@strawberry.field
def hello(self) -> str:
return "Hello World"
schema = strawberry.Schema(Query)
graphql_app = GraphQLRouter(schema)
app = FastAPI()
app.include_router(graphql_app, prefix="/graphql")
Published by botberry about 3 years ago
Improve help texts for CLI to work better on ZSH.
Published by botberry about 3 years ago
Errors encountered in subscriptions will now be logged to the strawberry.execution
logger as errors encountered in Queries and Mutations are. <3
Published by botberry about 3 years ago
Add logic to convert arguments of type LazyType.
Published by botberry about 3 years ago
This release fixes a bug where passing scalars in the scalar_overrides
parameter wasn't being applied consistently.
Published by botberry about 3 years ago
Pydantic fields' description
are now copied to the GraphQL schema
import pydantic
import strawberry
class UserModel(pydantic.BaseModel):
age: str = pydantic.Field(..., description="Description")
@strawberry.experimental.pydantic.type(UserModel)
class User:
age: strawberry.auto
type User {
"""Description"""
age: String!
}
Published by botberry about 3 years ago
We now run our tests against Windows during CI!
Published by botberry about 3 years ago
Add a shortcut to merge queries, mutations. E.g.:
import strawberry
from strawberry.tools import merge_types
@strawberry.type
class QueryA:
...
@strawberry.type
class QueryB:
...
ComboQuery = merge_types("ComboQuery", (QueryB, QueryA))
schema = strawberry.Schema(query=ComboQuery)
Published by botberry about 3 years ago
Makes the GraphQLSchema instance accessible from resolvers via the info
parameter.
Published by botberry about 3 years ago
Fix bug where errors thrown in the on_parse_* extension hooks were being
swallowed instead of being propagated.
Published by botberry about 3 years ago
Adds support for the auto
type annotation described in #1192 to the Pydantic
integration, which allows a user to define the list of fields without having to
re-specify the type themselves. This gives better editor and type checker
support. If you want to expose every field you can instead pass
all_fields=True
to the decorators and leave the body empty.
import pydantic
import strawberry
from strawberry.experimental.pydantic import auto
class User(pydantic.BaseModel):
age: int
password: str
@strawberry.experimental.pydantic.type(User)
class UserType:
age: auto
password: auto
Published by botberry about 3 years ago
This release adds a safety check on strawberry.type
, strawberry.input
and
strawberry.interface
decorators. When you try to use them with an object that is not a
class, you will get a nice error message:
strawberry.type can only be used with classes
Published by botberry about 3 years ago
Add Starlette
to the integrations section on the documentation.
Published by botberry about 3 years ago
This release add support for the upcoming python 3.10 and it adds support
for the new union syntax, allowing to declare unions like this:
import strawberry
@strawberry.type
class User:
name: str
@strawberry.type
class Error:
code: str
@strawberry.type
class Query:
find_user: User | Error
Published by botberry about 3 years ago
This release adds support for the graphql-transport-ws
GraphQL over WebSocket
protocol. Previously Strawberry only supported the legacy graphql-ws
protocol.
Developers can decide which protocols they want to accept. The following example shows
how to do so using the ASGI integration. By default, both protocols are accepted.
Take a look at our GraphQL subscription documentation to learn more.
from strawberry.asgi import GraphQL
from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL
from api.schema import schema
app = GraphQL(schema, subscription_protocols=[GRAPHQL_TRANSPORT_WS_PROTOCOL])
Published by botberry about 3 years ago
Nests the resolver under the correct span; prior to this change your span would have looked something like:
GraphQL Query
GraphQL Parsing
GraphQL Validation
my_resolver
my_span_of_interest #1
my_sub_span_of_interest #2
After this change you'll have:
GraphQL Query
GraphQL Parsing
GraphQL Validation
GraphQL Resolving: my_resolver
my_span_of_interest #1
my_sub_span_of_interest #2
Published by botberry about 3 years ago
Enhances strawberry.extensions.tracing.opentelemetry to include spans for the Parsing and Validation phases of request handling. These occur before your resovler is called, so now you can see how much time those phases take up!
Published by botberry about 3 years ago
Fix extensions
argument type definition on strawberry.Schema
Published by botberry about 3 years ago
This release introduces some brand new extensions to help improve the
performance of your GraphQL server:
ParserCache
- Cache the parsing of a query in memoryValidationCache
- Cache the validation step of executionFor complicated queries these 2 extensions can improve performance by over 50%!
Example:
import strawberry
from strawberry.extensions import ParserCache, ValidationCache
schema = strawberry.Schema(
Query,
extensions=[
ParserCache(),
ValidationCache(),
]
)
This release also removes the validate_queries
and validation_rules
parameters on the schema.execute*
methods in favour of using the
DisableValidation
and AddValidationRule
extensions.