-
Notifications
You must be signed in to change notification settings - Fork 767
Bugfix: Correct filter types for DjangoFilterConnectionFields #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
from datetime import datetime | ||
from textwrap import dedent | ||
|
||
import pytest | ||
from django.db.models import TextField, Value | ||
from django.db.models.functions import Concat | ||
|
||
from graphene import Field, ObjectType, Schema, Argument, Float, Boolean, String | ||
from graphene import Argument, Boolean, Field, Float, ObjectType, Schema, String | ||
from graphene.relay import Node | ||
from graphene_django import DjangoObjectType | ||
from graphene_django.forms import GlobalIDFormField, GlobalIDMultipleChoiceField | ||
from graphene_django.tests.models import Article, Pet, Reporter | ||
from graphene_django.utils import DJANGO_FILTER_INSTALLED | ||
|
||
# for annotation test | ||
from django.db.models import TextField, Value | ||
from django.db.models.functions import Concat | ||
|
||
pytestmark = [] | ||
|
||
if DJANGO_FILTER_INSTALLED: | ||
|
@@ -183,7 +182,7 @@ class context(object): | |
} | ||
""" | ||
schema = Schema(query=Query) | ||
result = schema.execute(query, context_value=context()) | ||
result = schema.execute(query, context=context()) | ||
assert not result.errors | ||
|
||
assert len(result.data["contextArticles"]["edges"]) == 1 | ||
|
@@ -462,15 +461,15 @@ class Meta: | |
class Query(ObjectType): | ||
all_reporters = DjangoFilterConnectionField(ReporterFilterNode) | ||
|
||
r1 = Reporter.objects.create( | ||
Reporter.objects.create( | ||
first_name="A test user", last_name="Last Name", email="[email protected]" | ||
) | ||
r2 = Reporter.objects.create( | ||
Reporter.objects.create( | ||
first_name="Other test user", | ||
last_name="Other Last Name", | ||
email="[email protected]", | ||
) | ||
r3 = Reporter.objects.create( | ||
Reporter.objects.create( | ||
first_name="Random", last_name="RandomLast", email="[email protected]" | ||
) | ||
|
||
|
@@ -638,7 +637,7 @@ def resolve_all_reporters(self, info, **args): | |
Reporter.objects.create( | ||
first_name="Bob", last_name="Doe", email="[email protected]", a_choice=2 | ||
) | ||
r = Reporter.objects.create( | ||
Reporter.objects.create( | ||
first_name="John", last_name="Doe", email="[email protected]", a_choice=1 | ||
) | ||
|
||
|
@@ -684,7 +683,7 @@ def resolve_all_reporters(self, info, reverse_order=False, **args): | |
return reporters | ||
|
||
Reporter.objects.create(first_name="b") | ||
r = Reporter.objects.create(first_name="a") | ||
Reporter.objects.create(first_name="a") | ||
|
||
schema = Schema(query=Query) | ||
query = """ | ||
|
@@ -767,3 +766,55 @@ def resolve_all_reporters(self, info, **args): | |
|
||
assert not result.errors | ||
assert result.data == expected | ||
|
||
|
||
def test_integer_field_filter_type(): | ||
class PetType(DjangoObjectType): | ||
class Meta: | ||
model = Pet | ||
interfaces = (Node,) | ||
filter_fields = {"age": ["exact"]} | ||
only_fields = ["age"] | ||
|
||
class Query(ObjectType): | ||
pets = DjangoFilterConnectionField(PetType) | ||
|
||
schema = Schema(query=Query) | ||
|
||
assert str(schema) == dedent( | ||
"""\ | ||
schema { | ||
query: Query | ||
} | ||
|
||
interface Node { | ||
id: ID! | ||
} | ||
|
||
type PageInfo { | ||
hasNextPage: Boolean! | ||
hasPreviousPage: Boolean! | ||
startCursor: String | ||
endCursor: String | ||
} | ||
|
||
type PetType implements Node { | ||
age: Int! | ||
id: ID! | ||
} | ||
|
||
type PetTypeConnection { | ||
pageInfo: PageInfo! | ||
edges: [PetTypeEdge]! | ||
} | ||
|
||
type PetTypeEdge { | ||
node: PetType | ||
cursor: String! | ||
} | ||
|
||
type Query { | ||
pets(before: String, after: String, first: Int, last: Int, age: Int): PetTypeConnection | ||
} | ||
""" | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.