A GraphQL library for Python that leverages type annotations 🍓
MIT License
Bot releases are hidden (Show)
Published by botberry about 1 year ago
Add text/html content-type to chalice graphiql response
Releases contributed by @jpopesculian via #3137
Published by botberry about 1 year ago
This release adds a new private hook in our HTTP views, it is called
_handle_errors
and it is meant to be used by Sentry (or other integrations)
to handle errors without having to patch methods that could be overridden
by the users
Releases contributed by @patrick91 via #3127
Published by botberry about 1 year ago
This release changes how we check for conflicting resolver arguments to
exclude self
from those checks, which were introduced on version 0.208.0.
It is a common pattern among integrations, such as the Django one, to
use root: Model
in the resolvers for better typing inference.
Releases contributed by @bellini666 via #3131
Published by botberry about 1 year ago
Mark Django's asyncview as a coroutine using asgiref.sync.markcoroutinefunction
to support using it with Python 3.12.
Releases contributed by @bellini666 via #3124
Published by botberry about 1 year ago
Fix generation of input based on pydantic models using nested Annotated
type annotations:
import strawberry
from pydantic import BaseModel
class User(BaseModel):
age: Optional[Annotated[int, "metadata"]]
@strawberry.experimental.pydantic.input(all_fields=True)
class UserInput:
pass
Releases contributed by @gazorby via #3109
Published by botberry about 1 year ago
This release fixes an issue when trying to generate code from a schema that
was using double quotes inside descriptions.
The following schema will now generate code correctly:
"""
A type of person or character within the "Star Wars" Universe.
"""
type Species {
"""
The classification of this species, such as "mammal" or "reptile".
"""
classification: String!
}
Releases contributed by @patrick91 via #3112
Published by botberry about 1 year ago
This release adds support for generating Strawberry types from SDL files. For example, given the following SDL file:
type Query {
user: User
}
type User {
id: ID!
name: String!
}
you can run
strawberry schema-codegen schema.graphql
to generate the following Python code:
import strawberry
@strawberry.type
class Query:
user: User | None
@strawberry.type
class User:
id: strawberry.ID
name: str
schema = strawberry.Schema(query=Query)
Releases contributed by @patrick91 via #3096
Published by botberry about 1 year ago
Adding support for additional pydantic built in types like EmailStr or PostgresDsn.
Releases contributed by @ppease via #3101
Published by botberry about 1 year ago
This release fixes an issue that would prevent using generics with unnamed
unions, like in this example:
from typing import Generic, TypeVar, Union
import strawberry
T = TypeVar("T")
@strawberry.type
class Connection(Generic[T]):
nodes: list[T]
@strawberry.type
class Entity1:
id: int
@strawberry.type
class Entity2:
id: int
@strawberry.type
class Query:
entities: Connection[Union[Entity1, Entity2]]
Releases contributed by @patrick91 via #3099
Published by botberry about 1 year ago
This fixes a bug where codegen would choke trying to find a field in the schema for a generic type.
Releases contributed by @mgilson via #3077
Published by botberry about 1 year ago
Adds new strawberry.Parent type annotation to support resolvers without use of self.
E.g.
@dataclass
class UserRow:
id_: str
@strawberry.type
class User:
@strawberry.field
@staticmethod
async def name(parent: strawberry.Parent[UserRow]) -> str:
return f"User Number {parent.id}"
@strawberry.type
class Query:
@strawberry.field
def user(self) -> User:
return UserRow(id_="1234")
Releases contributed by @mattalbr via #3017
Published by botberry about 1 year ago
This fixes a bug where codegen would choke on FragmentSpread nodes in the GraphQL during type collection.
e.g.:
fragment PartialBlogPost on BlogPost {
title
}
query OperationName {
interface {
id
... on BlogPost {
...PartialBlogPost
}
... on Image {
url
}
}
}
The current version of the code generator is not able to handle the ...PartialBogPost
in this position because it assumes it can only find Field
type nodes even though the spread should be legit.
Releases contributed by @mgilson via #3086
Published by botberry about 1 year ago
This release removes the deprecated ignore
argument from the QueryDepthLimiter
extension.
Releases contributed by @benesgarage via #3093
Published by botberry about 1 year ago
strawberry codegen
can now operate on multiple input query files.
The previous behavior of naming the file types.js
and types.py
for the builtin typescript
and python
plugins respectively is
preserved, but only if a single query file is passed. When more
than one query file is passed, the code generator will now use
the stem of the query file's name to construct the name of the
output files. e.g. my_query.graphql
-> my_query.js
or
my_query.py
. Creators of custom plugins are responsible
for controlling the name of the output file themselves. To
accomodate this, if the __init__
method of a QueryCodegenPlugin
has a parameter named query
or query_file
, the pathlib.Path
to the query file will be passed to the plugin's __init__
method.
Finally, the ConsolePlugin
has also recieved two new lifecycle
methods. Unlike other QueryCodegenPlugin
, the same instance of
the ConsolePlugin
is used for each query file processed. This
allows it to keep state around how many total files were processed.
The ConsolePlugin
recieved two new lifecycle hooks: before_any_start
and after_all_finished
that get called at the appropriate times.
Releases contributed by @mgilson via #2911
Published by botberry about 1 year ago
strawberry codegen
previously choked for inputs that used the
strawberry.UNSET
sentinal singleton value as a default. The intent
here is to say that if a variable is not part of the request payload,
then the UNSET
default value will not be modified and the service
code can then treat an unset value differently from a default value,
etc.
For codegen, we treat the UNSET
default value as a GraphQLNullValue
.
The .value
property is the UNSET
object in this case (instead of
the usual None
). In the built-in python code generator, this causes
the client to generate an object with a None
default. Custom client
generators can sniff at this value and update their behavior.
Releases contributed by @mgilson via #3050
Published by botberry about 1 year ago
Adds a new flag to export-schema
command, --output
, which allows the user to specify the output file. If unset (current behavior), the command will continue to print to stdout.
Releases contributed by @stillmatic via #3033
Published by botberry about 1 year ago
Mark pydantic constrained list test with need_pydantic_v1 since it is removed in pydantic V2
Releases contributed by @tjeerddie via #3034
Published by botberry about 1 year ago
Enhancements:
StrawberryAnnotation._is_list
to check if the annotation
extends from the list
type, enabling it to be considered a list.StrawberryAnnotation
Moved the _is_list
check before the _is_generic
check in resolve
to avoid unsupported
error in _is_generic
before it checked _is_list
.This enhancement enables the usage of constrained lists as class types and allows the creation of specialized lists. The following example demonstrates this feature:
import strawberry
from pydantic import BaseModel, ConstrainedList
class FriendList(ConstrainedList):
min_items = 1
class UserModel(BaseModel):
age: int
friend_names: FriendList[str]
@strawberry.experimental.pydantic.type(UserModel)
class User:
age: strawberry.auto
friend_names: strawberry.auto
Releases contributed by @tjeerddie via #2909
Published by botberry about 1 year ago
This release updates the built-in GraphiQL to the current latest version (3.0.5), it also updates React to the current latest version (18.2.0) and uses the production distribution instead of development to reduce bundle size.
Releases contributed by @kiendang via #3031
Published by botberry about 1 year ago
Add support for extra colons in the GlobalID
string.
Before, the string SomeType:some:value
would produce raise an error saying that
it was expected the string to be splited in 2 parts when doing .split(":")
.
Now we are using .split(":", 1)
, meaning that the example above will consider
SomeType
to be the type name, and some:value
to be the node_id.
Releases contributed by @bellini666 via #3025