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.126.1

Published by botberry about 2 years ago

Keep extra discovered types sorted so that each schema printing is
always the same.

strawberry - 🍓 0.126.0

Published by botberry about 2 years ago

This release adds support for adding descriptions to enum values.

Example

@strawberry.enum
class IceCreamFlavour(Enum):
    VANILLA = strawberry.enum_value("vanilla")
    STRAWBERRY = strawberry.enum_value(
        "strawberry", description="Our favourite",
    )
    CHOCOLATE = "chocolate"


@strawberry.type
class Query:
    favorite_ice_cream: IceCreamFlavour = IceCreamFlavour.STRAWBERRY

schema = strawberry.Schema(query=Query)

This produces the following schema

enum IceCreamFlavour {
  VANILLA

  """Our favourite."""
  STRAWBERRY
  CHOCOLATE
}

type Query {
  favoriteIceCream: IceCreamFlavour!
}
strawberry - 🍓 0.125.1

Published by botberry about 2 years ago

This release hides resolvable: True in @keys directives
when using Apollo Federation 1, to preserve compatibility
with older Gateways.

strawberry - 🍓 0.125.0

Published by botberry about 2 years ago

This release adds an integration with Django Channels. The integration will
allow you to use GraphQL subscriptions via Django Channels.

strawberry - 🍓 0.124.0

Published by botberry about 2 years ago

This release adds full support for Apollo Federation 2.0. To opt-in you need to
pass enable_federation_2=True to strawberry.federation.Schema, like in the
following example:

@strawberry.federation.type(keys=["id"])
class User:
    id: strawberry.ID

@strawberry.type
class Query:
    user: User

schema = strawberry.federation.Schema(query=Query, enable_federation_2=True)

This release also improves type checker support for the federation.

strawberry - 🍓 0.123.3

Published by botberry about 2 years ago

This release fixes a regression introduced in version 0.118.2 which was
preventing using circular dependencies in Strawberry django and Strawberry
django plus.

strawberry - 🍓 0.123.2

Published by botberry about 2 years ago

This release adds support for priting custom enums used only on
schema directives, for example the following schema:

@strawberry.enum
class Reason(str, Enum):
    EXAMPLE = "example"

@strawberry.schema_directive(locations=[Location.FIELD_DEFINITION])
class Sensitive:
    reason: Reason

@strawberry.type
class Query:
    first_name: str = strawberry.field(
        directives=[Sensitive(reason=Reason.EXAMPLE)]
    )

prints the following:

directive @sensitive(reason: Reason!) on FIELD_DEFINITION

type Query {
    firstName: String! @sensitive(reason: EXAMPLE)
}

enum Reason {
    EXAMPLE
}

while previously it would omit the definition of the enum.

strawberry - 🍓 0.123.1

Published by botberry about 2 years ago

This release adds support for priting custom scalar used only on
schema directives, for example the following schema:

SensitiveConfiguration = strawberry.scalar(str, name="SensitiveConfiguration")

@strawberry.schema_directive(locations=[Location.FIELD_DEFINITION])
class Sensitive:
    config: SensitiveConfiguration

@strawberry.type
class Query:
    first_name: str = strawberry.field(directives=[Sensitive(config="Some config")])

prints the following:

directive @sensitive(config: SensitiveConfiguration!) on FIELD_DEFINITION

type Query {
    firstName: String! @sensitive(config: "Some config")
}

scalar SensitiveConfiguration

while previously it would omit the definition of the scalar.

strawberry - 🍓 0.123.0

Published by botberry about 2 years ago

This PR adds support for adding schema directives to the schema of
your GraphQL API. For printing the following schema:

@strawberry.schema_directive(locations=[Location.SCHEMA])
class Tag:
    name: str

@strawberry.type
class Query:
    first_name: str = strawberry.field(directives=[Tag(name="team-1")])

schema = strawberry.Schema(query=Query, schema_directives=[Tag(name="team-1")])

will print the following:

directive @tag(name: String!) on SCHEMA

schema @tag(name: "team-1") {
    query: Query
}

