strawberry

A GraphQL library for Python that leverages type annotations 🍓

MIT License

Downloads
1.1M
Stars
3.8K
Committers
260

Bot releases are hidden (Show)

strawberry - 🍓 0.99.0

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
strawberry - 🍓 0.98.2

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!]!
}
strawberry - 🍓 0.98.1

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!]!
}
strawberry - 🍓 0.98.0

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.

strawberry - 🍓 0.97.0

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

Exampe

@strawberry.type
class Mutation:
    @strawberry.field
    def do_something(self, arg: int) -> None:
        return

results in this schema:

type Mutation {
    doSomething(arg: Int!): Void
}
strawberry - 🍓 0.96.0

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.

strawberry - 🍓 0.95.5

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.

strawberry - 🍓 0.95.4

Published by botberry over 2 years ago

This release adds compatibility with uvicron 0.17

strawberry - 🍓 0.95.3

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.

strawberry - 🍓 0.95.2

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!
}
strawberry - 🍓 0.95.1

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.

strawberry - 🍓 0.95.0

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"

strawberry - 🍓 0.94.0

Published by botberry almost 3 years ago

This release replaces cached_property with backports.cached_property to improve
the typing of the library.

strawberry - 🍓 0.93.23

Published by botberry almost 3 years ago

Improve typing of @strawberry.enum() by:

  1. Using a TypeVar bound on EnumMeta instead of EnumMeta, which allows
    type-checkers (like pyright) to detect the fields of the enum being
    decorated. For example, for the following enum:
@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 .

  1. Overloading it so that type-checkers (like pyright) knows in what cases it
    returns a decorator (when it's called with keyword arguments, e.g.
    @strawberry.enum(name="IceCreamFlavor")), versus when it returns the
    original enum type (without keyword arguments.
strawberry - 🍓 0.93.22

Published by botberry almost 3 years ago

This release adds load_many to DataLoader.

strawberry - 🍓 0.93.21

Published by botberry almost 3 years ago

This release adds deprecation_reason support to arguments and mutations.

strawberry - 🍓 0.93.20

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.

strawberry - 🍓 0.93.19

Published by botberry almost 3 years ago

Fixes TypeError when converting a pydantic BaseModel with NewType field

strawberry - 🍓 0.93.18

Published by botberry almost 3 years ago

This release allows setting http headers and custom http status codes with FastAPI GraphQLRouter.

strawberry - 🍓 0.93.17

Published by botberry almost 3 years ago

Fix compatibility with Sanic 21.12

Package Rankings
Top 1.15% on Pypi.org
Top 16.1% on Conda-forge.org
Badges
Extracted from project README
CircleCI Discord PyPI
Related Projects