A GraphQL library for Python that leverages type annotations 🍓
MIT License
Published by botberry about 4 years ago
This release improves support for strawberry.enums when type checking with mypy.
Published by botberry about 4 years ago
Fix ASGI view to call get_context
during a websocket request
Published by botberry about 4 years ago
Add support for adding a description to field arguments using the Annotated
type:
from typing import Annotated
@strawberry.type
class Query:
@strawberry.field
def user_by_id(id: Annotated[str, strawberry.argument(description="The ID of the user")]) -> User:
...
which results in the following schema:
type Query {
userById(
"""The ID of the user"""
id: String
): User!
}
Note: if you are not using Python v3.9 or greater you will need to import Annotated
from typing_extensions
Published by botberry about 4 years ago
This release adds support for using strawberry.enum as a function with MyPy,
this is now valid typed code:
from enum import Enum
import strawberry
class IceCreamFlavour(Enum):
VANILLA = "vanilla"
STRAWBERRY = "strawberry"
CHOCOLATE = "chocolate"
Flavour = strawberry.enum(IceCreamFlavour)
Published by botberry about 4 years ago
Add __str__
to Schema
to allow printing schema sdl with str(schema)
Published by botberry about 4 years ago
Extend support for parsing isoformat datetimes,
adding a dependency on the dateutil
library.
For example: "2020-10-12T22:00:00.000Z"
can now be parsed as a datetime with a UTC timezone.
Published by botberry about 4 years ago
Add schema.introspect()
method to return introspection result of the schema.
This might be useful for tools like apollo codegen
or graphql-voyager
which
expect a full json representation of the schema
Published by botberry about 4 years ago
This releases adds a new extension for OpenTelemetry.
import asyncio
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
ConsoleSpanExporter,
SimpleExportSpanProcessor,
)
import strawberry
from strawberry.extensions.tracing import OpenTelemetryExtension
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
SimpleExportSpanProcessor(ConsoleSpanExporter())
)
@strawberry.type
class User:
name: str
@strawberry.type
class Query:
@strawberry.field
async def user(self, name: str) -> User:
await asyncio.sleep(0.1)
return User(name)
schema = strawberry.Schema(Query, extensions=[OpenTelemetryExtension])
Published by botberry about 4 years ago
This release disables tracing for default resolvers and introspection queries
Published by botberry about 4 years ago
This releases allows UNSET to be used anywhere and prevents mypy to report an error.
Published by botberry about 4 years ago
This releases adds support for strawberry.union inside mypy.
Published by botberry about 4 years ago
This release fixes an issue with the extension runner and async resolvers
Published by botberry about 4 years ago
Fixed bug where you couldn't use the same Union type multiple times in a schema.
Published by botberry about 4 years ago
Added strawberry.Private
type to mark fields as "private" so they don't show up in the GraphQL schema.
Example:
import strawberry
@strawberry.type
class User:
age: strawberry.Private[int]
@strawberry.field
def age_in_months(self) -> int:
return self.age * 12
Published by botberry about 4 years ago
Fix typo in type_resolver.py
Published by botberry about 4 years ago
This release fixes an issue with mypy when doing the following:
import strawberry
@strawberry.type
class User:
name: str = strawberry.field(description='Example')
Published by botberry about 4 years ago
This release adds support for Apollo Tracing and support for creating Strawberry
extensions, here's how you can enable Apollo tracing:
from strawberry.extensions.tracing import ApolloTracingExtension
schema = strawberry.Schema(query=Query, extensions=[ApolloTracingExtension])
And here's an example of custom extension:
from strawberry.extensions import Extension
class MyExtension(Extension):
def get_results(self):
return {
"example": "this is an example for an extension"
}
schema = strawberry.Schema(query=Query, extensions=[MyExtension])
Published by botberry about 4 years ago
This release fixes an issue when trying to print a type
with a UNSET default value
Published by botberry about 4 years ago
UnionDefinition
has been renamed to StrawberryUnion
strawberry.union
now returns an instance of StrawberryUnion
instead of a_union_definition
attribute ofUnionDefinition
.Published by botberry about 4 years ago
This release adds the py.typed
file for better mypy support.