type Query {
    firstName: String!
}
"""
strawberry - 🍓 0.122.1

Published by botberry about 2 years ago

This release fixes that the AIOHTTP integration ignored the operationName of query
operations. This behaviour is a regression introduced in version 0.107.0.

strawberry - 🍓 0.122.0

Published by botberry about 2 years ago

This release adds support for printing default values for scalars like JSON.

For example the following:

import strawberry
from strawberry.scalars import JSON


@strawberry.input
class MyInput:
    j: JSON = strawberry.field(default_factory=dict)
    j2: JSON = strawberry.field(default_factory=lambda: {"hello": "world"})

will print the following schema:

input MyInput {
    j: JSON! = {}
    j2: JSON! = {hello: "world"}
}
strawberry - 🍓 0.121.1

Published by botberry about 2 years ago

This release adds a backward compatibility layer with libraries
that specify a custom get_result.

strawberry - 🍓 0.121.0

Published by botberry about 2 years ago

This release adds support for overriding the default resolver for fields.

Currently the default resolver is getattr, but now you can change it to any
function you like, for example you can allow returning dictionaries:

@strawberry.type
class User:
    name: str

@strawberry.type
class Query:
    @strawberry.field
    def user(self) -> User:
        return {"name": "Patrick"}  # type: ignore

schema = strawberry.Schema(
    query=Query,
    config=StrawberryConfig(default_resolver=getitem),
)

query = "{ user { name } }"

result = schema.execute_sync(query)
strawberry - 🍓 0.120.0

Published by botberry about 2 years ago

This release add a new DatadogTracingExtension that can be used to instrument
your application with Datadog.

import strawberry

from strawberry.extensions.tracing import DatadogTracingExtension

schema = strawberry.Schema(
    Query,
    extensions=[
        DatadogTracingExtension,
    ]
)
strawberry - 🍓 0.119.2

Published by botberry about 2 years ago

Fixed edge case where Union types raised an UnallowedReturnTypeForUnion
error when returning the correct type from the resolver. This also improves
performance of StrawberryUnion's _resolve_union_type from O(n) to O(1) in
the majority of cases where n is the number of types in the schema.

For
example the below)
would previously raise the error when querying two as StrawberryUnion would
incorrectly determine that the resolver returns Container[TypeOne].

import strawberry
from typing import TypeVar, Generic, Union, List, Type

T = TypeVar("T")

@strawberry.type
class Container(Generic[T]):
    items: List[T]

@strawberry.type
class TypeOne:
    attr: str

@strawberry.type
class TypeTwo:
    attr: str

def resolver_one():
    return Container(items=[TypeOne("one")])

def resolver_two():
    return Container(items=[TypeTwo("two")])

@strawberry.type
class Query:
    one: Union[Container[TypeOne], TypeOne] = strawberry.field(resolver_one)
    two: Union[Container[TypeTwo], TypeTwo] = strawberry.field(resolver_two)

schema = strawberry.Schema(query=Query)
strawberry - 🍓 0.119.1

Published by botberry over 2 years ago

An explanatory custom exception is raised when union of GraphQL input types is attempted.

strawberry - 🍓 0.119.0

Published by botberry over 2 years ago

This release changes when we add the custom directives extension, previously
the extension was always enabled, now it is only enabled if you pass custom
directives to strawberry.Schema.

strawberry - 🍓 0.118.2

Published by botberry over 2 years ago

This release adds an initial fix to make strawberry.auto work when using
from __future__ import annotations.

strawberry - 🍓 0.118.1

Published by botberry over 2 years ago

Fixes issue where users without pydantic were not able to use the mypy plugin.

strawberry - 🍓 0.118.0

Published by botberry over 2 years ago

You can now pass keyword arguments to to_pydantic

from pydantic import BaseModel
import strawberry

class MyModel(BaseModel):
   email: str
   password: str


@strawberry.experimental.pydantic.input(model=MyModel)
class MyModelStrawberry:
   email: strawberry.auto
   # no password field here

MyModelStrawberry(email="").to_pydantic(password="hunter")

Also if you forget to pass password, mypy will complain

MyModelStrawberry(email="").to_pydantic()
# error: Missing named argument "password" for "to_pydantic" of "MyModelStrawberry"
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