A GraphQL library for Python that leverages type annotations 🍓
MIT License
Bot releases are hidden (Show)
Published by botberry over 1 year ago
This release adds support for properly resolving lazy references
when using forward refs.
For example, this code should now work without any issues:
from __future__ import annotations
from typing import TYPE_CHECKING, Annotated
if TYPE_CHECKING:
from some.module import OtherType
@strawberry.type
class MyType:
@strawberry.field
async def other_type(self) -> Annotated[OtherType, strawberry.lazy("some.module")]:
...
Releases contributed by @bellini666 via #2744
Published by botberry over 1 year ago
This release fixes a bug in fragment codegen to pick up type definitions from the proper place
in the schema.
Releases contributed by @mgilson via #2805
Published by botberry over 1 year ago
Custom codegen plugins will fail to write files if the plugin is trying to put the
file anywhere other than the root output directory (since the child directories do
not yet exist). This change will create the child directory if necessary before
attempting to write the file.
Releases contributed by @mgilson via #2806
Published by botberry over 1 year ago
This release updates the built-in GraphiQL to the current latest version 2.4.7 and improves styling for the GraphiQL Explorer Plugin.
Releases contributed by @kiendang via #2804
Published by botberry over 1 year ago
In this release codegen no longer chokes on queries that use a fragment.
There is one significant limitation at the present. When a fragment is included via the spread operator in an object, it must be the only field present. Attempts to include more fields will result in a ValueError
.
However, there are some real benefits. When a fragment is included in multiple places in the query, only a single class will be made to represent that fragment:
fragment Point on Bar {
id
x
y
}
query GetPoints {
circlePoints {
...Point
}
squarePoints {
...Point
}
}
Might generate the following types
class Point:
id: str
x: float
y: float
class GetPointsResult:
circle_points: List[Point]
square_points: List[Point]
The previous behavior would generate duplicate classes for for the GetPointsCirclePoints
and GetPointsSquarePoints
even though they are really identical classes.
Releases contributed by @mgilson via #2802
Published by botberry over 1 year ago
Make StrawberryAnnotation hashable, to make it compatible to newer versions of dacite.
Releases contributed by @jaimecp89 via #2790
Published by botberry over 1 year ago
This release updates the Django Channels integration so that it uses the same base
classes used by all other integrations.
New features:
The Django Channels integration supports two new features:
multipart/form-data
POST requestsBreaking changes:
This release contains a breaking change for the Channels integration. The context
object is now a dict
and it contains different keys depending on the connection
protocol:
request
and response
. The request
object contains the fullrequest
was the GraphQLHTTPConsumer
request.consumer
.request
, ws
and response
. request
and ws
are the sameGraphQLWSConsumer
instance of the current connection.If you want to use a dataclass for the context object (like in previous releases),
you can still use them by overriding the get_context
methods. See the Channels
integration documentation for an example.
Releases contributed by @cdroege via #2775
Published by botberry over 1 year ago
This PR allows passing metadata to Strawberry arguments.
Example:
import strawberry
@strawberry.type
class Query:
@strawberry.field
def hello(
self,
info,
input: Annotated[str, strawberry.argument(metadata={"test": "foo"})],
) -> str:
argument_definition = info.get_argument_definition("input")
assert argument_definition.metadata["test"] == "foo"
return f"Hi {input}"
Releases contributed by @jkimbo via #2755
Published by botberry over 1 year ago
In this release codegen no longer chokes on queries that have a __typename
in them.
Python generated types will not have the __typename
included in the fields.
Releases contributed by @mgilson via #2797
Published by botberry over 1 year ago
Prevent AssertionError when using strawberry codegen
on a query file that contains a mutation.
Releases contributed by @mgilson via #2795
Published by botberry over 1 year ago
This release fixes a bug in experimental.pydantic whereby Optional
type annotations weren't exactly aligned between strawberry type and pydantic model.
Previously this would have caused the series field to be non-nullable in graphql.
from typing import Optional
from pydantic import BaseModel, Field
import strawberry
class VehicleModel(BaseModel):
series: Optional[str] = Field(default="")
@strawberry.experimental.pydantic.type(model=VehicleModel, all_fields=True)
class VehicleModelType:
pass
Releases contributed by @nicholasbutlin via #2782
Published by botberry over 1 year ago
This release introduces the new should_ignore
argument to the QueryDepthLimiter
extension that provides
a more general and more verbose way of specifying the rules by which a query's depth should be limited.
The should_ignore
argument should be a function that accepts a single argument of type IgnoreContext
.
The IgnoreContext
class has the following attributes:
field_name
of type str
: the name of the field to be compared againstfield_args
of type strawberry.extensions.query_depth_limiter.FieldArgumentsType
: the arguments of the field to be compared againstquery
of type graphql.language.Node
: the query stringcontext
of type graphql.validation.ValidationContext
: the context passed to the queryTrue
if the field should be ignored and False
otherwise.QueryDepthLimiter
class and should not be passed by the user.Instead, the user should write business logic to determine whether a field should be ignored or not by
the attributes of the IgnoreContext
class.
For example, the following query:
"""
query {
matt: user(name: "matt") {
email
}
andy: user(name: "andy") {
email
address {
city
}
pets {
name
owner {
name
}
}
}
}
"""
can have its depth limited by the following should_ignore
:
from strawberry.extensions import IgnoreContext
def should_ignore(ignore: IgnoreContext):
return ignore.field_args.get("name") == "matt"
query_depth_limiter = QueryDepthLimiter(should_ignore=should_ignore)
so that it effectively becomes:
"""
query {
andy: user(name: "andy") {
email
pets {
name
owner {
name
}
}
}
}
"""
Releases contributed by @tsmith023 via #2505
Published by botberry over 1 year ago
This release adds a method on the DatadogTracingExtension class called create_span
that can be overridden to create a custom span or add additional tags to the span.
from ddtrace import Span
from strawberry.extensions import LifecycleStep
from strawberry.extensions.tracing import DatadogTracingExtension
class DataDogExtension(DatadogTracingExtension):
def create_span(
self,
lifecycle_step: LifecycleStep,
name: str,
**kwargs,
) -> Span:
span = super().create_span(lifecycle_step, name, **kwargs)
if lifecycle_step == LifeCycleStep.OPERATION:
span.set_tag("graphql.query", self.execution_context.query)
return span
Releases contributed by @ronaldnwilliams via #2773
Published by botberry over 1 year ago
This release fixes an issue with optional scalars using the or
notation with forward references on python 3.10.
The following code would previously raise TypeError
on python 3.10:
from __future__ import annotations
import strawberry
from strawberry.scalars import JSON
@strawberry.type
class SomeType:
an_optional_json: JSON | None
Releases contributed by @bellini666 via #2774
Published by botberry over 1 year ago
This release adds support for using enum_value
with IntEnum
s, like this:
import strawberry
from enum import IntEnum
@strawberry.enum
class Color(IntEnum):
OTHER = strawberry.enum_value(
-1, description="Other: The color is not red, blue, or green."
)
RED = strawberry.enum_value(0, description="Red: The color red.")
BLUE = strawberry.enum_value(1, description="Blue: The color blue.")
GREEN = strawberry.enum_value(2, description="Green: The color green.")
Releases contributed by @patrick91 via #2761
Published by botberry over 1 year ago
This release adds a SentryTracingExtension that you can use to automatically add
tracing information to your GraphQL queries.
Releases contributed by @patrick91 via #2495
Published by botberry over 1 year ago
This release adds support for custom classes inside the OpenTelemetry integration.
With this, we shouldn't see errors like this anymore:
Invalid type dict for attribute 'graphql.param.paginator' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types.
Releases contributed by @abhinavramana via #2753
Published by botberry over 1 year ago
Add get_argument_definition
helper function on the Info object to get
a StrawberryArgument definition by argument name from inside a resolver or
Field Extension.
Example:
import strawberry
@strawberry.type
class Query:
@strawberry.field
def field(
self,
info,
my_input: Annotated[
str,
strawberry.argument(description="Some description"),
],
) -> str:
my_input_def = info.get_argument_definition("my_input")
assert my_input_def.type is str
assert my_input_def.description == "Some description"
return my_input
Releases contributed by @jkimbo via #2732
Published by botberry over 1 year ago
This release adds more type hints to internal APIs and public APIs.
Releases contributed by @alexauritt via #2568
Published by botberry over 1 year ago
This release improves the graphql-transport-ws
implementation by starting the sub-protocol timeout only when the connection handshake is completed.
Releases contributed by @kristjanvalur via #2703