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

Commit ed52efe

Browse files
committed
feat: mark this lib as deprecated and add a documentation on how to migrate to strawberry_django
1 parent dc587c7 commit ed52efe

File tree

8 files changed

+218
-13
lines changed

8 files changed

+218
-13
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
![python version](https://img.shields.io/pypi/pyversions/strawberry-django-plus.svg)
88
![django version](https://img.shields.io/pypi/djversions/strawberry-django-plus.svg)
99

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

1224
Built on top of [strawberry-django](https://github.com/strawberry-graphql/strawberry-graphql-django)

docs/contributing.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
!!! warning
2+
3+
All the extra features provided by this lib were contributed and merged directly
4+
into the official
5+
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
6+
lib. Since then this lib is deprecated and the official integration should be used instead.
7+
8+
If you were using this lib before, check out the
9+
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
10+
on how to migrate your code.
11+
112
We use [poetry](https://github.com/sdispater/poetry) to manage dependencies, to
213
get started follow these steps:
314

@@ -7,6 +18,7 @@ cd strawberry-django-plus
718
poetry install
819
poetry run pytest
920
```
21+
1022
This will install all the dependencies (including dev ones) and run the tests.
1123

1224
### Pre commit

docs/debug-toolbar.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
!!! warning
22

3+
All the extra features provided by this lib were contributed and merged directly
4+
into the official
5+
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
6+
lib. Since then this lib is deprecated and the official integration should be used instead.
7+
8+
If you were using this lib before, check out the
9+
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
10+
on how to migrate your code.
11+
12+
!!! tip
13+
314
Since version 3.0.0 this feature was removed from this lib due to it being merged on
415
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django),
516
and should now be used from there.

docs/index.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,38 @@ integration, enhancing its overall functionality.
1616
![python version](https://img.shields.io/pypi/pyversions/strawberry-django-plus.svg)
1717
![django version](https://img.shields.io/pypi/djversions/strawberry-django-plus.svg)
1818

19+
!!! warning
20+
21+
All the extra features provided by this lib were contributed and merged directly
22+
into the official
23+
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
24+
lib. Since then this lib is deprecated and the official integration should be used instead
25+
and development will continue there!
26+
27+
If you were using this lib before, check out the
28+
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
29+
on how to migrate your code.
30+
1931
## Features
2032

2133
- [x] All supported features by `strawberry` and `strawberry-django`.
22-
- [x] [Query optimizer extension](https://blb-ventures.github.io/strawberry-django-plus/query-optimizer/)
34+
- [x] [Query optimizer extension](query-optimizer/)
2335
that automatically optimizes querysets
2436
(using `only`/`select_related`/`prefetch_related`) to solve graphql `N+1` problems, with support
2537
for fragment spread, inline fragments, `@include`/`@skip` directives, prefetch merging, etc
26-
- [x] [Django choices enums using](https://blb-ventures.github.io/strawberry-django-plus/quickstart/#django-choices-enums)
38+
- [x] [Django choices enums using](quickstart/#django-choices-enums)
2739
support for better enum typing (requires
2840
[django-choices-field](https://github.com/bellini666/django-choices-field))
29-
- [x] [Permissioned resolvers](https://blb-ventures.github.io/strawberry-django-plus/quickstart/#permissioned-resolvers)
41+
- [x] [Permissioned resolvers](quickstart/#permissioned-resolvers)
3042
using schema directives, supporting both
3143
[django authentication system](https://docs.djangoproject.com/en/4.0/topics/auth/default/),
3244
direct and per-object permission checking for backends that implement those (e.g.
3345
[django-guardian](https://django-guardian.readthedocs.io/en/stable)).
34-
- [x] [Mutations for Django](https://blb-ventures.github.io/strawberry-django-plus/mutations/),
46+
- [x] [Mutations for Django](mutations/),
3547
with CRUD support and automatic errors validation.
36-
- [x] [Relay support](https://blb-ventures.github.io/strawberry-django-plus/quickstart/#relay-support)
48+
- [x] [Relay support](quickstart/#relay-support)
3749
for queries, connections and input mutations, all integrated with django types directly.
38-
- [x] [Django Debug Toolbar integration](https://blb-ventures.github.io/strawberry-django-plus/debug-toolbar/) with graphiql to
50+
- [x] [Django Debug Toolbar integration](debug-toolbar/) with graphiql to
3951
display metrics like SQL queries
4052
- [x] Improved sync/async resolver that priorizes the model's cache to avoid have to use
4153
[sync_to_async](https://docs.djangoproject.com/en/4.0/topics/async/#asgiref.sync.sync_to_async)

docs/migration-guide.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,129 @@
1+
## Migrating to Strawberry Django
2+
3+
All the extra features provided by this lib were contributed and merged directly
4+
into the official
5+
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
6+
lib. Since then this lib is deprecated and the official integration should be used instead.
7+
8+
Follow these steps to migrate your existing code:
9+
10+
### 1) Required dependencies
11+
12+
Make sure you have `strawberry-graphql>=0.10.0` in your dependencies. After the migration
13+
is complete you can safely remove `strawberry-django-plus` from them.
14+
15+
### 2) Replace your `gql.*` aliases
16+
17+
The `gql.*` alias should be replaces by their correct counterpart. For example:
18+
19+
- `gql.type` -> `strawberry.type`
20+
- `gql.field` -> `strawberry.field`
21+
- `gql.django.type` -> `strawberry.django.type` (or `strawberry_django.type`)
22+
- `gql.django.field` -> `strawberry.django.field` (or `strawberry_django.field`)
23+
24+
### 3) Relay API adjustments
25+
26+
The relay integration was from `v3.0` in this lib was ported "as is" to
27+
strawberry django, meaning that the `gql.*` step adjustment will also
28+
adjust the relay APIs.
29+
30+
In case you are migrating from `v2.x`, check the `v3.0.0` migration guide below.
31+
You don't need to upgrade to `v3.0.0` first, but you can use it to help adjusting
32+
your relay code.
33+
34+
If you were not using the relay integration, you can skip this step.
35+
36+
### 4) Mutation API adjustments
37+
38+
There are some differences to be aware for the mutations API:
39+
40+
1. `strawberry_django.mutation` and `strawberry_django.input_mutation` changed the
41+
`handle_django_errors` argument default value from `True` to `False`. If you want
42+
the old behaviour for all mutations without having to modify the argument by hand,
43+
you can set the `"MUTATIONS_DEFAULT_HANDLE_ERRORS": True` in your
44+
[strawberry django settings](https://strawberry-graphql.github.io/strawberry-graphql-django/guide/settings/)
45+
2. CUD mutations are now based on strawberry django's ones. You should rename your
46+
`create_mutation`/`update_mutation`/`delete_mutation` calls to
47+
`create`/`update`/`delete` respectively.
48+
3. CUD mutations from strawberry django define the input field argument's name to
49+
`data` by default. You can change it to `input` (this lib's argument name) by passing
50+
`argument_name="input"` to the mutation. If you want that name for all mutations
51+
regardless, you can set the `"MUTATIONS_DEFAULT_ARGUMENT_NAME": "input"` in your
52+
[strawberry django settings](https://strawberry-graphql.github.io/strawberry-graphql-django/guide/settings/)
53+
54+
### 5) Permissions refactored to use Field Extensions
55+
56+
Permission checking used to require including a "Schema Directive Extension" in your
57+
schema's extensions. That is not required anymore since the new implementation
58+
is based on the official "Field Extensions" support from strawberry.
59+
60+
Most extensions have the same name, except for `HasRootPerm` and `HasSourcePerm`
61+
that were renamed like this:
62+
63+
- `HasRootPerm` -> `HasSourcePerm`
64+
- `HasObjPerm` -> `HasRetvalPerm`
65+
66+
To migrate, all you need to do is change the directive your were previously
67+
inserting in your field with the related extension. For example, the following code:
68+
69+
```python
70+
import strawberry
71+
from strawberry_django_plus import gql
72+
from strawberry_django_plus.permissions import IsAuthenticated, HasObjPerm
73+
from strawberry_django_plus.directives import SchemaDirectiveExtension
74+
75+
@gql.type
76+
class Query:
77+
fruit: Fruit = gql.django.field(directives=[IsAuthenticated()])
78+
fruit2: Fruit = gql.django.field(directives=[HasObjPerm("can_view_fruit")])
79+
80+
schema = strawberry.schema(
81+
query=Query,
82+
extensions=[
83+
SchemaDirectiveExtension,
84+
],
85+
)
86+
```
87+
88+
Can be migrated to:
89+
90+
```python
91+
import strawberry
92+
from strawberry_django.permissions import IsAuthenticated, HasRetvalPerm
93+
94+
@strawberry.type
95+
class Query:
96+
fruit: Fruit = strawberry.django.field(extensions=[IsAuthenticated()])
97+
fruit2: Fruit = strawberry.django.field(extensions=[HasRetvalPerm("can_view_fruit")])
98+
99+
schema = strawberry.schema(
100+
query=Query,
101+
)
102+
```
103+
104+
### 6) Types/Fields description from model's docstring and field's `help_text`
105+
106+
The ability to retrieve types/fields description directly from the model's
107+
docstring and/or field's `help_text` is available on strawberry django,
108+
but it is an opt-in feature.
109+
110+
To enable those, you can set the `"FIELD_DESCRIPTION_FROM_HELP_TEXT": True` and
111+
`"TYPE_DESCRIPTION_FROM_MODEL_DOCSTRING": True` in your
112+
[strawberry django settings](https://strawberry-graphql.github.io/strawberry-graphql-django/guide/settings/)
113+
114+
### 7) Enjoy! 😊
115+
116+
If you followed all those steps correctly, your code should be working just like
117+
it was before.
118+
119+
Be sure to check
120+
[strawberry django's documentation page](https://strawberry-graphql.github.io/strawberry-graphql-django/)
121+
to know more about all the feature it provides.
122+
123+
Also, if you find any issues during your migration, be sure to open an issue at its repository.
124+
125+
Don't forget you can also reach us in our [discord page](https://strawberry.rocks/discord).
126+
1127
## Version 3.0.0
2128

3129
### Debug toolbar integration moved to strawberry-graphql-django

docs/mutations.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
!!! warning
2+
3+
All the extra features provided by this lib were contributed and merged directly
4+
into the official
5+
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
6+
lib. Since then this lib is deprecated and the official integration should be used instead.
7+
8+
If you were using this lib before, check out the
9+
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
10+
on how to migrate your code.
11+
112
This library provides 3 CUD mutations for streamlining common create/update/delete operations and reducing boilerplate code.
213
There is also a facility for creating custom mutations with automatic `ValidationError` support.
314

docs/query-optimizer.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
!!! warning
2+
3+
All the extra features provided by this lib were contributed and merged directly
4+
into the official
5+
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
6+
lib. Since then this lib is deprecated and the official integration should be used instead.
7+
8+
If you were using this lib before, check out the
9+
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
10+
on how to migrate your code.
111

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

5-
615
```python
716
import strawberry
817
from strawberry_django_plus.optimizer import DjangoOptimizerExtension
@@ -18,8 +27,9 @@ schema = strawberry.Schema(
1827

1928
Now consider the following:
2029
!!! Example
21-
=== "models"
22-
```python
30+
=== "models"
31+
32+
````python
2333

2434
class Artist(models.Model):
2535
name = models.CharField()
@@ -141,9 +151,9 @@ Now consider the following:
141151
```
142152

143153
!!! Note
144-
Even though `album__release_date` field was not selected here, it got selected
145-
in the prefetch query later. Since Django caches known objects, we have to select it here or
146-
else it would trigger extra queries latter.
154+
Even though `album__release_date` field was not selected here, it got selected
155+
in the prefetch query later. Since Django caches known objects, we have to select it here or
156+
else it would trigger extra queries latter.
147157

148158
### Model property
149159

@@ -168,7 +178,7 @@ class Song(models.Model):
168178
class SongType:
169179
name: auto
170180
name_with_album: str
171-
```
181+
````
172182

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

docs/quickstart.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
!!! warning
2+
3+
All the extra features provided by this lib were contributed and merged directly
4+
into the official
5+
[strawberry-graphql-django](https://github.com/strawberry-graphql/strawberry-graphql-django)
6+
lib. Since then this lib is deprecated and the official integration should be used instead.
7+
8+
If you were using this lib before, check out the
9+
[migration guide](migration-guide#migrating-to-strawberry-django) for more information
10+
on how to migrate your code.
11+
112
## Introduction
213

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

0 commit comments

Comments
 (0)