Open-source updates - 17 October 2021
Published by Patrick Arminio on
Last two weeks have been a bit hectic personally, that's why I'm only posting my weekly update now. Highlights from the last week are: a new FastAPI integration, an update to our Pydantic integration, a merge_types utility and improvements to our tests.
Last two weeks have been a bit hectic personally, that's why I'm only posting my
weekly update now. Highlights from the last week are: a new FastAPI integration,
an update to our Pydantic integration, a
merge_types utility and improvements
to our tests.
Are you using GraphQL with FastAPI?
Check out @strawberry_gql 🍓, it's now the recommended library for when you need to integrate GraphQL with FastAPI 🎉
Check the new docs here: fastapi.tiangolo.com/advanced/graph…
And Strawberry's docs: strawberry.rocks
We used to recommend using ASGI for integrating for FastAPI, but now we have a better integration based on API Routers and allows to use FastAPI's dependency injection system.
Also super happy to see many people reviewing this PR and making it better 😊
Pydantic integration update
Matt Allen made a PR to update our Pydantic integration to match Strawberry's Django API. The old API is now deprecated, but we will keep it for a while since it is being used by few people. The API looks like this:
import pydantic import strawberry from strawberry.experimental.pydantic import auto class User(pydantic.BaseModel): age: int password: str @strawberry.experimental.pydantic.type(User) class UserType: age: auto password: auto
instead of passing a list of
fields to the decorator, you can now use the same
API you use for all our decorators, but you can also use the "magic"
keyword to let Strawberry infer the type from the Pydantic model.
This API is much nice than
fields since it allows to easily declared the
exposed fields and allows to also edit description of a specific field without
having to pass the type of the field manually.
@strawberry.type class QueryA: ... @strawberry.type class QueryB: ... ComboQuery = merge_types((QueryB, QueryA)) schema = strawberry.Schema(query=ComboQuery)
This is an alternative to create a class that inherits from both
QueryB, and might be preferred by some people.
Now that we have tests running on windows, I've made a PR to add caching to our tests. Not sure I didn't do this earlier, but now our tests should run quite faster as they don't install all the dependencies all the time.
I've also made a PR to separate the Django tests. So now we have less tests to run for each python version and we'll also only run Django tests for the latest version of Django. There's not much need for us to run Django tests for multiple python versions. This will make our test suite faster.
Ester made a PR to add some checks when using @strawberry.type and other decorators. This will make it easier to work with Strawberry as it should make it easier to identify potential mistakes.
I made a PR to run tests on Python 3.10 stable.
I also had to make a fix to prevent Strawberry to install FastAPI by default. Turns out marking dependencies as optional doesn't work if they are not in an "extra" group.
I'm falling a bit behind with these updates, as they were supposed to be weekly updates, but in the last months I skipped them twice. I'll try to get back on track soon, I have some personal life changes happening now, but hopefully they won't distract me too much 😊