A GraphQL library for Python that leverages type annotations 🍓
MIT License
Bot releases are hidden (Show)
Published by botberry over 2 years ago
This release adds the following scalar types:
JSON
Base16
Base32
Base64
they can be used like so:
from strawberry.scalar import Base16, Base32, Base64, JSON
@strawberry.type
class Example:
a: Base16
b: Base32
c: Base64
d: JSON
Published by botberry over 2 years ago
Adds support for converting pydantic conlist.
Note that constraint is not enforced in the graphql type.
Thus, we recommend always working on the pydantic type such that the validation is enforced.
import strawberry
from pydantic import BaseModel, conlist
class Example(BaseModel):
friends: conlist(str, min_items=1)
@strawberry.experimental.pydantic.input(model=Example, all_fields=True)
class ExampleGQL:
...
@strawberry.type
class Query:
@strawberry.field()
def test(self, example: ExampleGQL) -> None:
# friends may be an empty list here
print(example.friends)
# calling to_pydantic() runs the validation and raises
# an error if friends is empty
print(example.to_pydantic().friends)
schema = strawberry.Schema(query=Query)
The converted graphql type is
input ExampleGQL {
friends: [String!]!
}
Published by botberry over 2 years ago
Adds support for converting pydantic conlist.
Note that constraint is not enforced in the graphql type.
Thus, we recommend always working on the pydantic type such that the validation is enforced.
import strawberry
from pydantic import BaseModel, conlist
class Example(BaseModel):
friends: conlist(str, min_items=1)
@strawberry.experimental.pydantic.input(model=Example, all_fields=True)
class ExampleGQL:
...
@strawberry.type
class Query:
@strawberry.field()
def test(self, example: ExampleGQL) -> None:
# friends may be an empty list here
print(example.friends)
# calling to_pydantic() runs the validation and raises
# an error if friends is empty
print(example.to_pydantic().friends)
schema = strawberry.Schema(query=Query)
The converted graphql type is
input ExampleGQL {
friends: [String!]!
}
Published by botberry over 2 years ago
This release updates graphql-core
to 3.2.0
Make sure you take a look at graphql-core
's release notes
for any potential breaking change that might affect you if you're importing things
from the graphql
package directly.
Published by botberry over 2 years ago
Support "void" functions
It is now possible to have a resolver that returns "None". Strawberry will automatically assign the new Void
scalar in the schema
and will always send null
in the response
@strawberry.type
class Mutation:
@strawberry.field
def do_something(self, arg: int) -> None:
return
results in this schema:
type Mutation {
doSomething(arg: Int!): Void
}
Published by botberry over 2 years ago
Add better support for custom Pydantic conversion logic and standardize the
behavior when not using strawberry.auto
as the type.
See https://strawberry.rocks/docs/integrations/pydantic#custom-conversion-logic for details and examples.
Note that this release fixes a bug related to Pydantic aliases in schema
generation. If you have a field with the same name as an aliased Pydantic field
but with a different type than strawberry.auto
, the generated field will now
use the alias name. This may cause schema changes on upgrade in these cases, so
care should be taken. The alias behavior can be disabled by setting the
use_pydantic_alias
option of the decorator to false.
Published by botberry over 2 years ago
Adds support for use_pydantic_alias
parameter in pydantic model conversion.
Decides if the all the GraphQL field names for the generated type should use the alias name or not.
from pydantic import BaseModel, Field
import strawberry
class UserModel(BaseModel):
id: int = Field(..., alias="my_alias_name")
@strawberry.experimental.pydantic.type(
UserModel, use_pydantic_alias=False
)
class User:
id: strawberry.auto
If use_pydantic_alias
is False
, the GraphQL type User will use id
for the name of the id
field coming from the Pydantic model.
type User {
id: Int!
}
With use_pydantic_alias
set to True
(the default behaviour) the GraphQL type user will use myAliasName
for the id
field coming from the Pydantic models (since the field has a alias
specified`)
type User {
myAliasName: Int!
}
use_pydantic_alias
is set to True
for backwards compatibility.
Published by botberry over 2 years ago
This release adds compatibility with uvicron 0.17
Published by botberry over 2 years ago
This release fixes an issue with FastAPI context dependency injection that causes class-based custom contexts to no longer be permitted.
Published by botberry over 2 years ago
This release fixes an issue with the name generation for nested generics,
the following:
T = TypeVar("T")
K = TypeVar("K")
V = TypeVar("V")
@strawberry.type
class Value(Generic[T]):
value: T
@strawberry.type
class DictItem(Generic[K, V]):
key: K
value: V
@strawberry.type
class Query:
d: Value[List[DictItem[int, str]]]
now yields the correct schema:
type IntStrDictItem {
key: Int!
value: String!
}
type IntStrDictItemListValue {
value: [IntStrDictItem!]!
}
type Query {
d: IntStrDictItemListValue!
}
Published by botberry over 2 years ago
Fix bug #1504 in the Pydantic integration, where it was impossible to define
both an input and output type based on the same Pydantic base class.
Published by botberry over 2 years ago
Adds to_pydantic
and from_pydantic
type hints for IDE support.
Adds mypy extension support as well.
from pydantic import BaseModel
import strawberry
class UserPydantic(BaseModel):
age: int
@strawberry.experimental.pydantic.type(UserPydantic)
class UserStrawberry:
age: strawberry.auto
reveal_type(UserStrawberry(age=123).to_pydantic())
Mypy will infer the type as "UserPydantic". Previously it would be "Any"
Published by botberry almost 3 years ago
This release replaces cached_property
with backports.cached_property
to improve
the typing of the library.
Published by botberry almost 3 years ago
Improve typing of @strawberry.enum()
by:
TypeVar
bound on EnumMeta
instead of EnumMeta
, which allows@strawberry.enum
class IceCreamFlavour(Enum):
VANILLA = "vanilla"
STRAWBERRY = "strawberry"
CHOCOLATE = "chocolate"
Prior to this change, pyright would complain if you tried to access
IceCreamFlavour.VANILLA
, since the type information of IceCreamFlavour
was
being erased by the EnumMeta
typing .
@strawberry.enum(name="IceCreamFlavor")
), versus when it returns thePublished by botberry almost 3 years ago
This release adds load_many
to DataLoader
.
Published by botberry almost 3 years ago
This release adds deprecation_reason
support to arguments and mutations.
Published by botberry almost 3 years ago
This release checks for AutoFieldsNotInBaseModelError when converting from pydantic models.
It is raised when strawberry.auto is used, but the pydantic model does not have
the particular field defined.
class User(BaseModel):
age: int
@strawberry.experimental.pydantic.type(User)
class UserType:
age: strawberry.auto
password: strawberry.auto
Previously no errors would be raised, and the password field would not appear on graphql schema.
Such mistakes could be common during refactoring. Now, AutoFieldsNotInBaseModelError is raised.
Published by botberry almost 3 years ago
Fixes TypeError when converting a pydantic BaseModel with NewType field
Published by botberry almost 3 years ago
This release allows setting http headers and custom http status codes with FastAPI GraphQLRouter.
Published by botberry almost 3 years ago
Fix compatibility with Sanic 21.12