Strawberry GraphQL @ 0.278.0
Released
Add GraphQL Query batching support
GraphQL query batching is now supported across all frameworks (sync and async)
To enable query batching, add a valid batching_config
to the schema configuration.
This makes your GraphQL API compatible with batching features supported by various client side libraries, such as Apollo GraphQL and Relay .
Example (FastAPI):
import strawberry
from fastapi import FastAPI
from strawberry.fastapi import GraphQLRouter
from strawberry.schema.config import StrawberryConfig
@strawberry.type
class Query:
@strawberry.field
def hello(self) -> str:
return "Hello World"
schema = strawberry.Schema(
Query, config=StrawberryConfig(batching_config={"max_operations": 10})
)
graphql_app = GraphQLRouter(schema)
app = FastAPI()
app.include_router(graphql_app, prefix="/graphql")
Example (Flask):
import strawberry
from flask import Flask
from strawberry.flask.views import GraphQLView
app = Flask(__name__)
@strawberry.type
class Query:
@strawberry.field
def hello(self) -> str:
return "Hello World"
schema = strawberry.Schema(
Query, config=StrawberryConfig(batching_config={"max_operations": 10})
)
app.add_url_rule(
"/graphql/batch",
view_func=GraphQLView.as_view("graphql_view", schema=schema),
)
if __name__ == "__main__":
app.run()
Note: Query Batching is not supported for multipart subscriptions
Releases contributed by @aryaniyaps via #3755