Commit Graph

193 Commits

Author SHA1 Message Date
Steven DeMartini
20a6cecc4c Add test validating query performance with select_related + prefetch_related
This test passes after reverting the `CustomField` resolver change
introduced in
https://github.com/graphql-python/graphene-django/pull/1315, but fails
with that resolver code present. For instance, adding back the resolver
code gives a test failure showing:

```
Failed: Expected to perform 2 queries but 11 were done
```

This should ensure there aren't regressions that prevent
query-optimization in the future.
2023-05-03 11:37:17 +03:00
Steven DeMartini
9796e93fc7 Remove obsolete tests and add note about rationale 2023-05-03 11:37:17 +03:00
Steven DeMartini
f67c5dbc8c Revert field resolver logic to fix poor query performance
This reverts the change to `convert_field_to_djangomodel` introduced in
https://github.com/graphql-python/graphene-django/pull/1315 for the
reasons discussed here
https://github.com/graphql-python/graphene-django/pull/1315/files#r1015659857.
As mentioned there, without reverting this code, "queries are forced
every time an object is resolved, making an exponential number of
queries when nesting without any possibility of optimizing".

That regression prevented `graphene-django-optimizer` from working with
`graphene-django` v3.0.0b9+ (where this change first was published), as
discussed in
https://github.com/graphql-python/graphene-django/issues/1356#issuecomment-1284718187,
https://github.com/tfoxy/graphene-django-optimizer/issues/86, and
https://github.com/tfoxy/graphene-django-optimizer/pull/83#issuecomment-1451987397.

For now, this marks the two tests that depended on this problematic code
as "expected to fail", and perhaps they can be reintroduced if there's a
way to support this logic in a way that does not prevent
`select_related` and `prefetch_related` query-optimization and introduce
nested N+1s.

