Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Commit

Permalink
feat: mark this lib as deprecated and add a documentation on how to m…
Browse files Browse the repository at this point in the history
…igrate to strawberry_django
  • Loading branch information
bellini666 committed Jul 5, 2023
1 parent dc587c7 commit ed52efe
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 13 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
![python version](https://img.shields.io/pypi/pyversions/strawberry-django-plus.svg)
![django version](https://img.shields.io/pypi/djversions/strawberry-django-plus.svg)

> **Warning**
>
> All the extra features provided by this lib were contributed and merged directly
> into the official
> [strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
> lib. Since then this lib is deprecated and the official integration should be used instead
> and development will continue there!
>
> If you were using this lib before, check out the
> [migration guide](https://blb-ventures.github.io/strawberry-django-plus/migration-guide#migrating-to-strawberry-django)
> for more information on how to migrate your code.
Enhanced Strawberry integration with Django.

Built on top of [strawberry-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
Expand Down
12 changes: 12 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
!!! warning

All the extra features provided by this lib were contributed and merged directly
into the official
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
lib. Since then this lib is deprecated and the official integration should be used instead.

If you were using this lib before, check out the
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
on how to migrate your code.

We use [poetry](https://github.com/sdispater/poetry) to manage dependencies, to
get started follow these steps:

Expand All @@ -7,6 +18,7 @@ cd strawberry-django-plus
poetry install
poetry run pytest
```

This will install all the dependencies (including dev ones) and run the tests.

### Pre commit
Expand Down
11 changes: 11 additions & 0 deletions docs/debug-toolbar.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
!!! warning

All the extra features provided by this lib were contributed and merged directly
into the official
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
lib. Since then this lib is deprecated and the official integration should be used instead.

If you were using this lib before, check out the
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
on how to migrate your code.

!!! tip

Since version 3.0.0 this feature was removed from this lib due to it being merged on
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django),
and should now be used from there.
Expand Down
24 changes: 18 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,38 @@ integration, enhancing its overall functionality.
![python version](https://img.shields.io/pypi/pyversions/strawberry-django-plus.svg)
![django version](https://img.shields.io/pypi/djversions/strawberry-django-plus.svg)

!!! warning

All the extra features provided by this lib were contributed and merged directly
into the official
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
lib. Since then this lib is deprecated and the official integration should be used instead
and development will continue there!

If you were using this lib before, check out the
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
on how to migrate your code.

## Features

- [x] All supported features by `strawberry` and `strawberry-django`.
- [x] [Query optimizer extension](https://blb-ventures.github.io/strawberry-django-plus/query-optimizer/)
- [x] [Query optimizer extension](query-optimizer/)
that automatically optimizes querysets
(using `only`/`select_related`/`prefetch_related`) to solve graphql `N+1` problems, with support
for fragment spread, inline fragments, `@include`/`@skip` directives, prefetch merging, etc
- [x] [Django choices enums using](https://blb-ventures.github.io/strawberry-django-plus/quickstart/#django-choices-enums)
- [x] [Django choices enums using](quickstart/#django-choices-enums)
support for better enum typing (requires
[django-choices-field](https://github.com/bellini666/django-choices-field))
- [x] [Permissioned resolvers](https://blb-ventures.github.io/strawberry-django-plus/quickstart/#permissioned-resolvers)
- [x] [Permissioned resolvers](quickstart/#permissioned-resolvers)
using schema directives, supporting both
[django authentication system](https://docs.djangoproject.com/en/4.0/topics/auth/default/),
direct and per-object permission checking for backends that implement those (e.g.
[django-guardian](https://django-guardian.readthedocs.io/en/stable)).
- [x] [Mutations for Django](https://blb-ventures.github.io/strawberry-django-plus/mutations/),
- [x] [Mutations for Django](mutations/),
with CRUD support and automatic errors validation.
- [x] [Relay support](https://blb-ventures.github.io/strawberry-django-plus/quickstart/#relay-support)
- [x] [Relay support](quickstart/#relay-support)
for queries, connections and input mutations, all integrated with django types directly.
- [x] [Django Debug Toolbar integration](https://blb-ventures.github.io/strawberry-django-plus/debug-toolbar/) with graphiql to
- [x] [Django Debug Toolbar integration](debug-toolbar/) with graphiql to
display metrics like SQL queries
- [x] Improved sync/async resolver that priorizes the model's cache to avoid have to use
[sync_to_async](https://docs.djangoproject.com/en/4.0/topics/async/#asgiref.sync.sync_to_async)
Expand Down
126 changes: 126 additions & 0 deletions docs/migration-guide.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,129 @@
## Migrating to Strawberry Django

All the extra features provided by this lib were contributed and merged directly
into the official
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
lib. Since then this lib is deprecated and the official integration should be used instead.

Follow these steps to migrate your existing code:

### 1) Required dependencies

Make sure you have `strawberry-graphql>=0.10.0` in your dependencies. After the migration
is complete you can safely remove `strawberry-django-plus` from them.

### 2) Replace your `gql.*` aliases

The `gql.*` alias should be replaces by their correct counterpart. For example:

- `gql.type` -> `strawberry.type`
- `gql.field` -> `strawberry.field`
- `gql.django.type` -> `strawberry.django.type` (or `strawberry_django.type`)
- `gql.django.field` -> `strawberry.django.field` (or `strawberry_django.field`)

### 3) Relay API adjustments

The relay integration was from `v3.0` in this lib was ported "as is" to
strawberry django, meaning that the `gql.*` step adjustment will also
adjust the relay APIs.

In case you are migrating from `v2.x`, check the `v3.0.0` migration guide below.
You don't need to upgrade to `v3.0.0` first, but you can use it to help adjusting
your relay code.

If you were not using the relay integration, you can skip this step.

### 4) Mutation API adjustments

There are some differences to be aware for the mutations API:

1. `strawberry_django.mutation` and `strawberry_django.input_mutation` changed the
`handle_django_errors` argument default value from `True` to `False`. If you want
the old behaviour for all mutations without having to modify the argument by hand,
you can set the `"MUTATIONS_DEFAULT_HANDLE_ERRORS": True` in your
[strawberry django settings](https://strawberry-graphql.github.io/strawberry-graphql-django/guide/settings/)
2. CUD mutations are now based on strawberry django's ones. You should rename your
`create_mutation`/`update_mutation`/`delete_mutation` calls to
`create`/`update`/`delete` respectively.
3. CUD mutations from strawberry django define the input field argument's name to
`data` by default. You can change it to `input` (this lib's argument name) by passing
`argument_name="input"` to the mutation. If you want that name for all mutations
regardless, you can set the `"MUTATIONS_DEFAULT_ARGUMENT_NAME": "input"` in your
[strawberry django settings](https://strawberry-graphql.github.io/strawberry-graphql-django/guide/settings/)

### 5) Permissions refactored to use Field Extensions

Permission checking used to require including a "Schema Directive Extension" in your
schema's extensions. That is not required anymore since the new implementation
is based on the official "Field Extensions" support from strawberry.

Most extensions have the same name, except for `HasRootPerm` and `HasSourcePerm`
that were renamed like this:

- `HasRootPerm` -> `HasSourcePerm`
- `HasObjPerm` -> `HasRetvalPerm`

To migrate, all you need to do is change the directive your were previously
inserting in your field with the related extension. For example, the following code:

```python
import strawberry
from strawberry_django_plus import gql
from strawberry_django_plus.permissions import IsAuthenticated, HasObjPerm
from strawberry_django_plus.directives import SchemaDirectiveExtension

@gql.type
class Query:
fruit: Fruit = gql.django.field(directives=[IsAuthenticated()])
fruit2: Fruit = gql.django.field(directives=[HasObjPerm("can_view_fruit")])

schema = strawberry.schema(
query=Query,
extensions=[
SchemaDirectiveExtension,
],
)
```

Can be migrated to:

```python
import strawberry
from strawberry_django.permissions import IsAuthenticated, HasRetvalPerm

@strawberry.type
class Query:
fruit: Fruit = strawberry.django.field(extensions=[IsAuthenticated()])
fruit2: Fruit = strawberry.django.field(extensions=[HasRetvalPerm("can_view_fruit")])

schema = strawberry.schema(
query=Query,
)
```

### 6) Types/Fields description from model's docstring and field's `help_text`

The ability to retrieve types/fields description directly from the model's
docstring and/or field's `help_text` is available on strawberry django,
but it is an opt-in feature.

To enable those, you can set the `"FIELD_DESCRIPTION_FROM_HELP_TEXT": True` and
`"TYPE_DESCRIPTION_FROM_MODEL_DOCSTRING": True` in your
[strawberry django settings](https://strawberry-graphql.github.io/strawberry-graphql-django/guide/settings/)

### 7) Enjoy! 😊

If you followed all those steps correctly, your code should be working just like
it was before.

Be sure to check
[strawberry django's documentation page](https://strawberry-graphql.github.io/strawberry-graphql-django/)
to know more about all the feature it provides.

Also, if you find any issues during your migration, be sure to open an issue at its repository.

Don't forget you can also reach us in our [discord page](https://strawberry.rocks/discord).

## Version 3.0.0

### Debug toolbar integration moved to strawberry-graphql-django
Expand Down
11 changes: 11 additions & 0 deletions docs/mutations.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
!!! warning

All the extra features provided by this lib were contributed and merged directly
into the official
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
lib. Since then this lib is deprecated and the official integration should be used instead.

If you were using this lib before, check out the
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
on how to migrate your code.

This library provides 3 CUD mutations for streamlining common create/update/delete operations and reducing boilerplate code.
There is also a facility for creating custom mutations with automatic `ValidationError` support.

Expand Down
24 changes: 17 additions & 7 deletions docs/query-optimizer.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
!!! warning

All the extra features provided by this lib were contributed and merged directly
into the official
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
lib. Since then this lib is deprecated and the official integration should be used instead.

If you were using this lib before, check out the
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
on how to migrate your code.

The automatic optimization is enabled by adding the `DjangoOptimizerExtension` to your
strawberry's schema config.


```python
import strawberry
from strawberry_django_plus.optimizer import DjangoOptimizerExtension
Expand All @@ -18,8 +27,9 @@ schema = strawberry.Schema(

Now consider the following:
!!! Example
=== "models"
```python
=== "models"

````python

class Artist(models.Model):
name = models.CharField()
Expand Down Expand Up @@ -141,9 +151,9 @@ Now consider the following:
```

!!! Note
Even though `album__release_date` field was not selected here, it got selected
in the prefetch query later. Since Django caches known objects, we have to select it here or
else it would trigger extra queries latter.
Even though `album__release_date` field was not selected here, it got selected
in the prefetch query later. Since Django caches known objects, we have to select it here or
else it would trigger extra queries latter.

### Model property

Expand All @@ -168,7 +178,7 @@ class Song(models.Model):
class SongType:
name: auto
name_with_album: str
```
````

Another option would be to define that on the field itself:

Expand Down
11 changes: 11 additions & 0 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
!!! warning

All the extra features provided by this lib were contributed and merged directly
into the official
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
lib. Since then this lib is deprecated and the official integration should be used instead.

If you were using this lib before, check out the
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
on how to migrate your code.

## Introduction

Since this lib has a long name, it does provide a shortcut called `gql` where all of
Expand Down

0 comments on commit ed52efe

Please sign in to comment.