As mentioned here
https://github.com/graphql-python/graphene-django/pull/1315#issuecomment-1468594361,
this is blocking upgrade to graphene-django v3 for many users, and
fixing this would allow many to begin upgrading and contributing to keep
graphene-django going.
2023-05-03 11:37:17 +03:00
Yuekui
86c5309c45
Fix broken UT due to pytest import error (#1368) 2022-11-14 13:56:18 +03:00
Nikolai Røed Kristiansen
4517e32224
👷 Add pre-commit (#1336)
* 🔧 Add pre-commit config

Similar to graphene and graphene-sqlalchemy

* ⬆ Bump black

* 👷 Lint on CI

* ⬆ Bump flake8-black

* 🔧 Keep excluding migrations

* ⬆ Bump flake8

* 🔧 Remove black and flake8 from tox config

* ⬆ Update pre-commit versions

* Upgrade syntax to python 3.7+

* Format with pre-commit

dedent docs/schema.py to allow formatting

* Fix tests on python 3.7
2022-10-19 17:10:30 +03:00
Firas K
541caa117e
Fixes related to pr#1412 (#1352)
* fix: setup.py graphene dependency

* fix: graphene_django/tests/test_get_queryset.py format

Co-authored-by: Firas Kafri <firaskafri@Firass-MacBook-Pro-2.local>
2022-09-24 15:50:40 +03:00
Thomas Leonard
5d81ba04f9
fix: unit test for graphene pr#1412 (#1315)
* Issue #1111: foreign key should also call get_queryset method

* fix: test for graphene PR https://github.com/graphql-python/graphene/pull/1412

Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
2022-09-23 11:45:02 +03:00
Thomas Leonard
37848fa2df
fix: convert Django BigIntegerField to BigInt GraphQL type (#1318)
Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
2022-09-22 19:09:11 +01:00
Thomas Leonard
3473fe025e
fix: backward pagination (#1346)
Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
Co-authored-by: Laurent  <laurent.riviere.pro@gmail.com>
2022-09-22 16:01:28 +01:00
Thomas Leonard
42a40b4df0
chore: update dev dependencies (#1345)
Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
2022-09-22 10:26:21 +01:00
Thomas Leonard
2aeb86ba3b
fix: backward pagination indexing error when using bigger last argument than total number of elements (#1344)
Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
2022-09-06 14:00:13 +02:00
Nikolai Røed Kristiansen
5f1731dca3
Fix: Use .formatted instead of format_error (#1327) & Fix tests
* 👽 Use .formatted instead of format_error

*  Fix test with newer graphene

null default values (graphql-python/graphene@03277a5)
no more trailing newlines
2022-08-15 11:41:39 +02:00
Tim Schilling
5d5d7f1815
Django v4, python 3.10 support for graphene-django v3 (#1281)
Co-authored-by: Yair Silbermintz <MisterGlass@users.noreply.github.com>
2022-01-07 20:26:07 +00:00
Paul Bailey
e7f7d8da07
Add missing auto fields (#1212)
* add missing auto fields

* add missing auto fields

* skip small auto field sometimes

* make small auto optional

* make small auto optional
2021-06-11 13:41:02 -07:00
Sebastián Sastoque H
ea593b673f
Fix: Use resolver passed as an attribute (#1131)
Co-authored-by: Sebastian Hernandez <sebastian@rhinoafrica.com>
2021-02-23 09:50:19 -08:00
Tonye Jack
5cee41407c
Added GraphQLTransactionTestCase (#1099)
* Added GraphQLTransactionTestCase

- Adds support for testing code that is executed within a transaction

Reference: https://docs.djangoproject.com/en/3.1/topics/testing/tools/#django.test.TransactionTestCase
```
 For instance, you cannot test that a block of code is executing within a transaction, as is required when using select_for_update(). In those cases, you should use TransactionTestCase.
```

* Update testing.py

* Update testing.py

* Fixed formatting.

* Updated docs.

* Updated test.

* Update testing.rst
2021-02-22 20:24:02 -08:00
Thomas Leonard
2d4ca0ac7b
Add enum support to filters and fix filter typing (v3) (#1119)
* - Add filtering support for choice fields converted to graphql Enum (or not)
- Fix type of various filters (used to default to String)
- Fix bug with contains introduced in previous PR
- Fix bug with declared filters being overridden (see PR #1108)
- Fix support for ArrayField and add documentation

* Fix for v3

Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
2021-02-22 20:21:32 -08:00
Jason Kraus
bcc7f85dad
Add BlankField and mount enums using it v3 (#1096)
* Add BlankField and mount enums using it

* fix lint error from duplicate import

Co-authored-by: Jonathan Kim <jkimbo@gmail.com>
2021-01-11 16:34:50 -08:00
Lucas
fdeadf5ce5
Fix project setup (#1087)
* Fix project setup

* Fix test_should_query_postgres_fields
2021-01-02 09:46:00 -08:00
Jason Kraus
8324d47999 Merge branch 'v2' into main 2020-12-30 22:31:41 -08:00
Ülgen Sarıkavak
40e5252936
Use the Django TestCase's Client (#1084)
* Use the Django Client test utility instance that Django provides with its TestCase class. This allows GraphQL tests to make use of the stateful client methods like login()

* Add missing test case initializer call

* Don't break backward compability

* Add test for pending deprecation warning on GraphQLTestCase._client

Co-authored-by: Tom Nightingale <tom@tnightingale.com>
2020-12-30 21:12:24 -08:00
Thiago Bellini Ribeiro
8c48516093
Also convert BaseCSVFilter for custom fields (#1081) 2020-12-30 21:03:57 -08:00
Jason Kraus
c049ab7470
WIP: Merge master into v3 (#1086)
* merge master into v3

* fix order_by snake casing by checking if value is None, switch executor to execution_context_class since schema.execute no longer supports executor

* fix linting by removing duplicate defintion and test of convert_form_field_to_string_list
2020-12-30 15:37:57 -08:00
Jason Kraus
2d0b9ddd42
improvement: convert decimal field to graphene decimal (#1083) 2020-12-30 08:25:41 -08:00
Ignacio Orlandini
8f63199a63
Handle database transactions (#1039)
* Handle Django database atomic requests

* Create and handle database atomic mutations

* Make code compatible with Python 2.7

* Code style

* Define set_rollback instead of using the one in rest_framework.views because of backward compatibility

* Implement mock.patch.dict
2020-12-22 20:18:14 -08:00
Jason Kraus
7b35695067
Fix 1061: DjangoListField should not cache queries (#1063)
* fix( DjangoListField ): test that default functionality should resolve/call queryset at view time, first attempt at solution

* fix( DjangoListField ): DjangoListField defines get_manager just like DjangoConnectionField for a better variable name default_manager instead of default_queryset

* fix: apply specific black formatting
2020-12-22 20:10:28 -08:00
Thomas Leonard
454b74052e
Fix backward Relay pagination (#1046)
* Fix backward Relay pagination

* linting

Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
2020-12-22 20:04:45 -08:00
Thomas Leonard
2140be5e6a
Add offset pagination (#1013)
* Add offset filtering

* Formatting

Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
2020-10-26 09:09:21 -07:00
Andreas Hasenkopf
ee3d4f521f
Include tests and examples in source package, but don't install them (#1034)
..., but don't install them.
Also applied changes as suggested by `black`.
2020-10-19 17:23:41 +01:00
Jonathan Kim
33c6a54414 Merge branch 'master' into v3 2020-08-12 07:06:35 +01:00
Nikolai Røed Kristiansen
67a0492c12
Add converter for django 3.1 JSONField (#1017) 2020-08-07 10:22:15 +01:00
Thomas Leonard
11dbde3bea
Fix Connection/Edge naming and add unit test (#1012)
Co-authored-by: Thomas Leonard <thomas@loftorbital.com>
2020-08-07 10:15:35 +01:00
Jonathan Kim
da9f41c295 Rename get_resolver -> wrap_resolve and fix tests 2020-08-06 20:45:30 +01:00
Jonathan Kim
6cfcddac5a Merge branch 'master' into v3 2020-08-06 20:35:08 +01:00
Nikolai Røed Kristiansen
2308965658
Extract query function from GraphQLTestCase making it possible to use in a pytest fixture (#1015) 2020-08-05 20:24:16 +01:00
Thiago Bellini Ribeiro
d50955a173
Do not break when after is greater than list_length (#999) 2020-07-09 18:01:22 +01:00
Jonathan Kim
965ebdee13 Merge branch 'master' into v3 2020-06-27 11:14:09 +01:00
Jonathan Kim
3026181b28
Set first amount to max limit if not set (#993) 2020-06-25 15:10:56 +01:00
Paul Craciunoiu
3c229b619e
Fix hasNextPage - revert to count. Fix after (#986)
Co-authored-by: Jonathan Kim <jkimbo@gmail.com>
2020-06-25 13:00:24 +01:00
Radosław Kowalski
1f752b6cad
Warn if fields or exclude are not defined on DjangoObjectType (#981) 2020-06-11 11:09:52 +01:00
Yuyang Zhang(helloqiu)
48bfc395ee
fix(converter): wrap field with NonNull if it is required (#545)
Co-authored-by: Jonathan Kim <jkimbo@gmail.com>
2020-06-10 17:52:45 +01:00
DoctorJohn
17146f9b01
Make v3 django choice field enum naming default (in v3) (#982)
Co-authored-by: Jonathan Kim <jkimbo@gmail.com>
2020-06-10 17:32:07 +01:00
DoctorJohn
85976ffb1f
Start raising DeprecationWarnings for using only_fields and exclude_fields (v3) (#980) 2020-06-10 17:30:24 +01:00
DoctorJohn
26c4c48abc
Fix that generated schemas could contain empty descriptions (v3) (#984) 2020-06-10 17:21:37 +01:00
Paul Craciunoiu
c00203499b
DjangoConnectionField slice: use max_limit first, if set (#965) 2020-06-06 19:00:21 +01:00
Jonathan Kim
fb90cb78b3 Merge branch 'master' into v3 2020-05-22 11:17:36 +01:00
Paul Craciunoiu
2225ed62e1
Do not access the internals of SimpleLazyObject (#945) 2020-05-09 17:35:09 +01:00
Jonathan Kim
9b41472922 Merge branch 'master' into v3 2020-05-09 12:50:39 +01:00
Jonathan Kim
5867331c7b
Allow defining fields as an empty list (#871) 2020-05-09 12:28:19 +01:00
Jonathan Kim
b4e34a5794
Improve DjangoListField (#929) 2020-05-09 12:28:03 +01:00